Rest Assured API Test - Java
import io.restassured.RestAssured;
import io.restassured.path.json.JsonPath;
import io.restassured.response.Response;
import org.testng.annotations.Test;
import java.util.HashMap;
public class testAPI {
Response res = RestAssured.given().when().get("https://reqres.in/api/users?page=2");
@Test
public void checkStatus(){
HashMap<String, String> hm = new HashMap<>();
hm.put("name","raman");
hm.put("job","tester");
Response postcall = RestAssured.given().contentType("application/json").when().body(hm).post("https://reqres.in/api/users");
System.out.println(postcall.asString());
}
@Test
public void checkBody(){
JsonPath jsonpath = new JsonPath(res.asString());
System.out.println(jsonpath.get("data[0].id").toString());
}
}
Comments
Post a Comment