Forum Discussion
14 Replies
Sort By
- Cizo89Frequent ContributorHi Leo,
I'm not sure if I got this right, but try this:
testRunner.testCase.setPropertyValue("TestCaseCustomProperty1", testRunner.testCase.testSuite.project.getPropertyValue("ProjectCustomProperty1"))
Or you can just use Property Expansion:
${#Project#ProjectCustomProperty1}
I hope it will help you, more useful tricks can be found here:
http://www.soapui.org/Scripting-Propert ... ricks.html
Regards,
Marek - SmartBear_SuppoSmartBear Alumni (Retired)Hi,
If you want to share properties between TestCases within the same TestSuite I would suggest use TestSuite property, then you can also use property expansion to get the value but if that not feasible, here is the solution,
//To get
log.info testRunner.testCase.testSuite.getTestCaseByName("TestCase Name").getPropertyValue("PropertyName")
//To set
testRunner.testCase.testSuite.getTestCaseByName("TestCase Name").setPropertyValue(String name, String value)
Thanks,
Jeshtha - hutabarat2014ContributorOK. I will give it a go and confirm that everything works.
- hutabarat2014ContributorHi Cizo89,
I tried your first solution, which is
testRunner.testCase.setPropertyValue("TestCaseCustomProperty1", testRunner.testCase.testSuite.project.getPropertyValue("ProjectCustomProperty1"))
and it works all right.
But, the thing is that when we want to have it at the top end (not writing in every single test case), how do we do that?
Perhaps I was not really clear.
Say, in the Project Property I have a property called IP_Address which contains value of 127.0.0.1.
Now, let's just say I got 200 Test Cases which use this project property of IP_Address.
Rather than going through each Test Case and write the groovy script like you mentioned above, is there a way to write a groovy script at a separate Test Suite (on top of the tree before any other Test Suites or Test Cases) that will populate every single property of IP_Address in each Test Case?
Having said that, also I would like to know than when a Test Case does not have currently a property called IP_Address, with this groovy script, we are able to create a new property, call it IP_Address and populate it with the value 127.0.0.1.
Is this a possible thing to do in SoapUI?
Much obliged.
Leo - Cizo89Frequent ContributorHi Leo,
I'll start with your last question - yes, if the TestCase (or TestSuite) doesn't have property called "IP_Address" and you'll use method setPropertyValue(String, String) on it, it will create it and populate it with your specified value.
Back to your problem.
If you have 200 TestCases and want to copy the value from Project property to each TestCase in a TestSuite via a Groovy script, the best way to do this is via TestSuite Setup Script:
for (testCase in testSuite.getTestCaseList()){
testCase.setPropertyValue("IP_Address", testSuite.project.getPropertyValue("IP_Address"))
}
Here is an example of a script for Project Setup Script for setting this property to all your TestCases in all our TestSuites:
for (testSuite in project.getTestSuiteList()){
for (testCase in testSuite.getTestCaseList()){
testCase.setPropertyValue("IP_Address", project.getPropertyValue("IP_Address"))
}
}
More info about Setup Scripts can be found here:
http://www.soapui.org/Functional-Testin ... ripts.html
Regards,
Marek - hutabarat2014ContributorHi Marek,
Thank you for your solutions.
I will give it a go tomorrow and let you know how it goes.
Kind regards,
Leo - hutabarat2014ContributorHi Marek,
I was away for a couple days.
I will keep you updated about your solution.
Kind regards,
Leo - hutabarat2014ContributorHi Marek,
Thank you for your solution:for (testSuite in project.getTestSuiteList()){
for (testCase in testSuite.getTestCaseList()){
testCase.setPropertyValue("IP_Address", project.getPropertyValue("IP_Address"))
}
}
One thing, I would like to ask you is that, instead of the name of one property, if for example, I got various properties.
Some of them starts with certain alphabet like "c_", for example "c_IP_Address" (without the quote marks).
Now, how do we put a regex in the name for that? Is it going to be like this?for (testSuite in project.getTestSuiteList()){
for (testCase in testSuite.getTestCaseList()){
testCase.setPropertyValue("c_*", project.getPropertyValue("c_*"))
}
}
Thank you,
Leo - Cizo89Frequent ContributorHi Leo,
since method setPropertyValue has String as both input params, I'm not sure if RegEx will work, probably not.
Here is the link to this method:
http://www.soapui.org/apidocs/com/eviwa ... .String%29
If you want to copy all your Project Properties to all your TestCases via Project Setup Script, this will work for you:
for (projectProperty in project.getPropertyList()){
for (testSuite in project.getTestSuiteList()){
for (testCase in testSuite.getTestCaseList()){
testCase.setPropertyValue(projectProperty.getName(), projectProperty.getValue())
}
}
}
Regards,
Marek - hutabarat2014ContributorHi Marek,
Thank you for your reply.
Perhaps, I didn't really make myself clear.
For example, in the Project level I got the following properties with this naming conventions:
c_ABC
c_DEF
c_GHI
p_Whatever
p_Whenever
p_Whoever
w_Here
w_There
w_Nowhere
So, from the example above, all I need to do is just to transfer properties which have a prefix of "c_" only to Test Cases.
I do not want to transfer properties with prefix "p_" and "w_" to Test Cases.
Thus, not ALL of the properties at Project level will be transferred to Test Cases.
Thanks again, Marek.
Kind regards,
Leo
Related Content
- 4 years agoSuperTester
- 3 years agoCata