restAssuredIntro
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package zacksolutions.DayOne;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import static io.restassured.RestAssured.*;
|
||||
import static io.restassured.matcher.ResponseAwareMatcher.*;
|
||||
import static org.hamcrest.Matcher.*;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class HttpRequest {
|
||||
public int id;
|
||||
public String job;
|
||||
@Test(priority = 1)
|
||||
void getUser() {
|
||||
when()
|
||||
.get("https://reqres.in/api/users?page=2")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("page", equalTo(2))
|
||||
.log().all();
|
||||
}
|
||||
@Test(priority = 2)
|
||||
void createUser(){
|
||||
HashMap<String,String> data = new HashMap<>();
|
||||
data.put("name", "Zakaria");
|
||||
data.put("job", "Engineer");
|
||||
|
||||
id = given().contentType("Application/json").body(data).when().post("https://reqres.in/api/users").jsonPath().getInt("id");
|
||||
System.out.println(id);
|
||||
}
|
||||
@Test(priority = 3, dependsOnMethods = {"createUser"})
|
||||
void updateUser(){
|
||||
|
||||
HashMap<String,String> data = new HashMap<>();
|
||||
data.put("name", "Sami");
|
||||
data.put("job", "Engineer/Surgeon");
|
||||
given().contentType("Application/json").body(data).when().put("https://reqres.in/api/users/" + id).then().statusCode(200).log().all();
|
||||
}
|
||||
@Test(priority = 4)
|
||||
void deleteUser(){
|
||||
when().delete("https://reqres.in/api/users/" + id).then().statusCode(204).log().all();
|
||||
System.out.println("id number: " + id + " is deleted");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user