Skip to content

Commit a3a8ac3

Browse files
committed
Initial commit
0 parents  commit a3a8ac3

File tree

8 files changed

+327
-0
lines changed

8 files changed

+327
-0
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.github/workflows/playwright.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Playwright Tests
2+
on:
3+
push:
4+
branches: [ main, master ]
5+
pull_request:
6+
branches: [ main, master ]
7+
jobs:
8+
test:
9+
timeout-minutes: 60
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-node@v4
14+
with:
15+
node-version: lts/*
16+
- name: Install dependencies
17+
run: npm ci
18+
- name: Install Playwright Browsers
19+
run: npx playwright install --with-deps
20+
- name: Run Playwright tests
21+
run: npx playwright test
22+
- uses: actions/upload-artifact@v4
23+
if: always()
24+
with:
25+
name: playwright-report
26+
path: playwright-report/
27+
retention-days: 30

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules/
2+
/test-results/
3+
/playwright-report/
4+
/blob-report/
5+
/playwright/.cache/

package-lock.json

Lines changed: 91 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "1stcourse",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {},
7+
"keywords": [],
8+
"author": "",
9+
"license": "ISC",
10+
"devDependencies": {
11+
"@playwright/test": "^1.42.1",
12+
"@types/node": "^20.11.30"
13+
}
14+
}

playwright.config.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// @ts-check
2+
const { defineConfig, devices } = require('@playwright/test');
3+
4+
/**
5+
* Read environment variables from file.
6+
* https://github.com/motdotla/dotenv
7+
*/
8+
// require('dotenv').config();
9+
10+
/**
11+
* @see https://playwright.dev/docs/test-configuration
12+
*/
13+
module.exports = defineConfig({
14+
testDir: './tests',
15+
timeout: 30 * 1000,
16+
expect: {timeout: 5000},
17+
reporter: 'html',
18+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
19+
use: {
20+
headless: false,
21+
/* Base URL to use in actions like `await page.goto('/')`. */
22+
// baseURL: 'http://127.0.0.1:3000',
23+
24+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
25+
trace: 'on-first-retry',
26+
},
27+
28+
/* Configure projects for major browsers */
29+
projects: [
30+
{
31+
name: 'chromium',
32+
use: { ...devices['Desktop Chrome'] },
33+
34+
},
35+
36+
// {
37+
// name: 'firefox',
38+
// use: { ...devices['Desktop Firefox'] },
39+
// },
40+
41+
// {
42+
// name: 'webkit',
43+
// use: { ...devices['Desktop Safari'] },
44+
// },
45+
46+
/* Test against mobile viewports. */
47+
// {
48+
// name: 'Mobile Chrome',
49+
// use: { ...devices['Pixel 5'] },
50+
// },
51+
// {
52+
// name: 'Mobile Safari',
53+
// use: { ...devices['iPhone 12'] },
54+
// },
55+
56+
/* Test against branded browsers. */
57+
// {
58+
// name: 'Microsoft Edge',
59+
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
60+
// },
61+
// {
62+
// name: 'Google Chrome',
63+
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
64+
// },
65+
],
66+
67+
/* Run your local dev server before starting the tests */
68+
// webServer: {
69+
// command: 'npm run start',
70+
// url: 'http://127.0.0.1:3000',
71+
// reuseExistingServer: !process.env.CI,
72+
// },
73+
});
74+

tests/RS_ClientApp.spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const {test, expect} = require('@playwright/test');
2+
3+
test('Browser check', async ({page})=>
4+
{
5+
await page.goto("https://rahulshettyacademy.com/client");
6+
await page.locator("#userEmail").fill("[email protected]");
7+
await page.locator("#userPassword").fill("Password1");
8+
await page.locator("[value='Login']").click();
9+
10+
11+
const titles = await page.locator(".card-body b").allTextContents();
12+
console.log(titles);
13+
})

tests/UIBasicsTest.spec.js

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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

Comments
 (0)