Reputation: 874
I am writing a validation groovy script for a test step, intended to test a SOAP Web Service.
Now, I want to call the same test step, with different input value from the groovy script. Is it possible? I dont want to write another test step.
Thanks
Upvotes: 0
Views: 2163
Reputation: 18507
Yes it's possible, anyway your question is too open so I purpose the follow approach.
Use for example testCase properties in your testStep request, this way you can change this properties an reuse the same request more than once. To do so, use the follow syntax in your TestStep: ${#TestCase#YourProperty}
, supposing for example you've a SOAP Request, it can be:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<someRequest>
<changeValue>${#TestCase#yourProperty}</changeValue>
<someRequest>
</soapenv:Body>
</soapenv:Envelope>
Then in your groovy testStep you can set the property value and call your testStep the times you want, see the follow code which I hope it's self explanatory:
// get the testCase
def tc = testRunner.testCase
// set the value for your property
tc.setPropertyValue('yourProperty','someValue')
// get testStep by its name
def ts = tc.getTestStepByName('TestStepName')
// invoke testStep
ts.run(testRunner,context)
If for example you would run this testStep various times based on the property value, you can use:
// get the testCase
def tc = testRunner.testCase
// get testStep by its name
def ts = tc.getTestStepByName('TestStepName')
// property values
def propertyValueArray = ['firstValue','anotherValue','moreValues','lastOne']
// for each property value
propertyValueArray.each { value ->
// set the value for your property
tc.setPropertyValue('yourProperty',value)
// invoke testStep
ts.run(testRunner,context)
}
Hope this helps,
Upvotes: 2
Reputation: 1
you can have parameters in your unit tests in 'where' definition. add anything you like there and use values by their names at first line
def "Field '#field' with value '#val' should result in '#code'"() {
when:
def myObject = ["$field": val]
then:
fooMethod(myObject) == code
where:
field | code | val
'myField' | 'nullable' | null
'myField' | 'blank' | ''
'myField' | 'valid' | 'abc123'
}
Upvotes: -1