Skip to content

Commit

Permalink
Request aborts and getting the api for request and
Browse files Browse the repository at this point in the history
response
  • Loading branch information
An5hul-Choudhary committed Apr 18, 2024
1 parent 3e1acf7 commit ca5023a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/NetworkTest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ test('Login', async() =>{
response,
body,
})
//intercepting response -APi response-> { playwright fakeresponse}->browser->render data on front end
}
)

Expand Down
20 changes: 20 additions & 0 deletions tests/NetworkTest2.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { test,expect } = require('@playwright/test');


test('@QW Security test request intercept', async ({ page }) => {

//login and reach orders page
await page.goto("https://rahulshettyacademy.com/client");
await page.locator("#userEmail").fill("anshika@gmail.com");
await page.locator("#userPassword").type("Iamking@000");
await page.locator("[value='Login']").click();
await page.waitForLoadState('networkidle');
await page.locator(".card-body b").first().waitFor();

await page.locator("button[routerlink*='myorders']").click();
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=621661f884b053f6765465b6' }))
await page.locator("button:has-text('View')").first().click();
await expect(page.locator("p").last()).toHaveText("You are not authorize to view this order");

})
43 changes: 43 additions & 0 deletions tests/NetworkTest3.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const {test, expect} = require('@playwright/test');
const { timeLog } = require('console');
const exp = require('constants');



test('First Playwright test without cookies', async ({ page }) => {

const userName = page.locator('#username');
const passWord = page.locator("input[id='password']");
const signIn = page.locator("[name='signin']");
const cardTitles = page.locator(".card-body a");

page.route('**/*.{png,jpg,jpeg}', route => route.abort());

page.on('request', request => console.log(request.url()));
page.on('response', response => console.log(response.url(), response.status()));
await page.goto("https://rahulshettyacademy.com/loginpagePractise/");
console.log(await page.title());
// await expect(page).toHaveTitle("Google");

//#username or //input[@id='username']
await userName.fill("rahulshetty")
//#password or //input[@id='password']
await passWord.fill("learning");

await signIn.click();
console.log(await page.locator("[style*='block']").textContent());
await expect(page.locator("[style*='block']")).toContainText('Incorrect');

// Enterning correct details now
await userName.fill("");
await userName.fill("rahulshettyacademy");
await signIn.click();

console.log(await cardTitles.nth(0).textContent()); // it will wait until the DOM is attached so after this the next step of displaying all card titles is not failing
const allTitles = await cardTitles.allTextContents(); //allTextContent returns array it can return 0 and many elements but playwright will not be able to understand how much to wait but in above it is sure that it will return one element only so it waits for that
console.log(allTitles);



});

0 comments on commit ca5023a

Please sign in to comment.