
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use the then method in Rest Assured?
We can use the then method in Rest Assured. It is mainly used to validate a Response obtained from a request. Thus, most assertions are included within a then method.
Syntax
RestAssured.baseURI = "http://dummy.restapiexample.com"; //GET operation with then methods given() .when().get("/api/v1/employees").then() //verify status code as 404 .assertThat().statusCode(404);
Example
Code Implementation
import org.testng.annotations.Test; import static io.restassured.RestAssured.*; import io.restassured.RestAssured; public class NewTest { @Test void test() { //base URL RestAssured.baseURI = "http://dummy.restapiexample.com"; //input details for GET request given() .when().get("/api/v1/employee/1") //verify status code as 200 within then method .then().log().all() .assertThat().statusCode(200); } }
Output
Advertisements