-
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.
start working on network interception test (request/body/response alt…
…eration)
- Loading branch information
1 parent
b24ae68
commit 7910c6d
Showing
4 changed files
with
72 additions
and
2 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
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
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,49 @@ | ||
const {test, expect, request} = require('@playwright/test'); | ||
const {APiUtils} = require('./utils/APiUtils'); | ||
|
||
const loginPayload = {userEmail:"[email protected]",userPassword:"Password1"}; | ||
const orderPayload = {orders:[{country:"Romania",productOrderedId:"6581ca399fd99c85e8ee7f45"}]}; | ||
|
||
let response; | ||
let fakePayloadOrders = {data: [], message:"No Orders"}; | ||
|
||
test.beforeAll(async () => { | ||
const apiContext = await request.newContext(); | ||
const apiUtils = new APiUtils(apiContext, loginPayload); | ||
response = await apiUtils.createOrder(orderPayload); | ||
}); | ||
|
||
test('@API Place the order', async ({page})=> | ||
{ | ||
await page.addInitScript(value => { | ||
window.localStorage.setItem('token',value); | ||
}, | ||
response.token ); | ||
await page.goto("https://rahulshettyacademy.com/client"); | ||
const products = page.locator(".card-body"); | ||
|
||
//mock the orders call --reroute how we want it | ||
// await page.route("https://rahulshettyacademy.com/api/ecom/order/get-orders-for-customer/65fd2ecda86f8f74dca8070b", //with explicit id of customer (wildcard for wokring with any) | ||
await page.route("https://rahulshettyacademy.com/api/ecom/order/get-orders-for-customer/*", | ||
async route=>{ | ||
//response interception -> [i am here] API response->browser->render data | ||
const response = await page.request.fetch(route.request()); | ||
let body = JSON.stringify(fakePayloadOrders); | ||
route.fulfill( | ||
{ | ||
response, | ||
body, | ||
} | ||
) | ||
} | ||
); | ||
// await page.pause(); | ||
//orders page | ||
await page.locator("button[routerlink='/dashboard/myorders']").dispatchEvent('click'); | ||
await page.waitForResponse("https://rahulshettyacademy.com/api/ecom/order/get-orders-for-customer/*"); | ||
console.log(await page.locator(".mt-4").textContent()); | ||
|
||
|
||
|
||
|
||
}) |
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,19 @@ | ||
|
||
|
||
|
||
|
||
test('Security test request intercept', async(page)=> | ||
{ | ||
//login and reach orders page | ||
|
||
//intercept the view-call | ||
await page.route("https://rahulshettyacademy.com/api/ecom/order/get-orders-details?id=*", | ||
route=>route.continue({ | ||
url: 'https://rahulshettyacademy.com/api/ecom/order/get-orders-details?id=621661884053f676546b6' | ||
}) | ||
|
||
) | ||
//once identified *all, click on View button for it | ||
await page.locator("button:has-text('View')").click(); | ||
|
||
}) |