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

Monday, May 20, 2013

SOAP UI : Adding XPath Assertion to all test steps(same request) in project.

Adding XPath Assertion to all test steps(same request) in project.

TSName = "TestSuiteName"
StepName = "TestStepName"
project.getTestSuiteList().each
{
    if(it.name == TSName)
    {
        TS = it.name
          it.getTestCaseList().each
          {
            TC =it.name
            def asserting = project.getTestSuiteByName(TS).getTestCaseByName(TC).getTestStepByName(StepName).getAssertionByName("XPath Match")
            if (asserting instanceof com.eviware.soapui.impl.wsdl.teststeps.assertions.basic.XPathContainsAssertion)
            {
                project.getTestSuiteByName(TS).getTestCaseByName(TC)getTestStepByName(StepName).removeAssertion(asserting)
            }
                def assertion = project.getTestSuiteByName(TS).getTestCaseByName(TC)getTestStepByName(StepName).addAssertion("XPath Match")
                if(StepName == "TestStepName")
            {
                assertion.path = "declare namespace ns1='http://www.xyz.com/';\n//ns1:StepResponse[1]/ns1:status[1]/ns1:value[1]"
                assertion.expectedContent = "success"
            }
            else
            {
                assertion.path = "declare namespace ns1='http://www.xyz.com/';\n//ns1:StepRequestResponse[1]/ns1:status[1]/ns1:value[1]""
                assertion.expectedContent = "200"
            }
          }
    }
}

SOAP UI : Adding XPath Assertion from test suite level, test case level and from test step(groovy)

Adding XPath Assertion to soap request test steps from Project level(Copy below script in load script of project)

def asserting = project.getTestSuiteByName("StockQuoteService").getTestCaseByName("GetStockQuote").getTestStepByName("GetStockQuote").getAssertionByName("XPath Match")
if (asserting instanceof com.eviware.soapui.impl.wsdl.teststeps.assertions.basic.XPathContainsAssertion)
{
project.getTestSuiteByName("StockQuoteService").getTestCaseByName("GetStockQuote")getTestStepByName("GetStockQuote").removeAssertion(asserting)
}

def assertion = project.getTestSuiteByName("StockQuoteService").getTestCaseByName("GetStockQuote")getTestStepByName("GetStockQuote").addAssertion("XPath Match")
assertion.path = "declare namespace ns1='http://www.restfulwebservices.net/ServiceContracts/2008/01';declare namespace a='http://www.restfulwebservices.net/DataContracts/2008/01';\n //ns1:GetStockQuoteResponse[1]/ns1:GetStockQuoteResult[1]/a:Symbol[1]"
assertion.expectedContent = "CTSH"

Adding XPath Assertion to soap request test steps from Test Suite level(Copy below script in setup script of test suite)

def asserting = testSuite.getTestCaseByName("GetStockQuote").getTestStepByName("GetStockQuote").getAssertionByName("XPath Match")
if (asserting instanceof com.eviware.soapui.impl.wsdl.teststeps.assertions.basic.XPathContainsAssertion)
{
testSuite.getTestCaseByName("GetStockQuote")getTestStepByName("GetStockQuote").removeAssertion(asserting)
}

def assertion = testSuite.getTestCaseByName("GetStockQuote")getTestStepByName("GetStockQuote").addAssertion("XPath Match")
assertion.path = "declare namespace ns1='http://www.restfulwebservices.net/ServiceContracts/2008/01';declare namespace a='http://www.restfulwebservices.net/DataContracts/2008/01';\n //ns1:GetStockQuoteResponse[1]/ns1:GetStockQuoteResult[1]/a:Symbol[1]"
assertion.expectedContent = "CTSH"

Adding XPath Assertion to soap request test steps from Test Case level(Copy below script in setup script of test case)

def asserting = testCase.getTestStepByName("GetStockQuote").getAssertionByName("XPath Match")
if (asserting instanceof com.eviware.soapui.impl.wsdl.teststeps.assertions.basic.XPathContainsAssertion)
{
testCase.getTestStepByName("GetStockQuote").removeAssertion(asserting)
}

def assertion = testCase.getTestStepByName("GetStockQuote").addAssertion("XPath Match")
assertion.path = "declare namespace ns1='http://www.restfulwebservices.net/ServiceContracts/2008/01';declare namespace a='http://www.restfulwebservices.net/DataContracts/2008/01';\n //ns1:GetStockQuoteResponse[1]/ns1:GetStockQuoteResult[1]/a:Symbol[1]"
assertion.expectedContent = "CTSH"

Adding XPath Assertion to soap request test steps using groovy step/script(Copy below script in groovy script test step) 
def testst = testRunner.testCase.getTestStepByName("GetStockQuote")
def asserting = testst.getAssertionByName("XPath Match")
if (asserting instanceof com.eviware.soapui.impl.wsdl.teststeps.assertions.basic.XPathContainsAssertion)
{
testst.removeAssertion(asserting)
}

def assertion = testst.addAssertion("XPath Match")
assertion.path = "declare namespace ns1='http://www.restfulwebservices.net/ServiceContracts/2008/01';declare namespace a='http://www.restfulwebservices.net/DataContracts/2008/01';\n //ns1:GetStockQuoteResponse[1]/ns1:GetStockQuoteResult[1]/a:Symbol[1]"
assertion.expectedContent = "CTSH"