Showing posts with label SoapUI. Show all posts
Showing posts with label SoapUI. Show all posts

Tuesday, March 25, 2014

SoapUI, Groovy Script tutorial

Groovy is built on JVM, so does the SoapUI, it’s no surprise that SoapUI offers the Groovy script support by default. Let’s do a simple test, basically send out a Http request with dynamic parameters, and parse the result using the regular expression capability of Groovy and IO capablity to save the result back to a file. for the parameter we can use the groorvy to poll a file and return some randomized keywords.

so the keywords file looks like
image

we create one project with one test suite, then under the suite, we can add test case, and for the test step, let’s add first step called GetKeyword as a groovy script.


image

then we put some script here, which will assign a keyword property to the context randomly.
image

then we can access this keyword using context.keyword in next step, now, let’s create a http request to bing.com

image

Click extract params,now if we run this test

image

the query keyword is hardcoded, we can replace it with a groovy expression

image

then add the 3rd step, that we read the response in step 2 and save it to a file

image

if we run the test case, you will see file named keyword.txt with the http response from bing.com search

also you can just copy and save the following xml as a project file, you open in in SoapUI

<?xml version="1.0" encoding="UTF-8"?>
<con:soapui-project activeEnvironment="Default" name="tst" soapui-version="4.6.4" xmlns:con="http://eviware.com/soapui/config"><con:settings/><con:testSuite name="testgroovy"><con:settings/><con:runType>SEQUENTIAL</con:runType><con:testCase failOnError="true" failTestCaseOnErrors="true" keepSession="false" maxResults="0" name="TestCase 1" searchProperties="true" id="cdd185b8-b6ae-4455-9713-ec70b5404569"><con:settings/><con:testStep type="groovy" name="GetKeyword"><con:settings/><con:config><script>def file=new File("c:\\a.txt")
def lines=file.readLines();
def randomindex=new Random()
def keyword=lines[randomindex.nextInt(lines.size())];
context.keyword=keyword
log.info(keyword)</script></con:config></con:testStep><con:testStep type="httprequest" name="Req2Bing"><con:settings/><con:config method="GET" xsi:type="con:HttpRequest" name="Req2Bing" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><con:settings><con:setting id="com.eviware.soapui.impl.wsdl.WsdlRequest@request-headers">&lt;xml-fragment/></con:setting></con:settings><con:endpoint>http://www.bing.com/search</con:endpoint><con:request/><con:credentials><con:authType>Global HTTP Settings</con:authType></con:credentials><con:jmsConfig JMSDeliveryMode="PERSISTENT"/><con:jmsPropertyConfig/><con:parameters><con:parameter><con:name>q</con:name><con:value>${=context.keyword}</con:value><con:style>QUERY</con:style><con:default>androidyou</con:default><con:path xsi:nil="true"/><con:description xsi:nil="true"/></con:parameter></con:parameters></con:config></con:testStep><con:testStep type="groovy" name="SaveitToFile"><con:settings/><con:config><script>def resp=testRunner.getTestCase().getTestStepByName("Req2Bing").httpRequest.response
def raw=resp.getContentAsString()
//save it fo file
def resultFile=new File("c:\\" + context.keyword + "t.txt")
resultFile.write(raw);</script></con:config></con:testStep><con:properties/></con:testCase><con:properties/></con:testSuite><con:properties/><con:wssContainer/></con:soapui-project>

Thursday, September 2, 2010

Free WCF / ASMX Test Trace tool. SoapUI and TCPTrace

I’ve always write a lot C# code to do some simple WCF testing. Until I find SoapUI, one Powerful wsdl stack test tool. It has the free Version which covers pretty all the test features I need. Let me show you a quick Tutorial.

SOAPUI is based ON http protocol mostly. so you might need to add one basicHttpBinding to you configuration. then we can enable the test on the http transport channel.

  Given a very basic Service.

image

when run the host application, you should be able to access the WSDL.

image

 

Now Just download the free version of soapUI from http://sourceforge.net/projects/soapui/files/ , there are different versions. I just select the 3.5.1 version.

SoapUI is based on Standard JAVA and javafx, so make sure you have the jdk ready . if javafx is not there, the installer will access internet and download the bits for you.

Run the soapui Utility.

image

Right click the project, Add one New project , you may specify a meaningful name.  you don't have to specify the initial wsdl , we will add it later on.


image

Right Click the new created Project , and chose Add WSDL

 image

Enter or Browse the WSDL url, I will put http://localhost:22276/Service1.svc?wsdl here. Click OK. Then you will see the Operation get listed in the project panel.

image

Double Click the Request 1 under GetData.  the SOAP request template has been generated for you, replace the ? with you value. and Click green Arrow button to submit the request.

image

for complexes object,  it’s there too. 
 image

 

Is it sweet? I think so.

Click the raw Tab. you can see the raw data there. there are some buttons that enable you to change the URL, Add customized Header. etc. (if you use the professional version. you will get more features like json view of the data.)

image

Further more, you can add it as a test case. Click the + button in the toolbar

image

 

then you can click the run the test .

image


also you can add more success criteria by click the add assertion button.

image

So here is all about SOAP. if you want to see the raw Http traffic, you can use the TCpTrace, also it’s free.

basically, change you service client to point a New port that TCPtrace is listening on, and TCPtrace will forward the request to the Service Port.

image

image

Please note. for those wsHttpBinding. you may have to Add one service behavior that allow server to process the request that has a different port(endpoint action), AddressFilterMode

image 
 

Also for the WCF client, you may just put one ClientViaBehavior to the endpoint, the client runtime will do the forwarding for you.

  


  more related articles.

Free WCF / ASMX Test Trace tool. SOAPbox by vordel
 
Locations of visitors to this page