Forum Discussion
PaulDonny
12 years agoRegular Contributor
To put a step in the second before last test request ....
If the test is always being added as the last step this should work:
You could also use getTestStepIndexByName(String stepName) if you are unsure of where exactly it will be but the script above will only move it up 1 step.
For my 3rd point, I have a post for a UI within SoapUI, it runs my test cases the way I want them ran. What I personally do with a lot of my test cases that I want ran multiple times is just iterate through the list of testcases using :
That will loop through the test steps of the given type (This being standard Soap requests) and assign each test to the variable "tests". As it loops through I grab the contents of the test case using:
holder then becomes the XML from the request that I was processing. I parse through the XML using regex looking for tags but if you wanted you could just use properties.
After that my next step is transferring the assertions:
And run the test step:
It's really simple once you get used to it essentially just 1 Soap Request is ever ran. The main problem is editing the XML when ran.
If the test is always being added as the last step this should work:
import com.eviware.soapui.impl.wsdl.teststeps.registry.GroovyScriptStepFactory
def tc1 = testRunner.testCase;
gs = tc1.addTestStep( GroovyScriptStepFactory.GROOVY_TYPE, "rerun/cleanup" )
[b]testRunner.testCase.moveTestStep(testRunner.testCase.getTestStepCount()-1,-1);[/b]
gs.properties["script"].value = 'def response = testRunner.testCase.testSteps["createClaim"].testRequest.response.contentAsString \nif (response.contains("Error processing query") == true) \n{ \ntestRunner.gotoStep(0) \n} \ndef uniqueId = context.expand( "${#TestCase#testCase}" )';
You could also use getTestStepIndexByName(String stepName) if you are unsure of where exactly it will be but the script above will only move it up 1 step.
For my 3rd point, I have a post for a UI within SoapUI, it runs my test cases the way I want them ran. What I personally do with a lot of my test cases that I want ran multiple times is just iterate through the list of testcases using :
for ( tests in testRunner.testCase.getTestStepsOfType(com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep.class) ) {
That will loop through the test steps of the given type (This being standard Soap requests) and assign each test to the variable "tests". As it loops through I grab the contents of the test case using:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context); //declared earlier in my script
def holder = groovyUtils.getXmlHolder(testName+"#Request");
holder then becomes the XML from the request that I was processing. I parse through the XML using regex looking for tags but if you wanted you could just use properties.
After that my next step is transferring the assertions:
/*
* Stealing the assertions from the respective test steps and putting it into the Runner
* test step
*/
def testRan = testRunner.testCase.getTestStepByName(testName);
def Assertions = testRan.getAssertions();
def removeAssertions = testRunner.testCase.getTestStepByName("Runner").getAssertions();
for (key in removeAssertions.keySet()) {
testRunner.testCase.getTestStepByName("Runner").removeAssertion(removeAssertions.get(key));
}
for (assertion in Assertions.keySet()) {
testRunner.testCase.getTestStepByName("Runner").cloneAssertion(Assertions.get(assertion),assertion);
}
And run the test step:
testRunResultsXML = testRunner.runTestStepByName("Runner").getResponse();
testRunResults = groovyUtils.getXmlHolder("Runner#Response");
testPrint = testRunResults.getPrettyXml();
It's really simple once you get used to it essentially just 1 Soap Request is ever ran. The main problem is editing the XML when ran.