Tuesday, May 21, 2013

SOAP UI Assertions : Adding XPath assertion with Groovy Script from Project level

SOAP UI Assertions : Adding XPath assertion with Groovy Script from Project level
def TSName = ["Testuite1","Testsuite2"]
for(j=0;j<TSName.size();j++)
{
def StepName = ["testStep1","testStep1"]
for(i=0;i<StepName.size();i++)
{
    project.getTestSuiteList().each
{
    if(it.name == TSName[j])
    {
        TS = it.name
        log.info "TS="+TS
        if(project.getTestSuiteByName(TS).getTestCaseByName(TC).getTestStepByName(StepName[i]))
        {
          it.getTestCaseList().each
          {
            TC =it.name
            def asserting = project.getTestSuiteByName(TS).getTestCaseByName(TC).getTestStepByName(StepName[i]).getAssertionByName("XPath Match")
            if (asserting instanceof com.eviware.soapui.impl.wsdl.teststeps.assertions.basic.XPathContainsAssertion)
            {
                project.getTestSuiteByName(TS).getTestCaseByName(TC)getTestStepByName(StepName[i]).removeAssertion(asserting)
            }
                def assertion = project.getTestSuiteByName(TS).getTestCaseByName(TC)getTestStepByName(StepName[i]).addAssertion("XPath Match")
                if(StepName[i] == "testStep1")
            {
                assertion.path = "declare namespace ns1='http://www.xyz.com/xyz/abc/v1/xyz';\n//ns1:parentnode[1]/ns1:status[1]/ns1:value[1]"
                assertion.expectedContent = "true" 
            }
            else
            {
                assertion.path = "declare namespace ns1='www.xyz.com/xyz/abc/v1/xyz';\n//ns1:parentnode[1]/ns1:status[1]/ns1:value[1]"
                assertion.expectedContent = "true"
            }
          }
    }
    }
}
}
}
log.info "j = "+j

No comments:

Post a Comment