Automation Testing

soapUI – How to Test a REST Service

By Test Guild
  • Share:
Join the Guild for FREE

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!

  1. 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

  2. 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.

  3. 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

  4. 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

  5. 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”>
    ]]>

  6. 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.

  7. 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

  8. 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.

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

  10. 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.

  11. 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

  12. 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

  13. 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.

  14. 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!

  15. Hi Joe,

    1) From where screen_name parameter should be taken?

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

  16. i have post the rest api request where i am getting the error in response HTTP Status 415 – Cannot consume content type…so my question is where i need to set the content type

    thanks in advance

    regards
    mahadev

  17. hi,
    i have 40+ rest so how to use all rest api in rest one by one without any human interface.can i use script in SOAPUI? if yes, so please give me a step how to use it

Comments are closed.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Symbolic AI vs. Gen AI: The Dynamic Duo in Test Automation

Posted on 09/23/2024

You've probably been having conversations lately about whether to use AI for testing. ...

8 Special Ops Principles for Automation Testing

Posted on 08/01/2024

I recently had a conversation, with Alex “ZAP” Chernyak about his journey to ...

Top 8 Open Source DevOps Tools for Quality 2024

Posted on 07/30/2024

Having a robust Continuous Integration and Continuous Deployment (CI/CD) pipeline is crucial. Open ...