ADS
Showing posts with label script. Show all posts
Showing posts with label script. Show all posts

Friday, August 2, 2013

Test Step results from Groovy in SOAPUI

After having lot of Groovy written for just retrieving the data from one place and copying it to another place, I thought to investigate some new commands. Although these are not new in the Javadoc, it was just new for me only ;).

So I just went ahead on how to extract the status of the test steps that has been executed.
One point to note over here is that, add the Groovy script to get the status of test steps at least in a test case or you can add the script to get the status of test step execution in the teardown script of the test case or test suite.

So here is the simple Groovy that will fetch you the status of your test steps

for (r in testRunner.results)

{
       log.info "Test Step " + <test_step_name> + "has been executed with status as " + r.status
}

If test step has been passed then result will be OK, on the other hand if test step has been failed, then status will be Failed
In the end it turns out to be very simple command which will be really very helpful for everyone.

Tuesday, April 2, 2013

Handling SOAP Request and Response from Groovy script

In this post, we will be learning how we can access SOAP Requests and Response using Groovy Scripts.

Let us take the following example
Request:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://www.webserviceX.NET/">
<soap:Header/>
<soap:Body>
<web:ConversionRate>
<web:FromCurrency>SEK</web:FromCurrency>
<web:ToCurrency>DKK</web:ToCurrency>
</web:ConversionRate>
</soap:Body>
</soap:Envelope>

Response:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<ConversionRateResponse xmlns="http://www.webserviceX.NET/">
<ConversionRateResult>5.7187</ConversionRateResult>
</ConversionRateResponse>
</soap:Body>
</soap:Envelope>

Now we want to access the content of above SOAP Request and Response, then we can use the following code:
import com.eviware.soapui.support.XmlHolder

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def step = context.testCase.getTestStepAt(0)
if( step instanceof com.eviware.soapui.model.testsuite.SamplerTestStep && step.testRequest.response != null ) // this step indicate that retrieved TestStep is a SOAP request and response is present for it
{
def response = groovyUtils.getXmlHolder( step.name +"#Response")
def request = groovyUtils.getXmlHolder(step.name + "#Request")
response.namespaces["ns"] = "http://www.w3.org/2001/XMLSchema"
log.info (request.getNodeValue("//ConversionRateResponse/ConversionRateResult")) 
log.info response.isEmpty()
log.info response.getNamespaces()

For more functions which you can do with SOAP Request and Response can be found at http://www.soapui.org/apidocs/index.html and go to package com.eviware.soapui.support and XmlHolder class in it.

Monday, April 1, 2013

Basic Groovy Scripts commands for SOAPUI

Using Groovy scripts in SOAPUI can help you do lots of stuff but beginning with this feature can be at times difficult for new users. Following are the commands that you can find really useful for starting with Groovy scripts in SOAPUI.

Go to the project level using the command
def project = testRunner.testCase.testSuite.project

Access the Test Suite using the following commands
def testsuite = project.getTestSuiteAt(index)
def testsuite = project.getTestSuiteByName("TestSuite Name")

Access the Test Case using the following commands
def testcase = testsuite.getTestCaseAt(index)
def testcase = testsuite.getTestCaseByName("TestCase Name")

Access the Test Steps using the following commands
def teststep = testcase.getTestStepAt(index)
def teststep = testcase.getTestStepByName("TestStep Name")

Run a Test Step using the following command
teststep.run(testRunner,context)

set property value at different level of hierarchy

set property at Project level
project.setPropertyValue("property_name","value") 


set property at TestSuite level
testsuite.setPropertyValue("property_name","value") 

set property at TestCase level
testcase.setPropertyValue("property_name","value") 

get property value from different level of hierarchy

get property from Project level
project.getPropertyValue("property_name")


get property from TestSuite level
testsuite.getPropertyValue("property_name")

get property from TestCase level
testcase.getPropertyValue("property_name") 


get the count of number of TestSuites, TestCases and TestSteps
project.testSuiteCount // get TestSuite count in the project
testsuite.testCaseCount // get TestCase count in the TestSuite
testcase.testStepCount // get TestSteps count in the TestCase
Any other basic commands which you feel should be added in the list please provide in the comment section.