P. 1
SoapUITutorial_new

SoapUITutorial_new

|Views: 582|Likes:
Published by Robert Zhu

More info:

Published by: Robert Zhu on Apr 06, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PPT, PDF, TXT or read online from Scribd
See more
See less

11/03/2012

pdf

text

original

soapUI Tutorial

JRA1 Meeting Cambridge 8 June 2007 Michalis Michael Cynet

What is soapUI?
soapUI is a free and open source desktop application for inspecting, invoking, developing, simulating/mocking and functional/load/compliance testing of web services over HTTP. More on soapUI on http://www.soapui.org .

Getting Started I
Download whatever version of soapUI you wish from http://www.soapui.org according to your system (Linux-Windows) Install it according to the instructions on your system.

com/wsdl.w3schools. Unfortunately our services current WSDL files are very generic and soapUI can¶t use them.Getting Started II In order to begin testing a service we need to have a WSDL file describing it . Or you can just use an all ready existing WSDL file as template and modify it as you please . You can start learning how to write WSDL files at http://www. . This is due to the fact that the request and response schema use the same root element. We need to create two separate WSDL files. One for the service request and the other for the service response.

xsd Note that the xsd files are created in a directory because more than one xsd files may be created each time.html . Our services schema is described in a Relax NG syntax.rnc service-res/service-res. Relax NG syntax can be turned into xsd with he help of trang $mkdir service-req service-res $trang service-req.thaiopensource.com/relaxng/trang.xsd $trang service-res.Getting Started III Next you will need to create the . You can find trang here: http://www.rnc service-req/service-req.xsd files needed in the WSDL description so that soapUI can validate the schema our services responses.

. change it. To bypass this the services rnc files have to be modified accordingly. However this may loosen the schema or if the modification is not the appropriate one.Getting Started IV Unfortunately its very common for the xsd files created by trang not to be accepted as a valid schema by soapUI. This is because our rnc files may contain multiple definitions for the same elements as nmwg:data or nmwg:metadata.

Because of path problems its not recommended to add a WSDL file yet. Go to the menu bar and click File -> New WSDL project From there you can give the project a name. Click ok and the project will be created .Creating Tests I Click to start soapUI Now lets create a WSDL project.

wdsl In windows this may not work. Then you will see that a request was created based on your WSDL description . Then enter something like file:. If this is the case then choose Add WSDL from file. Then agree to Create default Requests for all operations./request.Creating Tests II Right click on the newly created Project and choose Add WSDL from URL.

Creating Tests III The example requests accuracy is determined by the detail of the definitions in the xsd files You will notice that it¶s not quite like the real thing and modifications are required. . You may modify it or you can simple copy paste an example request inside the <soap:body> tag.

.Creating Tests IV Right click on the service interface icon and choose Generate Testsuite in order to create the container for the test cases to come This will create the container for the test cases to be defined.

Creating Tests V To create a new test case right click on the newly created Testsuite icon and choose New TestCase. Give it a name and the new test case is created. .

Creating tests VI To add a request to the test case right click on the example request and choose Add to Testcase The test suite and test cases can be manipulated by right clicking on their icons and selecting their corresponding editors. .

The response will appear on the right hand side By right clicking the space below the window you can add assertions-tests for the response . Click on the green play button on the upper left side to send the request to the service.Creating tests VII The request window should now appear. You can set the service address in the text bar on the top of the window.

Creating Tests VIII Choose schema validation and in the next message box choose the response WSDL file soapUI will then validate the response. In the same manner one can add soap fault assertions XPath matches or simple contains matches .

Creating Tests IX XPath matches are one of the most useful features of soapUI Choose the XPath matches. Then click on declare. The result of the XPath expression on the response will appear on the expected result box If it is what you were going for click save and there you are! . Add your XPath expression and click Select from current.

Creating Tests X In the same manner one can add tests for the response not being a soap fault or just to check if a certain string is part of the result For more in depth testing and for database access the use of a Groovy script is needed« .

. database or console applications simplifies testing by supporting unit testing and mocking out-of-the-box seamlessly integrates with all existing Java objects and libraries compiles straight to Java bytecode so you can use it anywhere you can use Java . OO abilities and an Ant DSL increases developer productivity by reducing scaffolding code when developing web.Getting Started with Groovy From the Groovy home web page: Groovy . GUI. is an agile and dynamic language for the Java Virtual Machine builds upon the strengths of Java but has additional power features inspired by languages like Python.. Ruby and Smalltalk makes modern programming features available to Java developers with almost-zero learning curve supports Domain Specific Languages and other compact syntax so your code becomes easy to read and maintain makes writing shell and build scripts easy with its powerful processing primitives.

After all tutorials on groovy are available on the groovy and soapUI web pages Groovy is a powerful scripting language with a syntax very similar to Java.Groovy I Our goal is not to give a complete tutorial on groovy but to give the necessary groovy tools needed for functional testing. The major deference is that there is not exact declaration of the type of each variable but just a generic def declaration or with no declaration at all.codehaus. .org/Getting+Started+ Guide . For a beginners tutorial look at http://groovy.

