From e1757506b4b2a2cf3bbea38197cce902c678417e Mon Sep 17 00:00:00 2001 From: Cristi-Fogel <37100222+Cristi-Fogel@users.noreply.github.com> Date: Thu, 22 Aug 2024 08:56:12 +0300 Subject: [PATCH] iframe, hover, events start working on the api components/validations --- tests/moreValidations.spec.js | 15 +++++- tests/webApiPart1.spec.js | 96 +++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 tests/webApiPart1.spec.js diff --git a/tests/moreValidations.spec.js b/tests/moreValidations.spec.js index 5945fce..a11d20a 100644 --- a/tests/moreValidations.spec.js +++ b/tests/moreValidations.spec.js @@ -1,4 +1,5 @@ const { test, expect } = require("@playwright/test"); +const { text } = require("stream/consumers"); test("Popup validations", async({page})=> { @@ -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(); -}) \ No newline at end of file + // 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 +}) diff --git a/tests/webApiPart1.spec.js b/tests/webApiPart1.spec.js new file mode 100644 index 0000000..57728ab --- /dev/null +++ b/tests/webApiPart1.spec.js @@ -0,0 +1,96 @@ +const {test, expect, request} = require('@playwright/test'); +const loginPayload = {userEmail:"cf@mailinator.com",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 = "cf@mailinator.com"; + + 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