Setup Rest Assured with Eclipse


Rest Assured is a java library for testing of REST services.Rest-Assured is an open-source Java Domain-Specific Language (DSL). It omits the requirement of using boiler-plate code to test complex API responses and supports both XML and JSON. An official guide of Rest Assured can be found here: 
Rest Assured Official Guide


Introduction:

REST Services are used for communication between two platforms which may be are developed using different languages or technologies. The reason behind automation rest services is that it takes less time as well as it helps to find defects earlier as it can be tested before UI is developed.
What are Rest API's:
REST is the underlying architectural principle of the web. The amazing thing about the web is the fact that clients (browsers) and servers can interact in complex ways without the client knowing anything beforehand about the server and the resources it hosts. The key constraint is that the server and client must both agree on the media used, which in the case of the web is HTML.
Rest API's are stateless and cacheless. They don't store information. REST is implemented in XML as well as JSON. Conversion of JSON objects into Java objects is very easy. REST architecture follows the CRUD ( Create, Read, Update and Delete ) Style where Create means POST request, Read means GET request, Update means PUT request and Delete request.We can communicate with REST API with above four requests.
A Real Example of REST API can be found on below link:
Creating a Maven project in Eclipse for Rest Assured:
Step1 : Open Eclipse and Click on File --> New --> Other 



Step 2: Select Maven project and Click on Next button












Step 3: Provide workspace location and click on Next button



















Step 4:
Select the highlighted archetype displayed in the below image and click on Next button.









Step 5: Specify Group Id, artifact id, package name and click on Finish button




Now a maven project will be available on your project list.

Step 6: In pom.xml file, present at bottom of your project add the following dependencies and save the file.

<dependencies>
     <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.9.10</version>
     </dependency>

     <dependency>
        <groupId>io.rest-assured</groupId>
        <artifactId>rest-assured</artifactId>
        <version>3.2.0</version>
    </dependency>
    <dependency>
        <groupId>io.rest-assured</groupId>
        <artifactId>json-path</artifactId>
        <version>3.2.0</version>
    </dependency>

    <dependency>
        <groupId>io.rest-assured</groupId>
        <artifactId>json-schema-validator</artifactId>
        <version>3.2.0</version>
    </dependency>

</dependencies>



Step 7:  Add following build plugins in pom.xml

<build>
    <plugins>
       
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.18.1</version>
            <configuration>
                <suiteXmlFiles>
                <suiteXmlFile>testng.xml</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>
        </plugin>
        
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.5.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
           </configuration>
        </plugin>

    </plugins>
</build>

Now right click on the project then click on Maven and the click on Update Project. 




































All the required libraries will be downloaded and will be available for your project.

In next post, we will learn about how to work with GET Requests using Rest Assured.

Comments

Popular posts from this blog

Extracting an XML Response with Rest-Assured