10.168.id.status_oper. "testpass".admin:"UNKNOWN"] def sql = Sql.status_oper.status:"down". "perfsonar_ma".newInstance("jdbc:mysql://192.status_admin] resultList.jdbc.eachRow("select id.86:3306/perfsonar_ma". First we define a map def knownResultsMap=[id:"DFN-Surfnet-Link-5678".mysql.Groovy II def knownResultsMap=[id:"DFN-Surfnet-Link-5678".admin:"UNKNOWN"] This map contains what we expect from the database Note: All examples to work need the proper imports! .status_admin from domain_link"){ def result=[:] result=[id:it.add(result) } Above you can see an example of accessing a mySQL database and retrieving data from it.status:it.Driver") def resultList=[] sql. "com.status:"down".admin:it.

id.10.status_admin] resultList. "testpass".admin:it.add(result)} With sql.newInstance("jdbc:mysql://192.eachRow method . "perfsonar_ma". "com. There is not need to declare the iterator.status_oper.86:3306/perfsonar_ma".Groovy III def sql = Sql.status:it.Driver") Then a connection to the mySQL database is established. The result map holds the results for one row and all rows are stored in the result list. def resultList=[] sql.eachRow("select id. its ³built-in´ with the .jdbc.eachRow the select statement is executed and the results are stored inside the result map with the help of an iterator ³it´ .status_admin fromdomain_link"){ def result=[:] result=[id:it. providing the address the username the password and the driver.status_oper.168.mysql.

id +" "+it.status+" "+it.admin)) println "\n We have a match" + "\n"+ it.id==knownResultsMap. .status==knownResultsMap.each{ if((it. admin==knownResultsMap.status)&&(it.admin } Next the results from the query and the expected results are cross checked Notice that with the ³.Groovy IV resultList.id)&&(it.each´ method there is no need for ³for´ or ³while´ loops or ³iterators´.

86:8080/exist/xmlrpc/db/sqlmacon fig".168.DatabaseImpl").registerDatabase(database). groovy can still use java libraries instead here is an example: Class cl = Class.newInstance(). "sqlmaservice". DatabaseManager.forName("org.getCollection("xmldb:exist://192.exist. Database database = (Database) cl. lucking of course groovy¶s capabilities. "testpass"). Collection collection = DatabaseManager.10. . The traditional java method and classes can be used for accessing eXist.xmldb.Groovy V There is no native Groovy support for the eXist database though« But no problem there.

restart old ones or decide which steps to start based on the results of the old ones.Groovy and soapUI I Groovy is an essential part of soapUI However looking at soapUI¶s getting started guide one can conclude that groovy scripting was not incorporated into soapUI for the reasons we want to use it Groovy is used in soapUI primarily as a control step. getting results from other steps and passing them to other steps. It can even be used to create new test steps. Nevertheless groovy¶s capabilities as a scripting language counter the native soapUI problem and allow us to bypass this disadvantage .

then through testCase and finally got what we wanted from the getTestStepByName method Next we obtained the response through the request object using its getProperty method.Groovy and soapUI II Groovy can access test steps through the testRunner instance. println property. def property = request.getTestStepByName( "MetadataKeyRequest1" ). The Groovy-soapUI combination has some powerful xml handling capabilities which we intend to use« .testCase.getProperty( "Response" ).value In the previous example we¶ve accessed the MetadatakeyRequest1 object through the testRunner instance. def request = testRunner.

text() } From the above example we can see the power of groovy on xml We got the response document through the groovy. def parameters=response["soapenv:Body"] ["nmwg:message"] ["nmwg:data"]["nmwg:key"]["nmwg:parameters"]["nmwg:parameter"] parameters.value).parseText(property.XmlParser and then accessed the parameters element through a very simple XPath API Then with the help of the .each{ println it['@name'] println it.util.Groovy and soapUI III def response = new groovy.XmlParser(false.util.false).each method and the XPath API we¶ve accessed all the parameter element .

error "script failed³ Through the log instance you can report any failures to the logging space at the bottom of the groovy script window The logs output is the soapUI log Or you can just throw an exception throw new Exception( ³script failed" ) .Groovy and soapUI IV As said before the groovy scripting step was not intended to be a testing mechanism but rather a control unit.info "script failed³ log. So there is no way I could find that could allow a groovy script step to fail as a test request step. But there are ways to get around that log.

withWriter { out -> fields. value -> out.each() { key. "c":"3"] new File("foo. "b":"2".writeLine("${key}=${value}") } } The former piece of code uses the withWriter method and the help of a ³closure´ to write the map to the file.ini"). Writing our results with the help of groovy to an external file.Groovy and soapUI V But the best way in my opinion is to write the result of the groovy script to an external file along with the results of all tests def fields = ["a":"1". can give us the reporting capability that we have using traditional languages for functional testing as Java and Perl .

org/Eclipse+Plugin When you finish testing the code pieces that are independent from soapUI you can copy the code to the soapUI script editor and add the remaining code.Groovy and soapUI VI-Tips The groovy script editor is pretty raw and I wouldn¶t suggest it for any serious developing I¶d suggest to install groovy on a machine and try most of the code apart from soapUI There is also an eclipse plug-in. Instructions on how to install it are found at http://groovy. .codehaus.

bat or .can be tricky. .jar Restart soapUI so that the changes may take place This is necessary for the mysql-connector and xmldb packages.sh file adding set CLASSPATH=%CLASSPATH%.\lib\mypackage.Groovy and soapUI VII-Tips Be careful! The embedded groovy language in soapUI can only accept new packages only if it is installed on your machine... JNLP versions can not accept new packages.bat or . Adding new packages to the embedded groovy-such as xmldb. Then modify the soapUI.sh is needed. Modification of soapUI. Copy the packages you want to add in the lib directory of the soapUI installation folder.

Groovy and soapUI VIII .

Questions? .

Thank you all for watching! . This tutorial was heavily based on Jochen¶s instructions found on svn.Thanks! A special thanks to Jochen Reinward for his precious assistance on soapUI and on the rnc to xsd transformation.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->