soapUI – How to Test a REST Service

Automation Guild Online Conference Top ad

How to Test a REST Service

What is REST? Why is it Needed

REST (Representational State of Transfer) is a lightweight option for developing web services the uses the HTTP protocol –a fact that makes is simpler with less overhead than a web service that uses the SOAP protocol.

Today we'll be looking at soapUI but you can also programmatically test a rest service using a library like rest-assured without using a vendor tool.

(If you're interested in learning how to use soapUI to test SOAP web services, check out my post/video: soapUI – How to test a web service.)


Twitter API

For this example, I'll be using the Twitter API (GET statuses/user_timeline Resource) to perform a search for and return the last five tweets on my Twitter timeline:

https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=jcolantonio&count=5

How to use soapUI to test REST service

Here are the steps to follow to get started using the free version of soapUI with REST testing:

    1. Create a new project in soapUI named TWITTER REST (make sure you select the Opens dialog to create REST Service); click “OK”


    1. In the New REST Service dialog, enter the Service Endpoint:
      https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=jcolantonio&count=5
    2. Click on the “Extract Resource/Method” and click “OK”


    1. On the New REST Resource dialog, click on the “Extract Params” button. You should have two parameters named id and count. Click “OK”


    1. In the New REST Method dialog, enter the Method Name, “GET JOE TIMELINE” and click “OK”


    1. Click on the “GET JOE TIMELINE” Request 1 and click on the green run arrow


  1. Cool! You should be able to see the XML results returned from the Twitter service:


Now let's add assertions to validate the response

In order to verify that the correct response has been returned, you'll need to add an assertion. For this example our assertion is going to verify that five twitter entries were indeed returned by response of the service.

    1. First, click on the request's “Add this REST request to a testcase” icon.


    1. Name the testsuite “TWITTER REST,” and the TestCase “GET TIMELINE.”
    2. Add the Request to TestCase. Accept all the default values and click “OK.”


    1. You should now have a TWITTER REST testsuite under your soapUI project:


Click on “GET JOE TIMELINE” Request and click “Assertions” then click on the “Add an assertion” icon.


    1. In the “Add Assertion” screen, click on Property
      Content>XPath Match and click the “Add” button.


    1. For the XPath Expression, enter:
declare namespace ns1='http://www.w3.org/2005/Atom';
count(//ns1:feed/ns1:entry)

    1. Expected Result: enter “5.”


  1. Click the “Save” button and re-run.
  2. Your “assertion” should be green.


How to Test a REST service and Rest Easy

That's it! You can now rest easy in the knowledge that you now know how to test a REST service using soapUI!

34 comments
venkat - October 28, 2012

Hi Joe,

can you please suggest how to automate gwt graphs(pie charts,bar charts, performance graph).
I need to capture x-axis and Y axis values( i.e 2010-2011,2011-2012) in graphs.We are using QTP-10.00 and Application developed in Google Web Development ToolKit(GWT).

Thanks in Advance.

Regards
Venkat gudi

Reply
    Joe Colantonio - November 14, 2012

    venkat » Hi Venkat – I’ve been trying against some Google graph samples without any luck. I have not tried creating my own sample to see if there is a method that can be exposed that will return X and Y info. You might want to check with your developers to see if this is an option.

    Reply
      venkat - November 25, 2012

      Thanks joe…

      Reply
xenon - January 4, 2013

Hi Joe,

Can you tell me, what I must change in the count(//ns1:feed/ns1:entry) because I dont have in the xml File.

Thanks

Reply
    Joe Colantonio - January 4, 2013

    xenon » Are you following this exact example? It should be there unless something has changed with the API.

    Reply
Rohit - January 7, 2013

Hi,

I am trying the same thing form the SoapUI but i am not able to get the response in SoapUI. Do we need to change some settings in the Soapui to connect to Internet like proxy setting..?? i am able to get the number of tweets in browser using SoapUI API but not from SoapUI. please help.

thanks in advance

Reply
    Joe Colantonio - January 8, 2013

    Rohit » Hi – You might need to add your companies proxy settings under soapUI>File>Preferences>Proxy Settings.

    Reply
Vams - February 11, 2013

What if if the response is like below? How do i need to test with xPath expression?Can you please guide me.
<![CDATA[

type=”text/javascript”>
]]>

Reply
Pogi - February 14, 2013

Hi Joe,

You might also be interested in WCFStorm.Rest (http://www.wcfstorm.com/wcf/learn-more-rest.aspx). It’s also a REST test tool which has some pretty good features IMHO

Reply
Jaymin - April 2, 2013

Hi Joe,

Do you have sample video or steps for POST JSON request and assertions.

I am now ok with GET but still not with POST. It would really help.

Thanks,
Jaymin.

Reply
    Joe Colantonio - May 11, 2013

    Jaymin » Hi Jaymin – I’m working on an example and will post it once I get it working. Thanks!

    Reply
krish - April 29, 2013

Hi Joe,
I am new to web services testing and to soapUI tool. But then with the help of few online resource I see a good picture on “what is a webserivce , HOw to works, what is Get and Post request?”. And then I used soapui tool to try a REST service and i got output as what i needed. Now my query is, if soapui tool is making life easy to send GET or POST requests with just few data’s (such as url) and clicks then there is a possibilty to do same thing without using tool. If it is possible then can you give me some inputs on how to do it?Thank You krish

Reply
    Joe Colantonio - May 3, 2013

    krish » Sure you could use straight programming langues like C# and Java. What language are you using?

    Reply
Ganesh - May 24, 2013

Heyy Joe.. Am also looking for POST JSON sample video.. When i was searching for solution, i got this link http://www.soapui.org/forum/viewtopic.php?t=11065 but am not good enough to explore this.. :( Please make a sample and share if possible very soon..
Regards,
Ganesh

Reply
    Joe Colantonio - May 27, 2013

    Ganesh » Hi Ganesh – I’m working on it. Just finding it hard to find a sample API that I can use to do this with.

    Reply
      Ganesh - May 28, 2013

      Ok Joe.. :) thanks for ur update.. :)

      Reply
solai - July 30, 2013

I had followed the same steps but getting pls help

Reply
Ambadi - August 15, 2013

Dear Joe,

I am new to the testing of HTTP services. I have found the SOAP UI as a tool to automate my testing activities. Could you please help me with what I am trying to achieve.
I have a set of XSD’s and XML messages and I need to fire the message over an http service, get the response back. I have around 52 messages, each having 300 more test cases. I need to automate all the cases and make a functional testing for an entire flow.

Please help me in setting up a project with this and to achieve the result.

Reply
Katarzyna - October 11, 2013

Dear Joe,
if I would like to test whole Twitter web service what endpoint should I choose?
Best Regards,

Reply
    Joe Colantonio - October 11, 2013

    Not sure what you mean by the “whole” twitter web services. I think you would have to use a bunch of the twitter apis to create a scenario like that. I don’t think there is just on wdsl for all the twitter functionality.

    Reply
Kapil Jain - January 17, 2014

Hi Joe, is it possible to define our own response so that webservice return the same ?

for example when you connect to rest webservice with request A then we know webservice will alway send respose B but I want response as per my requirement let say response C. is it possible ?

Please can you reply to my email at kapil.jain@cgi.com

Reply
    Joe Colantonio - January 17, 2014

    Ho not sure I understand – you want to mock a response that you know you will always get without actually calling the webservice that created the response?

    Reply
sagar - January 20, 2014

Hello Joe,

Do you have any video for load testing in soap ui? Also could you explain the parameter use in load testing like thread, delay, limit..etc.

Thanks

Reply
    Joe Colantonio - January 23, 2014

    Hi Sagar – unfortunately I don’t have any videos for load testing using loadUI. I will add it to my list of possible future posts. thanks for the suggestion!

    Reply
Swamy - January 22, 2014

Hi Joe Colantonio,

I am using SOAP UI PRO 4.6.3 version. Here i am unable to given REST service Name and also not editing. It is taking url name like(localhost).In File–> New REST Project —> url. example “http://localhost/CurrencyConvertor.asmx”. then it is taken service name as “localhost”. But here i need to give domain name.
Can you please help me.

Thanks,
Ram.

Reply
chan - January 31, 2014

We need to get the oauth key right? can you please give some info on this

Reply
Ram - March 7, 2014

This does not work with updated twitter api

Reply
    Joe Colantonio - March 12, 2014

    Hi Ram – yeah twitter changed their API awhile back and I have not updated the post yet. It is on my to-do list. thanks!

    Reply
tharaka - March 28, 2014

After the 6th step I’m getting following error

Sorry, that page does not exist

Reply
    Joe Colantonio - November 11, 2014

    Twitter changed their API. You know need to pass it outh authentication to have it work. I have on my to-do list to redo this with the new method

    Reply
Dipanshu - July 8, 2014

How can we set Matrix parameters of same name in soapUI tool testing?

Reply
Nitish - September 4, 2015

Hi Joe,

1) From where screen_name parameter should be taken?

2) Is there any need to add authorization in SOAP UI?

Reply
Click here to add a comment

Leave a comment: