ADS

Sunday, May 12, 2013

Assertion in SOAPUI using Groovy

If we need to add some basic assertions at runtime using Groovy, then following can be useful for you
def project = testRunner.testCase.testSuite.project
def testst = project.getTestSuiteAt(0).getTestCaseAt(0).getTestStepAt(0)
Adding CONTAINS assertion
def assertioncontains = testst.addAssertion("Contains")
assertioncontains.name = "contains assert"
assertioncontains.setToken("54")
assertioncontains.setIgnoreCase(true)
assertioncontains.setUseRegEx(true)
Adding NOT Contains assertion
def assertionnotcontains = testst.addAssertion("Not Contains")
assertionnotcontains.setToken("50")
assertionnotcontains.setIgnoreCase(true)
Adding XPATH Match assertion
def assertionxpath = testst.addAssertion("XPath Match")
assertionxpath.name = "xpath assert"
assertionxpath.setPath("path")
assertionxpath.setExpectedContent("expected content")
assertionxpath.setAllowWildcards(true)
Adding XQuery Match assertion
def assertionxquery = testst.addAssertion("XQuery Match")
assertionxquery.setPath("path")
assertionxquery.setExpectedContent("expected content")
assertionxquery.setAllowWildcards(true)
Similarly you can add more assertion based on your requirements. Now for the different properties that you need to set, you can refer the API doc provided by the SOAPUI http://www.soapui.org/apidocs/index.html