Learn SoapUI

Preview:

DESCRIPTION

Lear how to use SoapUI

Citation preview

SoapUI TrainingInduction courseFresh GradsIonut David02.04.2013

•What is SoapUI

• SoapUI Features

• SOAP and WSDL

• Functional Testing

• Service Mocking

Agenda

2

What is SoapUI

• Free and open source cross-platform Functional Testing solution.

• Creating even the most advanced test scenarios is very simple.

• SoapUI is a complete and automated testing solution.

• Testing for everyone.

• Streamlined service simulation.

• Advanced functionality comes standard.

SoapUI Features

• Functional Testing.

• Service Simulation.

• Security Testing.

• Load Testing.

• Technology Support.

• Automation.

• Analytics.

• Recording.

• Ecosystem.

What is a Web Service

• A web service is a method of communication between two electronic devices over the World Wide Web. A

web service is a software function provided at a network address over the web or the cloud, it is a service that

is "always on“.

• The Web Services Description Language is an XML-based interface description language that is used for

describing the functionality offered by a web service. A WSDL description of a web service (also referred to as

a WSDL file) provides a machine-readable description of how the service can be called, what parameters it

expects, and what data structures it returns.

SOAP and WSDL

• XML-based protocol to let applications exchange

information over HTTP.

• SOAP stands for Simple Object Access Protocol

• SOAP is a communication protocol

• SOAP is a format for sending messages

• SOAP is platform independent

• SOAP is language independent

• XML-based language for describing Web services

and how to access them.

• WSDL stands for Web Services Description

Language

• WSDL is an XML document

• WSDL is also used to locate Web services.

SOAP Definition WSDL Definition

SOAP and WSDL

• A SOAP message is an ordinary XML document containing the following elements:

• An Envelope element that identifies the XML document as a SOAP message.

• A Header element that contains header information.

• A Body element that contains call and response information.

• A Fault element containing errors and status information.

SOAP Syntax

SOAP and WSDL

<?xml version="1.0"?>

<soap:Envelope

xmlns:soap="http://www.w3.org/2001/12/soap-envelope"

soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Header>

...

</soap:Header>

<soap:Body>

...

<soap:Fault>

...

</soap:Fault>

</soap:Body>

</soap:Envelope>

SOAP Syntax Example

SOAP and WSDL

• A WSDL document describes a web service using these major elements:

• A container for data type definitions used by the web service.

• A typed definition of the data being communicated.

• A set of operations supported by one or more endpoints.

• A protocol and data format specification for a particular port type.

WSDL Document Structure

SOAP and WSDL

<definitions>

<types>

data type definitions........

</types>

<message>

definition of the data being communicated....

</message>

<portType>

set of operations......

</portType>

<binding>

protocol and data format specification....

</binding>

</definitions>

WSDL Example

Functional Testing

• Create a SoapUI Project

• Right click on the project node and select New SoapUI Project.

Functional Testing

• In the New SoapUI Project dialog enter a project name (i.e. Country_info) and click OK.

• Right click on the project node and select Add WSDL.

Functional Testing

• The Add WSDL dialog is now open

• Enter http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL.

• Click OK.

Functional Testing

• Now see that the WSDL was successfully added to the

project by seeing the operations in the Web Service in

the navigatorEnter

Functional Testing

• Create a request from your WSDL

• Click on the plus sign next to the web service in the navigator to expand.

• Double click on the request.

• You now have to enter your data manually in the code editor as shown below. Replace “?” with “RO” (without quotes)

Functional Testing

• Run a request to the Web Service

• Click on the green arrow head sign to submit the request.

Functional Testing

• Receive response

• On the right side of the window the response will be displayed.

Functional Testing

• Run an invalid request to the Web Service.

• Introduce a wrong country code (like “ZZ”).

• Click on the green arrow head sign to submit the request.

• The response of the Web Service will indicate that the country was not found.

• After seeing the result, correct the input data.

Functional Testing

• Create a Test Case from a request.

• In the request editor, select Add This Request to TestCase.

Functional Testing

• Next step:

• Adding a request to a TestCase will open the Create TestSuite dialog box. Enter a name for your TestSuite and

click OK.

• After clicking OK, you will be asked to create a TestCase. In the Create TestCase dialog, enter a name for your

TestCase and click OK.

Functional Testing

• Next step:

• The dialog box Add Request to TestCase will appear. Click OK.

Functional Testing

• Final step:

• SoapUI will now generate a TestSuite and TestCase for you while the request will be added as a TestRequest.

Below is a copy of the request that appears in the interface. A TestCase editor will also open with your new

TestRequest.

• The next step is to validate the response in your test by adding an Assertion.

Functional Testing

• Add an Assertion to the test:

