Udemy

How to handle Properties with Groovy Scripts

A free video tutorial from Raghav Pal
Automation Test Architect | Educator | 15 yrs
Rating: 4.5 out of 5Instructor rating
31 courses
433,621 students
How to handle Properties with Groovy Scripts

Lecture description

Today we will learn:

1. How to get property

2. How to set property

3. How to add property

4. How to remove property

5. How to loop through all properties

References

https://www.soapui.org/scripting-properties/tips-tricks.html

Notes

// Get and Set Property

//Project

testRunner.testCase.testSuite.project.getPropertyValue("Name")

testRunner.testCase.testSuite.project.setPropertyValue("Name","I am in Project")

//TestSuite

testRunner.testCase.testSuite.getPropertyValue("Name")

testRunner.testCase.testSuite.setPropertyValue("Name","I am in TestSuite")

//TestCase

testRunner.testCase.getPropertyValue("Name")

testRunner.testCase.setPropertyValue("Name","I am in TestCase")

//TestStep

testRunner.testCase.getTestStepByName("CountryCodes").getPropertyValue("Name")

testRunner.testCase.getTestStepByName("CountryCodes").setPropertyValue("Name","I am in Test Step")

//Global

com.eviware.soapui.SoapUI.globalProperties.getPropertyValue( "Name")

com.eviware.soapui.SoapUI.globalProperties.setPropertyValue( "Name","I am in Global Prop" )

// Add Property

testRunner.testCase.testSuite.project.addProperty("DOB")

// Remove property

//Project

testRunner.testCase.testSuite.project.removeProperty("Name");

//TestSuite

testRunner.testCase.testSuite.removeProperty("Name")

// Loop through properties

testRunner.testCase.properties.each

{

key,value ->

log.info (testRunner.testCase.getPropertyValue(key))

//log.info (key+" - "+value)

}

Learn more from the full course

SOAPUI API Testing | Step by Step for Beginners

learn SoapUI from scratch

06:44:07 of on-demand video • Updated September 2024

