Skip to content

Commit e175750

Browse files
committed
iframe, hover, events
start working on the api components/validations
1 parent db8e122 commit e175750

File tree

2 files changed

+110
-1
lines changed

2 files changed

+110
-1
lines changed

tests/moreValidations.spec.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const { test, expect } = require("@playwright/test");
2+
const { text } = require("stream/consumers");
23

34
test("Popup validations", async({page})=>
45
{
@@ -9,6 +10,18 @@ test("Popup validations", async({page})=>
910
await expect(page.locator("#displayed-text")).toBeVisible();
1011
await page.locator("#hide-textbox").click();
1112
await expect(page.locator("#displayed-text")).toBeHidden();
13+
14+
// java popup events(not web/html)
15+
await page.locator("#confirmbtn").click();
16+
page.on('dialog', dialog => dialog.accept());
17+
// page.on('dialog', dialog => dialog.dismiss());
1218

19+
//hover elements
20+
await page.locator("#mousehover").hover();
1321

14-
})
22+
// change to iframes
23+
const framesPage = page.frameLocator("#courses-iframe");
24+
await framesPage.locator("li a[href*='lifetime-access']:visible").click(); //this will also scroll into view the element
25+
const textCheck = await framesPage.locator(".text h2").textContent(); //string is "join 13242 happy subscribers" -- so we split and grab what we need
26+
console.log(textCheck.split(" ")[1]); //split on whitespace
27+
})

tests/webApiPart1.spec.js

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
const {test, expect, request} = require('@playwright/test');
2+
const loginPayload = {userEmail:"[email protected]",userPassword:"Password1"};
3+
const loginURL = "https://rahulshettyacademy.com/api/ecom/auth/login";
4+
5+
test.beforeAll( async ()=>{
6+
const apiContext = await request.newContext();
7+
const loginResponse = await apiContext.post(loginURL, {
8+
data:loginPayload
9+
});
10+
expect(loginResponse.ok()).toBeTruthy();
11+
const loginResponseJson = loginResponse.json();
12+
const token = loginResponseJson.token;
13+
14+
});
15+
// test.beforeEach( ()=>{
16+
// //code
17+
// })
18+
19+
20+
test('Browser check', async ({page})=>
21+
{
22+
const products = page.locator(".card-body");
23+
const searchForProductName = 'ZARA COAT 3';
24+
const email = "[email protected]";
25+
26+
await page.goto("https://rahulshettyacademy.com/client");
27+
await page.locator("#userEmail").fill(email);
28+
await page.locator("#userPassword").fill("Password1");
29+
await page.locator("[value='Login']").click();
30+
await page.locator(".card-body b").first().waitFor(); // products to loadup
31+
32+
const titles = await page.locator(".card-body b").allTextContents();
33+
console.log(titles);
34+
// await page.pause();
35+
//hunt for product 'Zara Coat 4' to click on it
36+
const countProducts = await products.count();
37+
for (let i=0; i < countProducts; ++i)
38+
{
39+
if(await products.nth(i).locator("b").textContent() === searchForProductName)
40+
{
41+
//logic to add product to cart, since we've identified the one we search for
42+
await products.nth(i).locator("text= Add To Cart").click();
43+
break; //found it, no need to continue loop
44+
}
45+
}
46+
// await page.pause();
47+
//goto cart
48+
await page.waitForLoadState('networkidle')
49+
await page.locator("button[routerlink='/dashboard/cart']").dispatchEvent('click');
50+
await page.locator("div li").first().waitFor(); //wait until 1st item of list of items show up (1st item in list is populated with data)
51+
52+
const bool = await page.locator("h3:has-text('Zara Coat 3')").isVisible(); //check that it exists -- returns boolean value
53+
expect(bool).toBeTruthy(); //TODO: check evauluation if not fixed at end of course
54+
await page.locator("li[class='totalRow'] button[type='button']").click(); //checkout button
55+
// await page.pause();
56+
57+
//checkout page
58+
await page.locator("[placeholder*='Country']").pressSequentially("ro", {delay:100}); // input field, shows results per input so pressing 1letter at a time
59+
const countryDropdown = page.locator(".ta-results");
60+
await countryDropdown.waitFor(); //wait until is shown
61+
const countryDropdownCount = await countryDropdown.locator("button").count();
62+
for(let i=0; i<countryDropdownCount; ++i){
63+
const text = await countryDropdown.locator("button").nth(i).textContent();
64+
if(text === " Romania"){ //could use trim to trim spaces, or can use the 'includes' option
65+
await countryDropdown.locator("button").nth(i).click();
66+
break;
67+
}
68+
}
69+
// await page.pause();
70+
71+
//asertions for the page
72+
expect(page.locator(".user__name [type='text']").first()).toHaveText(email);
73+
await page.locator(".action__submit").click(); // place order button
74+
75+
//thankyou for oder page
76+
await expect(page.locator(".hero-primary")).toHaveText(" Thankyou for the order. ");
77+
const orderID = await page.locator(".em-spacer-1 .ng-star-inserted").textContent();
78+
console.log("Order ID is: " + orderID);
79+
80+
//orders page
81+
await page.locator("button[routerlink='/dashboard/myorders']").dispatchEvent('click');
82+
await page.locator("tbody").waitFor(); //waiting for whole table-body to loadup, prior to making the evaluation #async breakage
83+
const rows = await page.locator("tbody tr"); //waiting for table data to be loaded up
84+
85+
for(let i=0; i<await rows.count(); i++){
86+
const rowOrderId = await rows.nth(i).locator("th").textContent();
87+
if (orderID.includes(rowOrderId))
88+
{
89+
await rows.nth(i).locator("button").first().click();
90+
break;
91+
}
92+
}
93+
const orderIdDetails = await page.locator(".col-text").textContent();
94+
95+
expect(orderID.includes(orderIdDetails)).toBeTruthy();
96+
})

0 commit comments

Comments
 (0)