• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • Home
  • Programming Languages
    • Java Tutorials
    • Python Tutorials
    • JavaScript Tutorials
  • Automation Tools and Different Tools
    • Web Automation
      • Selenium with Java
        • Selenium Basic
        • Selenium Advance
        • Selenium Realtime
        • Framework
        • Selenium Interview
        • Selenium Videos
        • Selenium with Docker
      • Selenium with Python
      • WebdriverIO
        • Selenium Webdriver C# Tutorial
      • Cypress
      • Playwright
    • TestNG
    • Cucumber
    • Mobile Automation
      • Appium
    • API Testing
      • Postman
      • Rest Assured
      • SOAPUI
    • testRigor
    • Katalon
    • TestProject
    • Serenity BDD
    • Gradle- Build Tool
    • RPA-UiPath
    • Protractor
    • Windows Automation
  • Automation For Manual Testers
  • Services
  • Online Training
  • Contact us
  • About me
  • Follow us
    • Linkedin
    • Facebook Group
    • Facebook Page
    • Instagram

Automation

Selenium WebDriver tutorial Step by Step

You are here: Home / REST Assured / How to Configure REST Assured with Eclipse

How to Configure REST Assured with Eclipse

August 25, 2018 by Mukesh Otwani 28 Comments

Configure REST Assured with Eclipse

In this post, we will discuss how to Configure REST Assured with Eclipse in simple ways. In order to start our first script with REST Assured we should have our local environment ready.

Things we need in order to start with REST Assured

1- System (Laptop/Desktop), any Browser and Internet Connection (That you already have) 😉

2- Java- Any version of Java will work, In this series I will be using Java 8

3- Code Editor (Eclipse)- You can use any editor since I am good with Eclipse so I will be using the same for complete series

4- Maven – If you are using latest version of Maven then by default Maven plugin comes with eclipse.

5- Testing Framework- To validate result in Rest Assured we need some Testing framework Like TestNG or JUnit. I will be using TestNG for the same.

6- Your time, effort and patience 🙂

As of now these tools/ Libraries are enough to start with our REST Assured and once we will move to advance level we will use different tools as well like Jenkins, Cucumber, Git and Github and so on.

Configure REST Assured with Eclipse

 

I already have a detailed video on the same.

 

Configure REST Assured with Eclipse

Step 1- Create a simple Maven project ‘RestAssuredProject’ in eclipse. The project structure will be as below:

 

Step 2: Find the latest stable version of ‘rest-assured’ Dependency

Navigate to http://rest-assured.io/

Navigate to footer section and Click on Getting Started Link and Copy the below dependency

<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.1.1</version>
<scope>test</scope>
</dependency>


You can also use 3.1.0 new version as of now.

 

Step 3: Add the above Dependency in pom.xml of the project

After adding rest-assured dependency in pom.xml, save the file. The Maven Dependencies section will be added automatically. You can find the jars as shown below in your project.

Dependency

Note: If the jar file is not added in the Maven dependencies section after saving, then clean and build the project.

 

Step 4: Create a new package and a new class

In src/test/java, create a package ‘getRequest’ and a java file ‘GetData’ as below.

 

Step 5: Add TestNG library to the project

Right click on Project -> Build Path -> Add Libraries -> TestNG

 

Step 6: Write the code as below:

We are using https://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=b6907d289e10d714a6e88b30761fae22 

Code

In the above class ’GetData’, we have initialized the variable api with a Sample API. You can also use any other API. There are 2 methods in this class:

  1. testResponseCode: Get the status code of the API and verify that the response is success(200) using Assert.
  2. testBody: Get the response time of the API and print it.

Rest Assured class provides the ‘get’ method for makng GET request to the API. The ‘getStatusCode’ method returns the response and the ‘getTime’ method returns the response time.

Note: We have imported io.restassured.RestAssured class and made it static so that we can use its methods(such as get method) directly without calling RestAssured class.

 

Step 7: Execute the test script and Verify the result

The following result will be generated after executing the above code using TestNG. The code and the Response will be printed in the console.

output
Hope you liked the article and if yes then please share with your friends.

Filed Under: REST Assured Tagged With: Configure REST Assured with Eclipse

Reader Interactions

