-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mocking the response to get the cart as empty
- Loading branch information
1 parent
9f86626
commit 3e1acf7
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
|
||
|
||
}) |