• Now that we've created and run our first test, we are going to add a validation of the response. In SoapUI,

this is called adding an assertion.

• Examples of assertions that is possible in SoapUI are:

• Schema Compliance

• Simple Contains

• Simple Not Contains

• SOAP Faults

• Response SLA

• XPath Match

• XQuery Match

• WS Security Status

• WS-Addressing Request/Response Assertion

• Script Assertion

Functional Testing

• Close all windows you have open in SoapUI before starting:

• Double Click on your Test Request as shown below. This will open the request editor.

• After clicking OK, you will be asked to create a TestCase. In the Create TestCase dialog, enter a name for your

TestCase and click OK.

Functional Testing

• Next step:

• Select Response SLA from the Add Assertion menu.

• In the Configure Response SLA Assertion dialog box, write 500 and click OK. This will validate that the

response of the SLA is under 500.

Functional Testing

• Next step:

• Now that you've added the assertion, you are going to run the request to validate the response. If all

assertions are successful, the SOAP icon should turn green in three places as shown below.

Functional Testing

• Validate response with XPath Match:

• Select XPath Match from the Add Assertion menu.

Functional Testing

• Validate response with XPath Match:

• In the XPath Match Configuration press Declare button and write below “//m:CapitalCityResult”

• Click “Select from current” and you should see the word Bucharest appearing in the Expected Results field.

• Click Save

Functional Testing

• Final step:

• Now that you've added a new assertion, you are going to run the test again. If all assertions are successful,

the SOAP icon should turn green in three places as shown below.

Service Mocking

• “Service Mocking, or simulation, is the practice of creating a facsimile environment that works similar to the

environment you’re facsimileing”.

• When to use it: You should use mocks when you can’t use the real thing

• Advantages:

• You can create tests in advance.

• Teams can work in parallel.

• You can create proof of concepts or demos.

• You can isolate systems.

• You can write test for resource not accessible.

• Mock can be delivered to the customer.

• Disadvantages:

• You have to do Double work.

• Deployment constraints.

• It’s not live is it?

Service Mocking

• Start a new SoapUI project using the following wsdl: http://www.webservicex.net/CurrencyConvertor.asmx?

WSDL

• Click OK button.

Service Mocking

• Right-click on one of the SOAP interfaces and select Generate MockService.

Service Mocking

• In the dialog Generate Mock Service you can specify the local port/path for the service you're creating but for

the moment just click OK

Service Mocking

• Enter the name of your Mock Service in the Name dialog and click OK. For example: Mock convertor

• After creating the MockService, you should get a MockService with one operation and one request.

• As you can see, the Icons are Grey and inactive. This is an indication that the MockService is not yet running. We

have successfully created our first MockService.

Service Mocking

• Now, double click on the MockService to see the MockService editor. In the editor we can see a list of all

operations for the service, as well as a request and response log which logs all incoming requests that have been

handled by the MockService.

• Double Click on the Conversion Rate Operation to see the MockResponses we have in the MockService

Service Mocking

• As you can see we do only have one, Let's edit it, double click on it to open the Response Editor

• The MockResponse editor is very similar to the standard SoapUI Request editor , but instead of requests, we'll

edit responses. The Incoming Request view is still very useful; it shows the last received request to the operation

which is useful for debugging client calls, including attachments and HTTP headers.

• Edit the ConversionRateResult to be something else than the default empty value "?“. For example: 2.5

Service Mocking

• First we must start the MockService. Click the Start button in the MockService editor, the green arrow head ,

this will start the service on the configured port and path

• To the Top Right of the Editor you should see that it's running, and the port it's responding on. The play Button is

greyed out and if you would like to stop the MockService, just click the stop button.

Service Mocking

• Now in the MockResponse editor, Click the Button Create Request.

• This will prompt you to open one of the existing requests for its operation in your project.

• You will also need to give it a name.

Service Mocking

• When you open the request, SoapUI will automatically change its endpoint to the endpoint of the locally

running MockService instead of the endpoint that the WSDL is using. Submit the opened request by clicking the

Run Button

• As you can see the MockService returned the values we entered earlier as the response.

Service Mocking

• Let's continue by making the created MockResponse a bit more dynamic by changing the dispatch and

by Groovy scripting.

• First we’ll create a second MockResponse.

• Give it a Groovy Name

Service Mocking

• Let's write a script for the response. Click the Script tab in the Response and enter the following Groovy Script,

(context.rand = Math.random() *10)

It will look like this:

• This script sets a property called rand to a random number (from 0 to 10).

• Now that we have written a script and the random results will be inserted into the response.

Ionut David| Software Engineerionut.david@endava.com

Tel +40 727 772 636 |Skype en_idavid

thank you