Use SoapUI open source for API testing
Create manual and automation frameworks in SoapUI
How to use Groovy scripts
How to handle different api testing needs
Basics of API testing in SoapUI
English [Auto]
Hello and welcome to discussion on soaps you are a beginner tutorial. You are going to see how to get insect properties to crew with scripts in soapie way. So in the last session we have learned about properties in soaps and how to use them. So today it's going to be very easy and we will see how to get properties set property and property through scripts. In soaps you will see and we will also see how do you remove property and how can you loop through all the properties in soap way with the help of groupy scripts. So lets get started and let me open my soul. So here is my soap U.A.E. and here is our project that we have been creating in the last sessions and this is the canteen for service to project and in the last session we created our group rescript this one where we bought existing properties and I believe one of the things that I missed in the last session was you can also get global properties and these properties are situated here. If you go to your preferences and go to global properties here if you have any property for example I will say this is name and value is I'm global property and I closed this and I see here hash global hash name and Janet and you can see that is that it is getting it from the global properties. So now coming back to today's agenda we have to do all this with the help of the script. So what I'm going to do is in our existing project I will create a new step which will be groovey script step. So just click here and I can name it get set properties and say okay and I will take it up let me take it to the top here. Yes. So now here we have our ruby script where we can do our scripting. So the very first thing we will learn about is how to get property. Okay. So now here we can get property at different levels so we can get property at project level at test suite level and test case level test step level. Okay. So to get the property at project we will be considered test or no and test that is actually interface which provides an entry point we just hope you a b and so you can see that Java docs here for interface tests or no and do not worry about this as of yet. We will learn about it in the later sessions as well. But for now we can just understand the syntax. So here we say test or no test case not test suite Daut project. And then we say get property value and the property key here. So for example if I go to the project level and if I go to the properties you can see we have here two properties which Geest name. And this is W and for the second property key is country name and value is. And so what we're going to do is we are going to fetch the name here and now we can also print it by log dot info and we can see here project property equals and we can actually store it in some variable. We can see just property and print the same thing here. And if I hadn't this there is some property. So. Project is should be lower case. So there is no nothing like a bookcase here. So it's Lucas and let me know. And yes you can see this prince I'm a project property so similarly if you want to go to that destitute level you will have the same thing here. Instead of project we will just go on the street level and let make it as test sweet property. And I will just again print it out on the console. I will say this is test suite property and with video we have stored is this so looking printed here. And of course you should keep the first letter as lowercase which is good coding practice. I'll copy it and I will printed here. And of course we have our property called name at that sweet level as well that we created in our last session. So let's move on it now. And yes it is saying I am a test suite property. Similarly Fortescue's let me just copy this again and paste it here. And here we just have to go and test case and I will name it this test case property. And here is when and paste it here. Let me turn it and I'm getting the test case property as well. Now in case of this step what we would do is see desk. No not best case not get test step by name so we can get the test step it seems to be an hour. If we have this property step here the name is country courts and do not get confused by this digit. Do this means the number of properties in this property step so we have two properties name and continue. That's why it is Schwing to. Otherwise the name is just Ganji courts. OK. So I will see the name country court and then the same thing get property value name and of course we can logon to console we just copy this from here. You sit here and here I will say this is just property and I have not put it into LBG but I will say this is just tip property and I will print it out to the console. So you can see here we can access that test strip property as well so we can get properties at all levels. Now also you can get the properties at global level. So the global properties are here as I discussed earlier. If you go to your preferences and go to global properties here you can set and get properties here. So for example we have already a property name and if you want to fit it there is a different index and actually that is of ph here. First top your way. I will also copy this in the notes so that you can get it in the description of this video. And here you can see how to get into said property and for getting a global property. This is the syntax so I can just copy this and go to my SO P-wave and paste it here. This is what you will see com dot dot dot. So you have global properties and the property value and the name of the property to an object is its name. And then you will also print it and we will see just copy it from here. Paste it and I will say this is global property. And here let me clear this and done it again and you can see we are now getting the global property as well. OK. So this was how simple and easy how we can get property we can actually set property with the themes index. The only difference is instead of get property value we will see a set property value and along with the key people also Gupta value. So we have to give the key and the value. So for example I will say name and I can see so I can actually or what I did so I did it was like I'm a project property. I can say I am in Egypt Similarly for test suite. I will say name is I am in test suite. Similarly for test case I will say set property value and properties name and value. I will said to him in test case and for test step appeal I will say said property will you name and the value will be in test step and then for globalization. We can do the same thing instead of get I said property value and the properties name and value I will set to is I am in global properties. OK. So now I really just clear this console. And now of course this will not make sense because we are just setting it so we do not want. So we do not want to store it. So let me just lay it out all the logon for us and all the variables here. So yes. Now we have this set property so you can see this other person testified and this will set all the properties as per what we have. So for example in project we have said name should be I'm in project. If I go to the project and I go to the property section you can see here it just change it and you can see names. Now I'm in Project Oleate was something else. Similarly you can go to test suite or test case. If I go to a test suite and I go to properties you can see it has changed. I'm in test suite. And of course if you were to test case and properties again that is I am in test case and for test step as well. You can see this is just names. I'm in test step and for global to us school preferences and global properties and here as well. It is updated too. I'm in global properties. Of course you can do our dot info and actually you can just either you can get it like we did earlier or you can directly see desk standard or best case or best suit not project dot get property value name. And if Iran this you can see it gets the property value as well. So this is how you set the property. Now you can also add property but the Sims index for example I see in case of project I will see there's no door test case not test not project not at property. And I can give the key or the property name. So for example I will say D or B. So let's say I want to or date of birth. So I really just said to your. And the net and if you go to the project now you can see that dealable property is added here. OK. Now one thing to note here is that you see at property you can only add that key and not the value but with set property you can also add key and value at the same time. So this is the difference between said property value and at property. Now let us also see how do we remove property. And again this index is very simple. Instead of set targets you will say remove property here. So I will say remove property and of course you just have to give the key or the property name and nothing else. Let me delete this also you can use control on your keyboard to delete an entire line delete this. And here you will see the remove property name. So let us do this only for project and seat and for that it will be same. So let me just say this. No they there's some photos. Let me ask you this and and disagree. It is no signature off met third remove property is applicable for argument type saying well you names. I will comment on that part and all of that. It should be property and hate as well it should be this is fine. Right. Let me. No. And yes. So it it should have removed it. So if I go to that particular one you can see there is no name as of now. And if I go to the test through Willisville and go to the properties you can see the name property is now removed. OK. Now let's also see how do you look through all the properties and this will be very useful when you're actually creating and coding for your projects. Let us go back to our super highway. But here let me comment. Everything else this comment this out and the comments are the same as in Java. So you use double forward slash for line command. You can also use single forward slash and then multiple starts and then a forward slash four. Again this is a line comment. And then you can see farver slash start. And this is a block command. OK. Now to loop two properties. See we want to look to properties of our best case so we will say test or no test case dark properties and dot each. So it is again a key vote and we will start a godly business and doggedly basis so this will be a block it will seek the value and give. Hi Fernando. Gordon you collected here and now we can actually log in full duckie. So for example if I had done this you can see all the keys here. Right. All the property names here. And we can also get the value. So for example I say I also want the values I will see value and let me clear this out. And let me do this. And it is giving this value in some other form that you can actually also lock the door in full. And then we can say this there's no doubt just does not get property value and the property name will be here key because though it is irritating and storing it to key. And now let me turn it I've had this and done this and you can see it to me I'm in test case D-W null which is actually for the test. If you go to the test case you can see the properties and you can see these are the properties that are disciplined. OK. So this is how you can get set to move into properties in so few ways. I hope this session was very useful for you so this session and properties can be very useful to all. So you wait to get through all your project and so forth. So I hope this was useful for you to in the next soakaway. Thank you for.