Skip to content

Commit

Permalink
iframe, hover, events
Browse files Browse the repository at this point in the history
start working on the api components/validations
  • Loading branch information
Cristi-Fogel committed Aug 22, 2024
1 parent db8e122 commit e175750
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 1 deletion.
15 changes: 14 additions & 1 deletion tests/moreValidations.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { test, expect } = require("@playwright/test");
const { text } = require("stream/consumers");

test("Popup validations", async({page})=>
{
Expand All @@ -9,6 +10,18 @@ test("Popup validations", async({page})=>
await expect(page.locator("#displayed-text")).toBeVisible();
await page.locator("#hide-textbox").click();
await expect(page.locator("#displayed-text")).toBeHidden();

// java popup events(not web/html)
await page.locator("#confirmbtn").click();
page.on('dialog', dialog => dialog.accept());
// page.on('dialog', dialog => dialog.dismiss());

//hover elements
await page.locator("#mousehover").hover();

})
// change to iframes
const framesPage = page.frameLocator("#courses-iframe");
await framesPage.locator("li a[href*='lifetime-access']:visible").click(); //this will also scroll into view the element
const textCheck = await framesPage.locator(".text h2").textContent(); //string is "join 13242 happy subscribers" -- so we split and grab what we need
console.log(textCheck.split(" ")[1]); //split on whitespace
})
96 changes: 96 additions & 0 deletions tests/webApiPart1.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
const {test, expect, request} = require('@playwright/test');
const loginPayload = {userEmail:"[email protected]",userPassword:"Password1"};
const loginURL = "https://rahulshettyacademy.com/api/ecom/auth/login";

test.beforeAll( async ()=>{
const apiContext = await request.newContext();
const loginResponse = await apiContext.post(loginURL, {
data:loginPayload
});
expect(loginResponse.ok()).toBeTruthy();
const loginResponseJson = loginResponse.json();
const token = loginResponseJson.token;

});
// test.beforeEach( ()=>{
// //code
// })


test('Browser check', async ({page})=>
{
const products = page.locator(".card-body");
const searchForProductName = 'ZARA COAT 3';
const email = "[email protected]";

await page.goto("https://rahulshettyacademy.com/client");
await page.locator("#userEmail").fill(email);
await page.locator("#userPassword").fill("Password1");
await page.locator("[value='Login']").click();
await page.locator(".card-body b").first().waitFor(); // products to loadup

const titles = await page.locator(".card-body b").allTextContents();
console.log(titles);
// await page.pause();
//hunt for product 'Zara Coat 4' to click on it
const countProducts = await products.count();
for (let i=0; i < countProducts; ++i)
{
if(await products.nth(i).locator("b").textContent() === searchForProductName)
{
//logic to add product to cart, since we've identified the one we search for
await products.nth(i).locator("text= Add To Cart").click();
break; //found it, no need to continue loop
}
}
// await page.pause();
//goto cart
await page.waitForLoadState('networkidle')
await page.locator("button[routerlink='/dashboard/cart']").dispatchEvent('click');
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)

const bool = await page.locator("h3:has-text('Zara Coat 3')").isVisible(); //check that it exists -- returns boolean value
expect(bool).toBeTruthy(); //TODO: check evauluation if not fixed at end of course
await page.locator("li[class='totalRow'] button[type='button']").click(); //checkout button
// await page.pause();

//checkout page
await page.locator("[placeholder*='Country']").pressSequentially("ro", {delay:100}); // input field, shows results per input so pressing 1letter at a time
const countryDropdown = page.locator(".ta-results");
await countryDropdown.waitFor(); //wait until is shown
const countryDropdownCount = await countryDropdown.locator("button").count();
for(let i=0; i<countryDropdownCount; ++i){
const text = await countryDropdown.locator("button").nth(i).textContent();
if(text === " Romania"){ //could use trim to trim spaces, or can use the 'includes' option
await countryDropdown.locator("button").nth(i).click();
break;
}
}
// await page.pause();

//asertions for the page
expect(page.locator(".user__name [type='text']").first()).toHaveText(email);
await page.locator(".action__submit").click(); // place order button

//thankyou for oder page
await expect(page.locator(".hero-primary")).toHaveText(" Thankyou for the order. ");
const orderID = await page.locator(".em-spacer-1 .ng-star-inserted").textContent();
console.log("Order ID is: " + orderID);

//orders page
await page.locator("button[routerlink='/dashboard/myorders']").dispatchEvent('click');
await page.locator("tbody").waitFor(); //waiting for whole table-body to loadup, prior to making the evaluation #async breakage
const rows = await page.locator("tbody tr"); //waiting for table data to be loaded up

for(let i=0; i<await rows.count(); i++){
const rowOrderId = await rows.nth(i).locator("th").textContent();
if (orderID.includes(rowOrderId))
{
await rows.nth(i).locator("button").first().click();
break;
}
}
const orderIdDetails = await page.locator(".col-text").textContent();

expect(orderID.includes(orderIdDetails)).toBeTruthy();
})

0 comments on commit e175750

Please sign in to comment.