Forum Discussion

borella's avatar
12 years ago

Scripting Message Content Assertion

I'm trying to modify a Message Content Assertion dynamically in a groovy script.

Assume I have a testcase with two test steps:
1. Groovy Script
2. SOAP call


The SOAP call has one Message Content Assertion. Now I try to dynamically change the first value of the assertion in the Groovy script:

wsdlTestSteps = testRunner.testCase.getTestStepsOfType( com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep.class );
wsdlTestSteps.each {
def assertion = it.getAssertionByName("Message Content Assertion");
if (assertion) {
assertion.getConfiguration().getElementsArray(0).setExpectedValue('some value')
}
}


The value is changed in the xml file, but the testcase won't fail, when I try to run it.

With an XPath assertion I can easily get it to work, but then I'm forced to have a lot of XPath assertions, which increases the risk, that I forget to test some fields.


wsdlTestSteps = testRunner.testCase.getTestStepsOfType( com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep.class );
wsdlTestSteps.each {
def assertion = it.getAssertionByName("XPath Match");
if(assertion) {
assertion.setExpectedContent('some content');
}
}

1 Reply

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi!

    Sorry, but instead of altering the value this way, have you tried to use a Custom Property in Expected Value column the Message Content Assertion dialog (right click and use the Get Data.. menu)?
    Then you could use Groovy to change the value of just that property.

    --
    Regards

    Erik
    SmartBear Sweden