Forum Discussion

Himanshu001's avatar
Himanshu001
New Member
7 years ago

Retrieve xpath from xpath assertion in the test step using groovy in OS SOAP UI

Hi,

 

I have created many xpath assertions in test step. I want to retrieve the xpaths and name of the assertion using groovy step in OS SOAP UI. Now i am using external file for the assertions and it is tedious task to copy paste all assertions in excel.

 

Please help on this.

 

Regards,

Himanshu

  • JHunt's avatar
    JHunt
    Community Hero

    I'm not sure what output format you wanted, but here's how to get hold of the objects in Groovy:

     

    import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep
    import com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep
    import com.eviware.soapui.impl.wsdl.teststeps.assertions.basic.XPathContainsAssertion
    
    Map assertions = [:]
    
    testRunner.testCase.project.testSuites.each { testSuite ->
    	testSuite.value.testCases.each { testCase -> 
    		testCase.value.testSteps.each { 
    			def testStep = it.value
    			if (testStep instanceof WsdlTestRequestStep || testStep instanceof RestTestRequestStep) {
    				testStep.assertions.each {
    					def assertion = it.value
    					if (assertion instanceof XPathContainsAssertion) {
    						assertion.XPathReferences.each { xpathReference ->
    							assertions["${testStep.name}: ${assertion.name}"] = "${xpathReference.XPath} = ${assertion.expectedContent}"
    						}
    					}
    				}
    			}
    		}
    	}
    }
    
    assertions.each {log.info it.key; log.info it.value}
    return null
    INFO:SomeRestTestStep: My XPath Match Assertion
    INFO://*:status = OK
  • nmrao's avatar
    nmrao
    Champion Level 3
    Himanshu001, the use case seemed to be interesting.

    Would you please tell a little more on how you are going to use external for the assertions and assert them dynamically. Appreciate your time.