Skip to content

Commit

Permalink
Mocking the response to get the cart as empty
Browse files Browse the repository at this point in the history
  • Loading branch information
An5hul-Choudhary committed Apr 18, 2024
1 parent 9f86626 commit 3e1acf7
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/NetworkTest.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const {test,expect} = require('@playwright/test');
let webContext;
const fakePayLoad = {data:[],message:"No Orders"};

test.beforeAll(async({browser}) =>{
const context = await browser.newContext();
const page = await context.newPage();
const email = "anshika222@gmail.com";
await page.goto("https://rahulshettyacademy.com/client");
await page.locator("#userEmail").fill(email);
await page.locator("#userPassword").fill("Iamking@000");
await page.locator("[value='Login']").click();
await page.waitForLoadState('networkidle');
await context.storageState({path: 'state.json'});
webContext = await browser.newContext({storageState:'state.json'});
})

// Mocking the response to get the cart as empty and checking the message
test('Login', async() =>{

const page = await webContext.newPage();

await page.goto("https://rahulshettyacademy.com/client");

await page.route("https://rahulshettyacademy.com/api/ecom/order/get-orders-for-customer/*",
async route => {
const response = await page.request.fetch(route.request());
let body = JSON.stringify(fakePayLoad);
route.fulfill({
response,
body,
})
}
)

await page.locator("button[routerlink*='myorders']").click();
//waiting for response
await page.waitForResponse("https://rahulshettyacademy.com/api/ecom/order/get-orders-for-customer/*")
console.log(await page.locator(".mt-4").textContent());


})

0 comments on commit 3e1acf7

Please sign in to comment.