

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
- Related Questions & Answers
- How to use Assertion in response in Rest Assured?
- How to use TestNG data providers for parameterization in Rest Assured?
- What is Rest Assured?
- How to handle static JSON in Rest Assured?
- How to validate XML response in Rest Assured?
- How to transform the response to the Java list in Rest Assured?
- Validate JSON Schema in Rest Assured.
- Explain DELETE request in Rest Assured.
- What is XmlPath in Rest Assured?
- Explain PUT request in Rest Assured.
- How to verify JSON response headers in Rest Assured?
- How to handle responses in text format in Rest Assured?
- How to get the response time of a request in Rest Assured?
- How to validate the response time of a request in Rest Assured?
- What is JSON parsing in Rest Assured?
Advertisements