-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a3a8ac3
Showing
8 changed files
with
327 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Playwright Tests | ||
on: | ||
push: | ||
branches: [ main, master ] | ||
pull_request: | ||
branches: [ main, master ] | ||
jobs: | ||
test: | ||
timeout-minutes: 60 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: lts/* | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Install Playwright Browsers | ||
run: npx playwright install --with-deps | ||
- name: Run Playwright tests | ||
run: npx playwright test | ||
- uses: actions/upload-artifact@v4 | ||
if: always() | ||
with: | ||
name: playwright-report | ||
path: playwright-report/ | ||
retention-days: 30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules/ | ||
/test-results/ | ||
/playwright-report/ | ||
/blob-report/ | ||
/playwright/.cache/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "1stcourse", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": {}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@playwright/test": "^1.42.1", | ||
"@types/node": "^20.11.30" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// @ts-check | ||
const { defineConfig, devices } = require('@playwright/test'); | ||
|
||
/** | ||
* Read environment variables from file. | ||
* https://github.com/motdotla/dotenv | ||
*/ | ||
// require('dotenv').config(); | ||
|
||
/** | ||
* @see https://playwright.dev/docs/test-configuration | ||
*/ | ||
module.exports = defineConfig({ | ||
testDir: './tests', | ||
timeout: 30 * 1000, | ||
expect: {timeout: 5000}, | ||
reporter: 'html', | ||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ | ||
use: { | ||
headless: false, | ||
/* Base URL to use in actions like `await page.goto('/')`. */ | ||
// baseURL: 'http://127.0.0.1:3000', | ||
|
||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ | ||
trace: 'on-first-retry', | ||
}, | ||
|
||
/* Configure projects for major browsers */ | ||
projects: [ | ||
{ | ||
name: 'chromium', | ||
use: { ...devices['Desktop Chrome'] }, | ||
|
||
}, | ||
|
||
// { | ||
// name: 'firefox', | ||
// use: { ...devices['Desktop Firefox'] }, | ||
// }, | ||
|
||
// { | ||
// name: 'webkit', | ||
// use: { ...devices['Desktop Safari'] }, | ||
// }, | ||
|
||
/* Test against mobile viewports. */ | ||
// { | ||
// name: 'Mobile Chrome', | ||
// use: { ...devices['Pixel 5'] }, | ||
// }, | ||
// { | ||
// name: 'Mobile Safari', | ||
// use: { ...devices['iPhone 12'] }, | ||
// }, | ||
|
||
/* Test against branded browsers. */ | ||
// { | ||
// name: 'Microsoft Edge', | ||
// use: { ...devices['Desktop Edge'], channel: 'msedge' }, | ||
// }, | ||
// { | ||
// name: 'Google Chrome', | ||
// use: { ...devices['Desktop Chrome'], channel: 'chrome' }, | ||
// }, | ||
], | ||
|
||
/* Run your local dev server before starting the tests */ | ||
// webServer: { | ||
// command: 'npm run start', | ||
// url: 'http://127.0.0.1:3000', | ||
// reuseExistingServer: !process.env.CI, | ||
// }, | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const {test, expect} = require('@playwright/test'); | ||
|
||
test('Browser check', async ({page})=> | ||
{ | ||
await page.goto("https://rahulshettyacademy.com/client"); | ||
await page.locator("#userEmail").fill("[email protected]"); | ||
await page.locator("#userPassword").fill("Password1"); | ||
await page.locator("[value='Login']").click(); | ||
|
||
|
||
const titles = await page.locator(".card-body b").allTextContents(); | ||
console.log(titles); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
const {test, expect} = require('@playwright/test'); | ||
const { title } = require('process'); | ||
|
||
test('First test ever', async ({browser})=> | ||
{ | ||
const context = await browser.newContext(); | ||
const page = await context.newPage(); | ||
|
||
await page.goto("https://rahulshettyacademy.com/loginpagePractise/"); | ||
}); | ||
|
||
|
||
test('Browser Input Error Message test', async ({page})=> | ||
{ | ||
const userNameInput = page.locator('#username'); | ||
const signInButton = page.locator("#signInBtn"); | ||
//products page | ||
const productCardTitles = page.locator(".card-body a"); | ||
|
||
await page.goto("https://rahulshettyacademy.com/loginpagePractise/"); | ||
await userNameInput.fill("rahulshe"); | ||
await page.locator("[type='password']").fill("learning"); | ||
await signInButton.click(); | ||
//no explicit wait needed like selenium (takes one from config 30s) | ||
console.log(await page.locator("[style*='block']").textContent()); // grab text | ||
await expect(page.locator("[style*='block']")).toContainText('Incorrect'); //no need to have all text, just one word in this case | ||
await userNameInput.fill(""); | ||
await userNameInput.fill("rahulshettyacademy"); | ||
await signInButton.click(); | ||
// wait until all page content is loaded | ||
await page.waitForLoadState('networkidle'); | ||
//array of 4 products | ||
console.log(await productCardTitles.nth(0).textContent()); | ||
console.log(await productCardTitles.nth(3).textContent()); | ||
console.log(await productCardTitles.first().textContent()); | ||
console.log(await productCardTitles.last().textContent()); | ||
const allTitles = await productCardTitles.allTextContents(); //will return an array, can be blank --- so might want an additional check in place | ||
console.log(allTitles); | ||
|
||
}); | ||
|
||
test('Browser Check List test', async ({page})=>{ | ||
await page.goto("https://rahulshettyacademy.com/client"); | ||
await page.locator("#userEmail").fill("[email protected]"); | ||
await page.locator("#userPassword").fill("Password1"); | ||
await page.locator("[value='Login']").click(); | ||
//await page.waitForLoadState('networkidle'); | ||
// //if networkidle fails, | ||
|
||
const titles = await page.locator(".card-body b").allTextContents(); //if this cails, can add first as well | ||
console.log(titles); | ||
}); | ||
|
||
//radiobuttons + dropdowns | ||
test("UI Controls test", async ({page})=> | ||
{ | ||
const userNameInput = page.locator('#username'); | ||
const signInButton = page.locator("#signInBtn"); | ||
const documentLink = page.locator("[href*='documents-request']"); | ||
|
||
await page.goto("https://rahulshettyacademy.com/loginpagePractise/"); | ||
await userNameInput.fill("rahulshettyacademy"); | ||
await page.locator("[type='password']").fill("learning"); | ||
//fixed, static dropdown | ||
const dropdown = page.locator("select.form-control"); //define dropdown | ||
await dropdown.selectOption("consult"); //select desired option | ||
|
||
await page.locator(".radiotextsty").nth(1).click(); | ||
await page.locator("#okayBtn").click(); | ||
//confirm selection | ||
await expect(page.locator(".radiotextsty").nth(1)).toBeChecked(); | ||
console.log(page.locator(".radiotextsty").nth(1).isChecked()); //fails if not checked | ||
|
||
await page.locator("#terms").click(); | ||
await expect(page.locator("#terms")).toBeChecked(); | ||
//uncheck therms and assert it to be empty (no direct toBeChecked() method) | ||
await page.locator("#terms").uncheck(); | ||
expect (await page.locator("#terms").isChecked()).toBeFalsy(); //if action is done on this level, shift inside | ||
// check blinking item on page | ||
await expect(documentLink).toHaveAttribute("class", "blinkingText"); // if class element is found, then blinking will eventually work | ||
|
||
await page.pause(); | ||
await signInButton.click(); | ||
}); | ||
|
||
test.only('Child windows handling', async ({browser})=> | ||
{ | ||
//we define context and start from browser level, not page | ||
const context = await browser.newContext(); | ||
const page = await context.newPage(); | ||
const documentLink = page.locator("[href*='documents-request']"); | ||
//normal test flow | ||
await page.goto("https://rahulshettyacademy.com/loginpagePractise/"); | ||
//define page and start the event listener so it's ready for whwen you click to open the page | ||
Promise.all( | ||
[ | ||
context.waitForEvent('page'), | ||
documentLink.click(), //page open in another tab, so we check it there | ||
]); | ||
|
||
}); |