|
| 1 | +const {test, expect} = require('@playwright/test'); |
| 2 | +const { title } = require('process'); |
| 3 | + |
| 4 | +test('First test ever', async ({browser})=> |
| 5 | +{ |
| 6 | + const context = await browser.newContext(); |
| 7 | + const page = await context.newPage(); |
| 8 | + |
| 9 | + await page.goto("https://rahulshettyacademy.com/loginpagePractise/"); |
| 10 | +}); |
| 11 | + |
| 12 | + |
| 13 | +test('Browser Input Error Message test', async ({page})=> |
| 14 | +{ |
| 15 | + const userNameInput = page.locator('#username'); |
| 16 | + const signInButton = page.locator("#signInBtn"); |
| 17 | + //products page |
| 18 | + const productCardTitles = page.locator(".card-body a"); |
| 19 | + |
| 20 | + await page.goto("https://rahulshettyacademy.com/loginpagePractise/"); |
| 21 | + await userNameInput.fill("rahulshe"); |
| 22 | + await page.locator("[type='password']").fill("learning"); |
| 23 | + await signInButton.click(); |
| 24 | + //no explicit wait needed like selenium (takes one from config 30s) |
| 25 | + console.log(await page.locator("[style*='block']").textContent()); // grab text |
| 26 | + await expect(page.locator("[style*='block']")).toContainText('Incorrect'); //no need to have all text, just one word in this case |
| 27 | + await userNameInput.fill(""); |
| 28 | + await userNameInput.fill("rahulshettyacademy"); |
| 29 | + await signInButton.click(); |
| 30 | + // wait until all page content is loaded |
| 31 | + await page.waitForLoadState('networkidle'); |
| 32 | + //array of 4 products |
| 33 | + console.log(await productCardTitles.nth(0).textContent()); |
| 34 | + console.log(await productCardTitles.nth(3).textContent()); |
| 35 | + console.log(await productCardTitles.first().textContent()); |
| 36 | + console.log(await productCardTitles.last().textContent()); |
| 37 | + const allTitles = await productCardTitles.allTextContents(); //will return an array, can be blank --- so might want an additional check in place |
| 38 | + console.log(allTitles); |
| 39 | + |
| 40 | +}); |
| 41 | + |
| 42 | +test('Browser Check List test', async ({page})=>{ |
| 43 | + await page.goto("https://rahulshettyacademy.com/client"); |
| 44 | + await page.locator("#userEmail").fill("[email protected]"); |
| 45 | + await page.locator("#userPassword").fill("Password1"); |
| 46 | + await page.locator("[value='Login']").click(); |
| 47 | + //await page.waitForLoadState('networkidle'); |
| 48 | + // //if networkidle fails, |
| 49 | + |
| 50 | + const titles = await page.locator(".card-body b").allTextContents(); //if this cails, can add first as well |
| 51 | + console.log(titles); |
| 52 | +}); |
| 53 | + |
| 54 | +//radiobuttons + dropdowns |
| 55 | +test("UI Controls test", async ({page})=> |
| 56 | +{ |
| 57 | + const userNameInput = page.locator('#username'); |
| 58 | + const signInButton = page.locator("#signInBtn"); |
| 59 | + const documentLink = page.locator("[href*='documents-request']"); |
| 60 | + |
| 61 | + await page.goto("https://rahulshettyacademy.com/loginpagePractise/"); |
| 62 | + await userNameInput.fill("rahulshettyacademy"); |
| 63 | + await page.locator("[type='password']").fill("learning"); |
| 64 | + //fixed, static dropdown |
| 65 | + const dropdown = page.locator("select.form-control"); //define dropdown |
| 66 | + await dropdown.selectOption("consult"); //select desired option |
| 67 | + |
| 68 | + await page.locator(".radiotextsty").nth(1).click(); |
| 69 | + await page.locator("#okayBtn").click(); |
| 70 | + //confirm selection |
| 71 | + await expect(page.locator(".radiotextsty").nth(1)).toBeChecked(); |
| 72 | + console.log(page.locator(".radiotextsty").nth(1).isChecked()); //fails if not checked |
| 73 | + |
| 74 | + await page.locator("#terms").click(); |
| 75 | + await expect(page.locator("#terms")).toBeChecked(); |
| 76 | + //uncheck therms and assert it to be empty (no direct toBeChecked() method) |
| 77 | + await page.locator("#terms").uncheck(); |
| 78 | + expect (await page.locator("#terms").isChecked()).toBeFalsy(); //if action is done on this level, shift inside |
| 79 | + // check blinking item on page |
| 80 | + await expect(documentLink).toHaveAttribute("class", "blinkingText"); // if class element is found, then blinking will eventually work |
| 81 | + |
| 82 | + await page.pause(); |
| 83 | + await signInButton.click(); |
| 84 | +}); |
| 85 | + |
| 86 | +test.only('Child windows handling', async ({browser})=> |
| 87 | +{ |
| 88 | + //we define context and start from browser level, not page |
| 89 | + const context = await browser.newContext(); |
| 90 | + const page = await context.newPage(); |
| 91 | + const documentLink = page.locator("[href*='documents-request']"); |
| 92 | + //normal test flow |
| 93 | + await page.goto("https://rahulshettyacademy.com/loginpagePractise/"); |
| 94 | + //define page and start the event listener so it's ready for whwen you click to open the page |
| 95 | + Promise.all( |
| 96 | + [ |
| 97 | + context.waitForEvent('page'), |
| 98 | + documentLink.click(), //page open in another tab, so we check it there |
| 99 | + ]); |
| 100 | + |
| 101 | +}); |
0 commit comments