Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*
* For a chosen REST Service POST request:
*
* -> Manually specify a new request body
* -> Update the request of ALL (POST) REST TestRequest TestSteps contained in ALL TestCases of a chosen TestSuite
*/
//Set TestSuite to update here:
def testSuiteNameToUpdate = "TestSuite 2"
//Set new request body here:
def requestBodyToCopy = """{
"apiPostId" : "125",
"data" : [ {
"name" : "email",
"value" : "aaaacccchtomosanya@yahoo.com"
}, {
"name" : "data_source",
"value" : "Outlet"
}, {
"name" : "date_of_record",
"value" : "2016-04-18T00:05:57Z"
}, {
"name" : "marketing_opt_in_mens",
"value" : "1"
}, {
"name" : "marketing_opt_in_womens",
"value" : "1"
}, {
"name" : "marketing_opt_in_kids",
"value" : "0"
}, {
"name" : "email_sp3_status_id",
"value" : "100"
} ]
}"""
//Get chosen TestSuite
def project = testRunner.getTestCase().getProject()
def testSuiteToUpdate = project.getTestSuiteByName(testSuiteNameToUpdate)
//Select ALL TestCases
def testCasesToUpdate = testSuiteToUpdate.getTestCaseList()
def updateCount=0
//For each TestCase
testCasesToUpdate.each{testCase ->
log.info "--Checking TestCase: $testCase.name"
//Select ALL RESTTestRequest TestSteps
def testStepsToUpdate = testCase.getTestStepList()
//For each TestStep
testStepsToUpdate.each{testStep ->
log.info testStep.name
//Is it a POST request?
if (testStep instanceof com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep &&
testStep.restMethod.method.toString()=="POST"){
log.info "Updating request of TestStep $testStep.name ..."
testStep.getHttpRequest().setRequestContent(requestBodyToCopy)
updateCount++
}
}
}
return "Total of $updateCount REST TestRequest TestSteps have been updated."
@nmrao
Copy link

nmrao commented Jul 8, 2016

If it is a groovy script, then line # 42, leads to compilation error.
It should be one of the below:
def project = testRunner.getTestCase().getTestSuite().getProject() or
def project = testRunner.testCase.testSuite.project or
def project = context.testCase.testSuite.project

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment