Friday 6 November 2020

Top 30 API Testing Interview Questions & Answers for SDET/QAE? SET-03 Rest Assured Interview Questions and Answers



This is the third Set of API Testing Interview Question, for Set-01&02 refer below links.
 
Check below link for question SET-01&02:
Top API Interview Question 1-10


API Testing is one of the most used Testing types in the microservice architecture. If you are preparing for any interviews on SDET or Automation Roles, then I would definitely suggest learning API Automation with Rest Assured.

API testing has become absolutely vital with the rise of cloud applications and interconnected platforms. Many of the services we use daily rely on multiple interconnected APIs, so even if just one of them is malfunctioning, then the entire service is at risk.



Learning about APIs is not optional anymore..


In RESTful API, there are three common ways to pass data between the client and server: path parameter, query parameter, and form parameter.


****************

Path parameter

****************


Path parameters are used to identify a specific resource in the URL path. They are specified in the URL path and preceded by a colon (:). In RestAssured, we can pass path parameters using the pathParam() method.


EXAMPLE:

*********

Suppose we have a RESTful API endpoint that retrieves a user's information based on their ID, which is passed as a path parameter:

bash


GET /users/:id



CODE with Rest Assured:

************************


To pass the path parameter using RestAssured, we can use the pathParam() method like this:


int userId = 123;

given()

.pathParam("id", userId)

.when()

.get("/users/{id}")

.then()

.statusCode(200);


 
 
21. Define API Authentication method with Rest Assured for basic, Pre-emptive, Digest?

 
Click here for Answer with Scripts

 
 

22. How to pass Username and Password with form param in Rest Assured?
 

@Test
    public void getformParam() {
     
    Response resp = given().formParam("Username", "TestUser1","Password","pwd123")
        .when().get("http://automationReinvented/login");
    System.out.println(resp.getBody().asString());
    System.out.println("STATUS-CODE: "+resp.getStatusCode());
    assertEquals(resp.getStatusCode(),200);
    }

     

23.  How to Setup API automation framework from scratch using Rest Assured, Gradle with code?
 
 Click here for Answer with Code


 24. How to fetch List from Response Body in Rest Assured?
 

public static void verifyStatusCodeGET() {

    Response resp=given().when().get("https://reqres.in/api/users");
    System.out.println(resp.path("total").toString());
    assertEquals(resp.getStatusCode(),200);
   
   
    List<String> jsonResponse = resp.jsonPath().getList("data");}//data is list here

     

 Click for Job Openings and Apply

25. What are the dependencies used for Rest Assured framework in API Automation?

Click here for build.gradle file


26. Assuming you have a list of map in Response body and you have to fetch the third one, what command will you use? 

@Test(description="validate with jsonpath and json object and pass post body as json file")
public void MethodValidationPUT() throws IOException, ParseException {
        Response resp=given().when().get("https://reqres.in/api/users");
    System.out.println(resp.path("total").toString());
    assertEquals(resp.getStatusCode(),200);
Map<String, String> dataEmp = resp.jsonPath().getMap("data[2]");//data is a list of map
}



27. How to rerun failed test cases using listener?

 
28. How to run API test cases in parallel?
 
Answer: We can use TestNG in parallel with below options in the testng.xml suite.

<suite name="My suite" parallel="methods" thread-count="5">
<suite name="My suite" parallel="tests" thread-count="5">
<suite name="My suite" parallel="classes" thread-count="5">
<suite name="My suite" parallel="instances" thread-count="5">


29. How to push API Automation code to github?
 


*****************

Query parameter:

*****************


Query parameters are used to filter or sort data. They are specified in the URL query string and separated by an ampersand (&). In RestAssured, we can pass the query parameters using the queryParam() method.


EXAMPLE

***********


Suppose we have a RESTful API endpoint that retrieves a list of users based on their gender, which is passed as a query parameter:

bash


GET /users?gender=female


CODE with Rest Assured:

************************


To pass the query parameter using RestAssured, we can use the queryParam() method like this:


given()

.queryParam("gender", "female")

.when()

.get("/users")

.then()

.statusCode(200);


 
30. Can you write a pojo class for below Request Body?
 
Request Body:
{
    "name": "autouser",
    "job": "tester"
}
Answer: 

package pojo;

    public class pojoClas {
   
    public pojoClas(String name, String job) {
this.name = name;
    this.job = job;
    }
    private String name;
    private String job;

} // I will add more details about POJO in my next post so stay tuned and add the blog to your favourites.


REVISION:


4. What is the GET Method?

GET    Retrieve information about REST API resources

5. What is the POST Method?

POST    Create a REST API resource

6.What is the PUT Method?

PUT    Update the REST API resource

7. What is the DELETE Method?

DELETE    Delete REST API resources or related components
 


******************

Form parameter

******************


Form parameters are used to submit data to the server in an HTTP form. They are specified in the request body as key-value pairs. In RestAssured, we can pass form parameters using the formParam() method.


EXAMPLE

************


Suppose we have a RESTful API endpoint that creates a new user based on their name and email, which are passed as form parameters:


POST /users

Content-Type: application/x-www-form-urlencoded

name=Sidharth&email=sidharth@gmail.com


CODE with Rest Assured:

************************


To pass the form parameters using RestAssured, we can use the formParam() method like this:


given()

.formParam("name", "John")

.formParam("email", "sidharth@gmail.com")

.when()

.post("/users")

.then()

.statusCode(201);



To check API related topics and interview tips, check below and keep reading:

API Testing Content

TOP 15 BDD - CUCUMBER Interview Q&A


************************************************

✍️AUTHORLinkedIn Profile

************************************************

Learn (API-Microservice-Automation)Testing + Selenium UI Automation + SDET with Self Paced Videos prepared by FAANG employees and LIVE Doubt Session 

SDET TRANING VIDEOS AVAILABLE with Live Doubt Session. Check out the Training Page for Course Content or reach out @whatsapp +91-9619094122. 

This includes class-notes, 400+ interview questions, 3 projects, 20+ Java Coding question set for product companies along with career guidance from FAANG employees for Automation and SDET. We provide full support in clearing doubts & it is paid with very minimal amount.

We will also help you to design the best utility package and framework for your next project. Any doubts then reach out to us at the below whatsapp link.

Learning is directly proportional to earning so keep learning....

For more details whatsapp: https://lnkd.in/dnBWDM33


Check below link for question and answers with the code:

Top API Interview Question 1-10

Top API INterview Questions 11-20 

Top API AUTOMATION Interview Q&A - 21-30

*************************************************

SeleniumWebdriver Automation Testing Interview Questions:

https://automationreinvented.blogspot.com/search/label/SeleniumWebdriver

API Testing Interview Question Set:

https://automationreinvented.blogspot.com/2022/03/top-80-api-testing-interview-questions.html

DevOps Interview Q&A:

https://automationreinvented.blogspot.com/2021/11/top-11-devops-interview-questions-and.html 

Kubernetes Interview Question Set

https://automationreinvented.blogspot.com/search/label/Kubernetes

Docker Interview Question Set

https://automationreinvented.blogspot.com/Docker

Linux Interview question Set

https://automationreinvented.blogspot.com/search/label/Linux

Automation Testing/SDET Framework Design

https://automationreinvented.blogspot.com/search/label/FrameworkDesign

Java Related Interview Question Set

https://automationreinvented.blogspot.com/search/label/Java

GIT Interview Question Set:

https://automationreinvented.blogspot.com/2021/09/top-40-git-interview-questions-and.html

Coding Interview Question Set:

https://automationreinvented.blogspot.com/search/label/Coding%20Questions

Mobile Testing Interview Question Set:

https://automationreinvented.blogspot.com/search/label/Mobile%20Testing

Python Interview Question Set for QAE - SDET - SDE:

https://automationreinvented.blogspot.com/search/label/Python


 

No comments:

Post a Comment

All Time Popular Posts

Most Featured Post

API Status Codes with examples for QA-Testers

  🔺 LinkedIn: https://www.linkedin.com/in/sidharth-shukla-77b53145/ 🔺 Telegram Group:  https://t.me/+FTf_NPb--GQ2ODhl 🏮In API testing, it...