Category:
Rest Assured
Rest Assured allows you to arrange your test script in BDD style using Given, When and Then.
Prerequisites to perform Request:- GIVEN
E.g.- Setting the Base URI, Base Path, Content Type , Request body (Payload) , cookies, headers , authentication , params etc.
Performing Request :- WHEN
E.g:- Which HTTP request to hit i.e. HTTP verbs – GET, POST etc
Verification and extracting response post hitting :- THEN
E.g. Verify status code, response data, log, extracting data etc.
// Given
RestAssured.given()
.baseUri("https://hireqa.co.in")
// When
.when()
.get("/register")
// Then
.then()
.statusCode(200)
.statusLine("HTTP/1.1 200 OK")
// To verify register count
.body("registerid", Matchers.hasSize(10))
// To verify booking id at index 3
.body("registerid[3]", Matchers.equalTo(1));