/// <reference types = "Cypress"/>
//*api testing*//
describe("api testing", () => {
//1) GET request
it("GET", () => {
cy.request({
method: "GET",
url: "https://reqres.in/api/users?page=2",
}).then((res) => {
cy.log(res);
cy.log(res.body.data);
expect(res.body.data[0]).to.have.property("id");
expect(res.body.data[0]).to.have.keys(
"id",
"avatar",
"email",
"first_name",
"last_name"
);
//assert every element at a time using forEach method:
let arry = res.body.data;
arry.forEach((el) => {
expect(el).to.have.keys(
"id",
"avatar",
"email",
"first_name",
"last_name"
);
});
});
});
//2) POST request
it("POST", () => {
cy.request({
method: "POST",
url: "https://reqres.in/api/users",
body: {
name: "morpheus",
job: "leader",
},
}).then((res) => {
cy.log(res);
cy.log(res.body);
expect(res.body).to.have.property("job", "leader");
expect(res.body).to.have.property("name", "morpheus");
});
});
//3) PUT request
it("PUT", () => {
cy.request({
method: "PUT",
url: "https://reqres.in/api/users/2",
body: {
name: "morpheus",
job: "zion resident",
},
}).then((res) => {
// cy.log(res);
// cy.log(res.body);
expect(res.body.job).to.equal("zion resident");
expect(res.body.name).to.equal("morpheus");
expect(res.status).to.equal(200);
});
});
//4) DELETE request
it.only("DELETE", () => {
cy.request({
method: "DELETE",
url: "https://reqres.in/api/users/2",
}).then((res) => {
expect(res.status).to.equal(204);
});
});
});
टिप्पण्या
टिप्पणी पोस्ट करा
आपल्या प्रतिक्रियेबद्दल धन्यवाद ! आम्ही लवकरात लवकर प्रतिक्रियेला उत्तर देण्याचा प्रयत्न करू