-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPI_July.java
More file actions
54 lines (37 loc) · 1.64 KB
/
API_July.java
File metadata and controls
54 lines (37 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.api;
import org.testng.annotations.Test;
import io.restassured.RestAssured;
import io.restassured.builder.RequestSpecBuilder;
import io.restassured.http.ContentType;
import io.restassured.path.json.JsonPath;
import io.restassured.response.Response;
import io.restassured.response.ValidatableResponse;
import io.restassured.specification.RequestSpecification;
import static io.restassured.RestAssured.baseURI;
import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.equalTo;
public class API_July
{
RequestSpecification reqSpec = new RequestSpecBuilder().
setContentType(ContentType.JSON). setBaseUri("https://reqres.in").build();
@Test
public void testAPI1()
{
RequestSpecification rest = given().contentType(ContentType.JSON);
Response rest2 = given().contentType(ContentType.JSON).when().get();
ValidatableResponse rest3 = given().contentType(ContentType.JSON).when().get().then().assertThat().statusCode(200);
}
@Test
public void testAPI2()
{
//RestAssured.baseURI = "https://reqres.in";
//Response response = given().spec(reqSpec).queryParam("page",2).get("/api/users");
Response response =given().spec(reqSpec).queryParam("page",2).get("/api/users");
String str = response.then().extract().asString();
System.out.println(response.then().extract().body().asPrettyString());
JsonPath path = new JsonPath(str);
System.out.println(path.getString("data[1].first_name"));
System.out.println("Print URL:- "+path.getString("support.url"));
System.out.println("Print total_pages:- "+path.getString("total_pages"));
}
}