Reputation: 662
i am trying to automate Restful tests with SoapUI API. Understand by that, that i don't want to open the SoapUI GUI to launch my project, although the xml file resulting from the save on file of the WsdlProject, can be imported and executed via the GUI.
Here is what i have :
I create a SoapUI Project :
WsdlProject wadlProject = new WsdlProject();
I then add a test suite :
WsdlTestSuite ts = wadlProject.addNewTestSuite("HelloTestSuite");
Then to this test suite I add one or more test cases :
WsdlTestCase tc = ts.addNewTestCase("HelloTestCase1");
Finaly i add test Steps to a test case :
WsdlTestStep testStep = tc.addTestStep(HTTP_RQST,"HelloTestStep1",ip_addr+":"+port,"POST");
With
private final String HTTP_RQST = HttpRequestStepFactory.HTTPREQUEST_TYPE;
Now if i want lets say to add a payload to my POST test step i do :
testStep.setPropertyValue("request", "My Payload to send with the test");
########################## NOW MY QUESTION IS : ##########################
If i want to add a simple contains assertion to this test step how is it done?
I have tried : testStep.setPropertyValue("Contains", "success");
But it is not how it works. Hope any one can help me.
Thanks
Upvotes: 2
Views: 1706
Reputation: 18507
You can do it using the following code:
import com.eviware.soapui.impl.wsdl.*
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase
import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStep
import com.eviware.soapui.model.testsuite.TestAssertion
import com.eviware.soapui.impl.wsdl.teststeps.assertions.basic.SimpleContainsAssertion
import com.eviware.soapui.impl.wsdl.teststeps.HttpTestRequestStep
WsdlProject wadlProject = new WsdlProject();
WsdlTestSuite ts = wadlProject.addNewTestSuite("HelloTestSuite");
WsdlTestCase tc = ts.addNewTestCase("HelloTestCase1");
WsdlTestStep testStep = tc.addTestStep("httprequest","HelloTestStep1",ip_addr+":"+port,"POST");
TestAssertion assertion = ((HttpTestRequestStep)testStep).addAssertion("Contains");
((SimpleContainsAssertion)assertion).setToken("success");
This code is only a sample to add a contains
assertion looking for a string success
in the response. Another kind of asserts can be added as well but take in account the implementation of com.eviware.soapui.model.testsuite.TestAssertion.TestAssertion
interface returned by addAssertion
methods because each one has it's own methods to setup the assertion, in the contains case the implementation is com.eviware.soapui.impl.wsdl.teststeps.assertions.basic.SimpleContainsAssertion
.
It's similar that how addTestStep()
method works, which returns an instance of com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStep
interface, however since your type is "httprequest"
the implementation is com.eviware.soapui.impl.wsdl.teststeps.HttpTestRequestStep
... in resume the thing is that without the proper casts you can't invoke the necessary methods to add the assertions (at least using java... with groovy there is no problem at all :)
)
Hope it helps,
Upvotes: 2