cancel
Showing results for 
Search instead for 
Did you mean: 

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

New Member

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

2 REPLIES 2
Community Hero

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

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
Community Hero

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

@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.


Regards,
Rao.
New Here?
Join us and watch the welcome video:
Watch the new Interview
Top Kudoed Authors