SoapUI is an open-source web service testing application for service-oriented architectures (SOA) and representational state transfers (REST).
Its functionality covers web service inspection, invoking, development, simulation and mocking, functional testing, load and compliance testing.
A commercial version, SoapUI Pro, which mainly focuses on features designed to enhance productivity, was also developed by Eviware software.
In 2011, SmartBear Software acquired Eviware.
SoapUI was initially released to SourceForge in September 2005. It is free software, licensed under the terms of the European Union Public License.
Since the initial release, SoapUI has been downloaded more than 2,000,000 times.
It is built entirely on the Java platform, and uses Swing for the user interface. This means that SoapUI is cross-platform.
Today, SoapUI also supports IDEA, Eclipse, and NetBeans.
SoapUI can test SOAP and REST web services, JMS, AMF, as well as make any HTTP(S) and JDBC calls.
→Right Click on your Project
→ Create New TestSuit (CTRL + T)
→ Specify name of TestSuit
→ Right Click on your TestSuit
→ New TestCase (CTRL + N)
→ Specify name of TestCase
→ Expand Test Case
→ Click on Test Steps
→ Add Step
→ Choose request (e.g. SOAP Request)
→ Specify name for new step
→ Select operation to invoke for request
→ Add Request to TestCase (OK)
Green «+» icon will appear.
By clicking it you can add Assertions.
Assertions are added to the TestSuits so to be able to add Assertions you need to create at least one TestSuit and click the green + sign.
Then you can choose one of the wide variety of available assertion types.
ChooseContains. With this assertion it will be possible to search for the existence of a string token in the property value. It supports regular expressions and is applicable to any property.
Specify unique name of Assertion
Type in content that you expect to receive in case of successfull request
Choose Not Contains. With this assertion it will be possible to search for the non-existence of a string token in the property value. It supports regular expressions and is applicable to any property.
Specify unique name of Assertion
Type in content that you definitely do not want to receive in the response
Choose SOAP Response. With this assertion you can check that the last received response is a valid SOAP Response. It is applicable only to SOAP TestRequest Steps only. Do not try to use it with REST.
Double click on the Assertion. It does not require any additional parameters and can be added to the test step only once.
Choose Valid HTTP Status Code. With this assertion you can check that the last received response is a valid SOAP Response. It is applicable only to SOAP TestRequest Steps only. Do not try to use it with REST.
Type in the HTTP Status Codes that are appropriate for your request.
Usually it is 200 but you need to read system specification to be sure.
Choose Response SLA. With this assertion you can validate that the last received response time was within the defined limit. It is applicable to Script TestSteps And TestSteps that send requests and receive responses.
Specify the maximum response time (ms)
If response time is not mentioned in the spec add some reasonable time.
Choose XPath Match. This Assertion uses an XPath expression to select content from the target property and compares the result to an expected value. Applicable to any property containing XML.
Click Declare
To verify that the property is present in the response type in exists
(//property_name)
Type in true to the Expected Result field.
To verify that the property is present in the response only once, type in count
(//property_name)
Type in 1 to the Expected Result field.
To validate property's value put path to the propery
(full path or property's name - both options are acceptable)
Type in the expected property value to the Expected Result field.
It is possible to use XPath Assertion with multiple properties.
Type in the parent property. After you get first correct response you can click
Select from current
Click Allow Wildcards
Type in * instead of actuall values in the Expected Result field.
When, for example, we can not reach server and all our assertions are failed they will have red indicator.
File → Create Empty Project
Enter Project Name
New Rest Mock Service
Specify name of MockService
Add new mock action
Type in Resource path and choose method GET
New MockResponse
Enter name of new MockResponse
Copy the json below and paste it to the Response body
{
"bicycles":{
"bicycle": [{
"id":1,
"name": "
Helkama
",
"country": "
Finland
"
}, {
"id":2,
"name": "
Stels
",
"country": "Russia"
},{
"id":3,
"name": "
Tunturi
",
"country": "
Finland
"
}]
}
}
Change Content | Media type to application/json. Http Status Code should be 200 – OK. Headers are optional. You can add them by clicking green + sign.
Right click on BicycleService and
Add new mock action
call it «bicycle/1»
Right click on «bicycle/1» (or click Ctrl + N) and
create New MockResponse
call it «singleBicycle»
Copy the following json and paste it to the Response body
{
"bicycle": {
"id":1,
"name":
"Helkama
",
"country":
"Finland
"
}
}
Create new mock action, keep already used name «/bicycle» but make it
POST
instead of GET.
Create new MockResponse and call it «addBicycle»
Copypaste the following json to body
{ "key":12041961 }
Create new GET mock action «/incorrectep» and new MockResponse «400» Change Http Status Code to 400 – Bad Request
Notice that the Port used by BicycleService is 8080
Start BicycleService
Now we have four different mock scenarious.
Use
Postman
to test them.
POST to http://localhost:8080/bicycle
Should return key 12041961
GET to http://localhost:8080/bicycle
Should return list of all bicycles
GET to http://localhost:8080/bicycle/1
Should return one bicycle
GET to http://localhost:8080/incorrectep
Should return empty body and Http Status 400 Bad Request
To create dynamic response for the POST to /bicycle request replace 12041996 with ${variable} and add the following code to the script folder
context.setProperty("variable",Math.random()*100000000000000000)
To test the script go to Postman and send multiple requests
Share in social media:
|