Created
July 1, 2016 16:05
-
-
Save rupzme/cfed4594dc3ae1ce7a419ca5fc9b5747 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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" : "[email protected]" | |
}, { | |
"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." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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()
ordef project = testRunner.testCase.testSuite.project
ordef project = context.testCase.testSuite.project