Saturday, February 8, 2020

REST Assured Static Import

Most of the time we have used all the static method of REST Assured using Class reference of REST Assured classes

But we can use the static method of REST Assured classes using static import.


import static io.restassured.RestAssured.given;  

Now we can use given() method directly no required of RestAssured to access given() method

import org.testng.annotations.Test;

import static io.restassured.RestAssured.given;
import io.restassured.builder.RequestSpecBuilder;
import io.restassured.http.ContentType;
import io.restassured.specification.RequestSpecification;

public class ValidateAPI {

    @Test
    public void validateSimpleAPI() {
       
        RequestSpecification requestSpecification = new RequestSpecBuilder().setBaseUri("http://restapi.demoqa.com/utilities/weather/city/")
                .setContentType(ContentType.JSON)
                .addFilter(new CustomLoggingFilter())
                .build();
       
        given(requestSpecification).when().get("/Hyderabad").then();
       
    }
}


Robot Framework set up

Now a days most of the time we are looking for configuration based and less coding tools for development and testing as well.

Robot Framework is such kind of automation tool where we can say development of automation scenario is much easier with less coding.

Now we will learn how we can configure Robot framework

Step 1:


Download python from here


 
Step 2:

Select the checkbox Add Python  to path.


Step 3:

Check the python installation
                                                             python --version
                                                             python -v
                                                             pip --version
                                                             pip -v


Step 4:


Install Robot Framework using the following command:

                                                           pip install robotframework

                                                           pip install --upgrade robotframework
 

Step 5:


Install robotframework-seleniumlibrary using the following command

                                                          pip install robotframework-seleniumlibrary

                                                          pip install --upgrade robotframework-seleniumlibrary
 
Step 6:


Open Eclipse Marketplace…
Help ->  Eclipse Marketplace...
 
Step 7:


Search for robot framework plugin we will use RED – Robot Editor

 

Add python plugin PyDev


Step 8:


After completion of successful installation, we get the RED – Robot Editor documentation.
 

 
We can open the documentation from here.



We can also get the details from the official GitHub page.
 

Step 9:


Add Perspective for Robot from Eclipse
Window -> Perspective -> Open Perspective -> Other…


 

Select Robot from Open Perspective window and click on Open button.



Now we can see the Robot perspective added in eclipse.
 




Also Check Robot Preferences from
Window -> Preferences -> Robot



Step 10:

Create a new Robot project File -> New -> Project 





Select Robot Project from Robot Framework section



Then give a name of this project and click Finish
 



Step 11:


Add a new Test Suite



 
Step 12: 


Type the following code for robot script.


*** Test Cases ***
MyFirstRobotTest
    Log   Hello 
Right click on the file and run.