Groovy - How to automatically modify/set operation test step request
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Groovy - How to automatically modify/set operation test step request
Hello,
I want to automatically change content of a WSDL request of several requests in test steps of a test case. The name of the service changed in the WS I used to test, but the contents still the same.
I add the idea to do this using a groovy test step script to launch manually. In order to reuse it, I created it in a separated TestSuite.
def testCase = testRunner.testCase.testSuite.project.getTestSuiteByName("testSuiteName").getTestCaseByName("testCaseName") def request, holder testCase.testStepList.each { step -> request = context.expand( '${#[testSuiteName#testCaseName#'+step.name+']#Request}') if(request.contains("<soap:serviceNameBefore>")){ request = request.replaceAll("soap:serviceNameBefore>","soap:serviceNameAfter>") // At this time, the request is not updated on expected test step // I guess I missing something here } }
I don't find the correct method to update request according to the variable I modified (a string with expected request)
Do you have an idea ? Is there another way to do that ?
To help understand, here is the example of what I want to do. Change this request :
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://XX/"> <soapenv:Header/> <soapenv:Body> <soap:serviceNameBefore> <request> <name>?</name> <price>?</price> </request> </soap:serviceNameBefore> </soapenv:Body> </soapenv:Envelope>
in all test step to that one
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://XX/"> <soapenv:Header/> <soapenv:Body> <soap:serviceNameAfter> <request> <name>?</name> <price>?</price> </request> </soap:serviceNameAfter> </soapenv:Body> </soapenv:Envelope>
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Each operation supports fixed element, and changing that may not be suggested.
Or missing the details or context in the question.
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@nmrao I edited my question with this :"The name of the operation changed in the WS I used to test, but the contents still the same."
You are right regarding the risks but in this case I know it is possible.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Operation name and Element name in the request are two different things. Is it only Element name changed in your case? And not the operation name?
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The name of the operation changed, not the element. I may have not well explained.
I give you details. I want to change this request :
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://XX/"> <soapenv:Header/> <soapenv:Body> <soap:OperationBefore> <request> <name>?</name> <price>?</price> </request> </soap:OperationBefore> </soapenv:Body> </soapenv:Envelope>
to that one
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://XX/"> <soapenv:Header/> <soapenv:Body> <soap:OperationAfter> <request> <name>?</name> <price>?</price> </request> </soap:OperationAfter> </soapenv:Body> </soapenv:Envelope>
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
https://www.soapui.org/soap-and-wsdl/operations-and-requests.html
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the links. You are right, I mean changing the element of the request.
I edited my original post to try to make it more understandable.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Below should help you:
import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep
//Define element names in below two statements
def elementNameBefore = 'DefineOldName'
def elementNameAfter = 'DefineNameName'
//No change required beyond this
def testCase = testRunner.testCase.testSuite.project.getTestSuiteByName("testSuiteName").getTestCaseByName("testCaseName") testCase.testStepList.findAll{it instanceof WsdlTestRequestStep}.each { step -> def content = step.httpRequest.requestContent def changedContent = content.replaceAll(elementNameBefore, elementNameAfter) step.httpRequest.requestContent = changedContent }
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Regards,
Rao.
