Skip to content

Commit

Permalink
Add code for intercept
Browse files Browse the repository at this point in the history
  • Loading branch information
damienteo committed Nov 17, 2023
1 parent 786468c commit be2eeb8
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ module.exports = defineConfig({
},
e2e: {
setupNodeEvents,
specPattern: "cypress/integration/examples/BDD/*.feature",
specPattern: "cypress/integration/examples/*.js",
},
});
28 changes: 28 additions & 0 deletions cypress/integration/examples/fakeTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/// <reference types='Cypress' />

describe("Intercept Test suite", () => {
it("should display different results", () => {
cy.visit("https://rahulshettyacademy.com/angularAppdemo");

cy.intercept(
{
method: "GET",
url: "https://rahulshettyacademy.com/Library/GetBook.php?AuthorName=shetty",
},
{
statusCode: 200,
body: [
{ book_name: "RestAssured with Java", isbn: "RSU", aisle: "2301" },
],
}
).as("bookRetrievals");

cy.get('button[class="btn btn-primary"]').click();

cy.wait("@bookRetrievals").then(({ request, response }) => {
cy.get("tr").should("have.length", response.body.length + 1);
});

cy.get("p").should("have.text", "Oops only 1 Book available");
});
});
25 changes: 25 additions & 0 deletions cypress/integration/examples/fakeTest2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/// <reference types='Cypress' />

describe("Intercept Test suite", () => {
it("should display different results", () => {
cy.visit("https://rahulshettyacademy.com/angularAppdemo");

cy.intercept(
"GET",
"https://rahulshettyacademy.com/Library/GetBook.php?AuthorName=shetty",
(request) => {
request.url =
"https://rahulshettyacademy.com/Library/GetBook.php?AuthorName=malhotra";
request.continue((response) => {
// expect(response.statusCode).to.equal(403);
});
}
).as("dummyUrl");

cy.get('button[class="btn btn-primary"]').click();

cy.wait("@dummyUrl").then(({ request, response }) => {
cy.get("tr").should("have.length", response.body.length + 1);
});
});
});

0 comments on commit be2eeb8

Please sign in to comment.