Comments

  1. learner says

    February 19, 2022 at 12:53 AM

    I followed this exactly but getting

    [RemoteTestNG] detected TestNG version 7.4.0
    java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7

    and
    FAILED: testbody
    java.lang.NoClassDefFoundError: Could not initialize class io.restassured.RestAssured

    FAILED: testResponseCode
    java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.reflection.ReflectionCache
    at org.codehaus.groovy.runtime.dgmimpl.NumberNumberMetaMethod.(NumberNumberMetaMethod.java:33)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

    Reply
    • Mukesh Otwani says

      February 21, 2022 at 11:27 AM

      Hi Mate,

      Please try using different version of RestAssured. Which version you are using?

      Reply
  2. Balamurugan V says

    July 2, 2021 at 11:59 AM

    Thanks Mukesh..

    Clear artifact and demo video.. This is very useful..

    Reply
  3. sony says

    March 3, 2020 at 2:28 PM

    I have added maven dependency in the project for rest assured jar but its jar is there but it is not identifying rest assured methods

    Reply
    • Mukesh Otwani says

      March 3, 2020 at 3:11 PM

      Hi Sony,

      Do maven update for your project and try again

      Reply
  4. Manju says

    February 5, 2020 at 10:31 PM

    to test the Microservice REST API, is there is any additional thing i need to do in the Maven project?

    Reply
    • Mukesh Otwani says

      February 6, 2020 at 1:11 PM

      Hi Manju,

      If you are done with required configurations then you can go ahead with Microservices Rest API testing.

      Reply
  5. christina says

    January 28, 2020 at 3:03 PM

    can we see the response data, for the API which we test using this??

    Reply
    • Mukesh Otwani says

      January 28, 2020 at 6:31 PM

      Hi Christina,

      Yes, you will get whole response data in String format using asString() method

      Reply
  6. Shivaraj says

    July 31, 2019 at 10:47 PM

    Dear Mukesh I am asserting status code through poi library means fetching expected status code through Excel but I am getting below error “reference to assertequals ambiguous” if I run through maven but it is working when I run through testing please guide me

    Reply
    • Mukesh Otwani says

      August 5, 2019 at 12:49 AM

      Hi Shivraj,

      Using Apache POI, if you read any numerical data from excel then it always returns double type. Please refer this link for better understanding

      Reply
  7. Masthan says

    June 13, 2019 at 8:50 PM

    hi Mukesh,

    While try to execute the code, it is giving following mesage

    java.net.ConnectException: Connection timed out: connect

    i unable to find out why i am getting this exception

    Reply
    • Mukesh Otwani says

      June 13, 2019 at 9:16 PM

      Hi Masthan,

      Are you running your script in your organizational network, if so then there is a network restriction.

      Reply
  8. RAAJ says

    May 20, 2019 at 3:05 PM

    Hi mukesh,

    I am testing SOAP services. How Can I validate XMl using REST assured ?

    Reply
    • Mukesh Otwani says

      May 20, 2019 at 7:08 PM

      Hi Raaz,

      Rest Assured can only be used with Rest APIs which deals with JSON data not xml

      Reply
  9. Ruchi says

    March 27, 2019 at 12:30 PM

    Hi Mukesh,

    Can we configure eclipse with POSTMAN for api automation? If yes then can you pls provide video.

    Thanks

    Reply
    • Mukesh Otwani says

      March 27, 2019 at 6:20 PM

      Hi Ruchi,

      Are you using postman API for API testing or just Postman client tool. Could you please elaborate your requirement.

      Reply
  10. Milind says

    December 11, 2018 at 11:57 AM

    Thanks Mukesh Sir

    Reply
  11. Milind says

    December 9, 2018 at 12:35 AM

    Hello Mukesh Sir,

    Please post below videos in detail with example:
    1.Data providers and its use in selenium
    2.Collection and its use in selenium

    The above topics are the prime focus of interviewer.
    It will really helpful to our emerging automation testers.

    Thanks in advance.

    Reply
    • Mukesh Otwani says

      December 11, 2018 at 10:12 AM

      Hi Milind,

      I have already covered them Data Provider http://learn-automation.com/data-driven-framework-in-selenium-webdriver/
      Collection topics- List https://www.youtube.com/watch?v=OFjYA0apYGY you will also find for Set, Map

      Thanks
      Mukesh Otwani

      Reply
  12. shridhar says

    November 19, 2018 at 2:13 PM

    is selenium manadatory for api testing and api test framwork design ?

    Reply
    • Mukesh Otwani says

      November 20, 2018 at 9:52 AM

      Hi Sridhar,

      If you are looking for Rest based API testing then Selenium is not at all required. And for your information, Selenium itself is an API which allow us to interact Web UI through code.

      Reply
  13. Dhanraj K says

    November 1, 2018 at 11:10 AM

    Hi Mukesh,
    Your teaching is mind blowing. Keep rocking.
    When can we expect sample code for PUT, PUSH and DELETE?

    Reply
    • Mukesh Otwani says

      November 1, 2018 at 11:32 AM

      Hi Dhanraj,

      I have video for this please have a look https://www.youtube.com/watch?v=7RUzarUREpo&t=1704s

      Reply
  14. Sanu says

    October 11, 2018 at 8:08 PM

    its really Fabulous Mukesh bhai..i will start soon Automating Postman API

    Reply
    • Mukesh Otwani says

      October 12, 2018 at 12:53 PM

      Hi Sanu,

      Keep learning…:)

      Reply
  15. Anurag Bhatia says

    August 28, 2018 at 1:03 AM

    Dear Sir,
    You have given the methods for “get” request, thanks for that.
    Can you please share the sample code for “PUT”, “PUSH”, “DELETE” & oblige ?
    Thanks

    Reply
    • Mukesh Otwani says

      August 28, 2018 at 8:33 AM

      Hi Anurag,

      I’ll upload remaining all soon…:)

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Free Selenium Videos

https://www.youtube.com/watch?v=w_iPCT1ETO4

Search topic

Top Posts & Pages

  • Selenium Webdriver tutorial for beginners
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Selenium Webdriver C# Tutorial
  • WHAT ARE YOUR EXPECTATIONS FROM US?

Stay connected via Facebook

Stay connected via Facebook

Archives

Footer

Categories

Recent Post

  • API Testing Using Postman And RestAssured
  • Disable Personalise Your Web Experience Microsoft Edge Prompt In Selenium
  • How To Fix Error: No tests found In Playwright
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Best and easy way to Group test cases in selenium

Top Posts & Pages

  • Selenium Webdriver tutorial for beginners
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Selenium Webdriver C# Tutorial
  • WHAT ARE YOUR EXPECTATIONS FROM US?