I developed some SoapUI cases which set a property at the start of each test case by reading the properties from a file. This works fine, I can then access each property (lets say propertyA) by the syntax ${propertyA} in each test request step.
Now I realized that one of the properties is the same for each test case, so I thought I create a testsuite property for that purpose and remove the property definition from the test case property files. First my test cases all failed, cause now 'propertyA' was not known any more, but I figured out that (according to http://www.soapui.org/Scripting-Properties/property-expansion.html) one solution is to replace each reference to propertyA by #testSuite#propertyA.
This is kind of tedious, though, so I thought of creating a groovy script at the beginning of each test case which creates a test case property from the test suite property. According to
http://www.soapui.org/Scripting-Properties/tips-a-tricks.html I thought that a script like
def testSuiteProperty = testRunner.testCase.testSuite.getPropertyValue("propertyA")
testRunner.testCase.setPropertyValue("propertyA", testSuiteProperty)
should do the job. And if I log.info the value of testSuiteProperty this gives indeed the desired value, and also if I assign the testCase property to some variable and log.info it, it shows the correct value.
However, in the next test step, propertyA is not known. Just to make sure I tried to use ${#testCase#propertyA} there, but that is also not known. What did I get wrong here?
I think your problem is that the t of testCase in ${#testCase#propertyA} must be uppercase: ${#TestCase#propertyA}. If I add a groovy test step with your code:
def testSuiteProperty = testRunner.testCase.testSuite.getPropertyValue("propertyA")
testRunner.testCase.setPropertyValue("propertyA", testSuiteProperty)
And then I add a SOAP test step with follow xml:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:open="http://www.openuri.org/">
<soapenv:Header/>
<soapenv:Body>
<open:procesa>
<open:selector>${#TestCase#propertyA}</open:selector>
</open:procesa>
</soapenv:Body>
</soapenv:Envelope>
It works correctly, however if I use ${#testCase#propertyA} the property value is not found.
Besides you can check if correct value is used in the raw tab in the left side of the SOAP test step request. In this tab the request is show with the properties replaced by it's values.
Hope this helps,
Related
I have a SpringBootTest that reads in properties from application.properties. The setup code uses the #Value annotation to set the values accordingly. One of these properties is an array of names.
I am trying to write a data driven test using Spock. The where statement is using these names that are initialized in the setup:
expect:
retrievedName == value
where:
value << getNames()
This always fails with org.spockframework.runtime.SpockExecutionException: Data provider is null.
It appears that the getNames() call is invoked before the properties are initialized in the setup code. If I do not use the where statement (data driven testing), all works fine. Is there a workaround for this?
You cannot use data initialized in the setup section as a source for data driven tests. As per the docs:
Although it is declared last, the where block is evaluated before the feature method containing it runs.
You can try and use setupSpec() methods and #Shared fields as a workaround.
See here for an example.
I am having an issue with property transfer and test case variable in soap UI.
Basically in my property transfers I want to pull out a value from a soap request response step, but I want the some values to be picked out from a test case property like so:
declare namespace T='http://test.com'
//T:Testxml/T:NextLevel/T:FinalLevel[#date='${#TestCase#testDate}']/#price
However it doesn't like this as it spits out [null] but when I replace the variable to a hard coded date (same value as in the test case property), then it works.
My question is how can I pass through a test case variable in this scenario?
I can easily set property in Property step for following line:
<(tagName)>111<(/tagName)>
just by modifying line as:
<(tagName)>${Properties#PropertyName}<(/tagName)>
where Properties is a step in testSuite with names and values.
But how I can do this for such row: <(city cityNumber="111")>
and for such: <(Request requestType="TEXT" versionNumber="VERSION")>?
I just want to write those properties in my Properties table.
First: I do not understand the round brackets - what is that suppose to be?
You would do it the same way:
<city cityNumber="${Properties#PropertyName}">
<Request requestType="${Properties#PropertyText}" versionNumber="${Properties#PropertyVersion}">
SoapUI, when it internally goes the through the property expansion phase, it treats everything as String. Only after the message gets transmitted to your server, does it get treated as XML.
Documented on property expansion.
I am a beginner in soapui testing. Hopefully you can help me solving this problem.
In my test project I have a test suites which contains several test cases. Multiple test case will start the same test case. To run this test case I need some property values to be transferred to this test case.
I tried to achieve this in two ways. But I failed in both.
I tried to call the test case and set the needed properties in the test case. I start the test case from a Groovy script. But I couldn't find a good example how to set the properties in the called test case.
I tried to get the property values of the calling parent test case inside the called test case. It looks like the parent test case that called the test case isn't available in the context of the running test case.
The test cases, that will call the same test case, will be run in parallel. So, I think it isn't a solution to first set the property values and then start the test case, because they will be overwritten by the other test cases that run at the same time. Also using test suite properties for these values won’t work because of running the test cases in parallel.
My test project looks like this.
MyProject
TestSuite_APLtests
TestCase_user_01
Properties test step
Run_test <groovy script>
Step_01
…..
TestCase_user_02
Properties test step
Run_test <groovy script>
Step_01
…..
TestCase_General
Properties test step
POST sessions
Step_01
…..
The ‘Properties test step’ of each ‘TestCase_user_’ contains a user and password needed in test case ‘TestCase_General’ and will be different for each test case.
In the ‘Run_test’ groovy script of each ‘TestCase_user_’ the test case ‘TestCase_General’ is started by using:
def myTestSuite = testRunner.testCase.testSuite.project.getTestSuiteByName("TestSuite_APLtests")
def myTestCase = myTestSuite.getTestCaseByName("TestCase_General")
myTestCase.run(null, false)
How can I add the properties user and password to the run comment that starts the test case?
If I try to get the property values with a groovy script in test case ‘TestCase_General’ I don’t know how to determine which test case has called ‘TestCase_General’. I found some posts on internet that suggests to use: context.getProperty("#CallingRunTestCaseStep#") to determine the calling test case. But this value is null. And when I try to check if the calling test case is available in the context by using: context.hasProperty("#CallingRunTestCaseStep#") this is false, so this doesn't work to find the calling test case.
Can someone tell me what the solution will be to get this working.
Thanks,
You can set Test Case properties from groovy script with setPropertyValue(name,value) method, however if you run the Test Cases in parallel, this properties as you said will be overwritten for each Test Case calling TestCase_General. So instead of use setPropertyValue you can pass the context properties through the run(StringToObjectMap properties, boolean async) method in the WsdlTestCase.java class. Your groovy code to call TestCase_General could be:
import com.eviware.soapui.support.types.StringToObjectMap
// get test suite
def myTestSuite = testRunner.testCase.testSuite.project.getTestSuiteByName("TestSuite_APLtests")
// get your test case
def myTestCase = myTestSuite.getTestCaseByName("TestCase_General")
// set the user and password properties in the context
context.setProperty("user","userTestCaseN")
context.setProperty("password","passwordTestCaseN")
// run the testCase passing the context
def contextMap = new StringToObjectMap( context )
myTestCase.run(contextMap,false);
To access the context properties in the groovy script of your TestCase_General use this code:
context.getProperty("userPassword")
Or if you prefer to use context.expand:
context.expand('${#user}')
Note that the use of # depends on how you are accessing the properties.
If you also need to use the context properties in the SOAP Test Request of your TestCase_General use this way ${#propetryName} i.e:
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Header/>
<Body>
<request>
<user>${#user}</user>
</request>
</Body>
</Envelope>
Hope this helps,
Good day,
Brief illustration on what I am planning to achieve:
From within a Test Case I have a groovy script to set a Property for the current Test Case:
The Question is: How can I modify (set) a MockService Property value from outside of the Mock Service itself. I know the solution lies in just adding the right syntax to the example above
All the best
You can set a property in the mockservice context like that:
testRunner.testCase.testSuite.project.mockServices["yourMockService"].getMockRunner().getMockContext().setProperty("yourProperty","yourPropertyValue")
I DID NOT need either getMockRunner() or getMockService() to set a property for my mock.
This is what worked for me:
testRunner.testCase.testSuite.project.mockServices["your_mock"].setPropertyValue("your_property_name", "your_property_value")