From efcddce271688de8462913d930255c82d42edd07 Mon Sep 17 00:00:00 2001 From: Haja Date: Mon, 2 Feb 2026 21:15:02 +0000 Subject: [PATCH 1/2] Worked on intro --- package-lock.json | 91 ++++++++++++++++++++++++++++++++++++++++++ package.json | 21 ++++++++++ playwright.config.ts | 93 +++++++++++++++++++++++++++++++++++++++++++ tests/example.spec.ts | 20 ++++++++++ tests/test-1.spec.ts | 11 +++++ tests/test-2.spec.ts | 8 ++++ tests/test-3.spec.ts | 6 +++ 7 files changed, 250 insertions(+) create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 playwright.config.ts create mode 100644 tests/example.spec.ts create mode 100644 tests/test-1.spec.ts create mode 100644 tests/test-2.spec.ts create mode 100644 tests/test-3.spec.ts diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..39ab36c --- /dev/null +++ b/package-lock.json @@ -0,0 +1,91 @@ +{ + "name": "learning-playwright-5911873", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "learning-playwright-5911873", + "version": "1.0.0", + "license": "ISC", + "devDependencies": { + "@playwright/test": "^1.57.0", + "@types/node": "^25.0.9" + } + }, + "node_modules/@playwright/test": { + "version": "1.57.0", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.57.0.tgz", + "integrity": "sha512-6TyEnHgd6SArQO8UO2OMTxshln3QMWBtPGrOCgs3wVEmQmwyuNtB10IZMfmYDE0riwNR1cu4q+pPcxMVtaG3TA==", + "dev": true, + "dependencies": { + "playwright": "1.57.0" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@types/node": { + "version": "25.0.9", + "resolved": "https://registry.npmjs.org/@types/node/-/node-25.0.9.tgz", + "integrity": "sha512-/rpCXHlCWeqClNBwUhDcusJxXYDjZTyE8v5oTO7WbL8eij2nKhUeU89/6xgjU7N4/Vh3He0BtyhJdQbDyhiXAw==", + "dev": true, + "dependencies": { + "undici-types": "~7.16.0" + } + }, + "node_modules/fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "dev": true, + "hasInstallScript": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/playwright": { + "version": "1.57.0", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.57.0.tgz", + "integrity": "sha512-ilYQj1s8sr2ppEJ2YVadYBN0Mb3mdo9J0wQ+UuDhzYqURwSoW4n1Xs5vs7ORwgDGmyEh33tRMeS8KhdkMoLXQw==", + "dev": true, + "dependencies": { + "playwright-core": "1.57.0" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "fsevents": "2.3.2" + } + }, + "node_modules/playwright-core": { + "version": "1.57.0", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.57.0.tgz", + "integrity": "sha512-agTcKlMw/mjBWOnD6kFZttAAGHgi/Nw0CZ2o6JqWSbMlI219lAFLZZCyqByTsvVAJq5XA5H8cA6PrvBRpBWEuQ==", + "dev": true, + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/undici-types": { + "version": "7.16.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz", + "integrity": "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==", + "dev": true + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..14b2580 --- /dev/null +++ b/package.json @@ -0,0 +1,21 @@ +{ + "name": "learning-playwright-5911873", + "version": "1.0.0", + "description": "This is the repository for the LinkedIn Learning course `learning-playwright`. The full course is available from [LinkedIn Learning][lil-course-url].", + "main": "index.js", + "scripts": { + "test": "npx playwright test", + "test:chromium": "npx playwright test --project=chromium", + "test:first": "npx playwright test --grep @first", + "test:local": "BASE_URL=http://localhost:4200 npx playwright test", + "test:report": "npx playwright test && npx playwright show-report", + "test:ui": "npx playwright test --ui" + }, + "keywords": [], + "author": "", + "license": "ISC", + "devDependencies": { + "@playwright/test": "^1.57.0", + "@types/node": "^25.0.9" + } +} \ No newline at end of file diff --git a/playwright.config.ts b/playwright.config.ts new file mode 100644 index 0000000..e6f2476 --- /dev/null +++ b/playwright.config.ts @@ -0,0 +1,93 @@ +import { defineConfig, devices } from "@playwright/test"; + +/** + * Read environment variables from file. + * https://github.com/motdotla/dotenv + */ +// import dotenv from 'dotenv'; +// import path from 'path'; +// dotenv.config({ path: path.resolve(__dirname, '.env') }); + +/** + * See https://playwright.dev/docs/test-configuration. + */ +export default defineConfig({ + timeout: 30_000, //indicating the maximum time a test can run + globalTimeout: 10 * 60 * 1000, //indicating the 10 minutes maximum time the entire test suite can run + testDir: "./tests", + /* Run tests in files in parallel */ + fullyParallel: true, + /* Fail the build on CI if you accidentally left test.only in the source code. */ + forbidOnly: !!process.env.CI, + /* Retry on CI 2 times and locally 1 time */ + retries: process.env.CI ? 2 : 0, + /* Opt out of parallel tests on CI. */ + workers: process.env.CI ? 1 : undefined, + /* Reporter to use. See https://playwright.dev/docs/test-reporters */ + reporter: "html", + /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ + use: { + /* Base URL to use in actions like `await page.goto('')`. */ + baseURL: "https://practicesoftwaretesting.com/", + + /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ + trace: "on", + actionTimeout: 0, + ignoreHTTPSErrors: true, + video: "retain-on-failure", + screenshot: "only-on-failure", + headless: true, + }, + + /* Configure projects for major browsers */ + projects: [ + { + name: "setup", + testMatch: /.*\.setup\.ts/, + }, + { + name: "chromium", + dependencies: ["setup"], + use: { ...devices["Desktop Chrome"], permissions: ["clipboard-read"] }, + }, + + // { + // name: "firefox", + // dependencies: ["setup"], + // use: { ...devices["Desktop Firefox"] }, + // }, + + // { + // name: "webkit", + // dependencies: ["setup"], + // 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://localhost:3000', + // reuseExistingServer: !process.env.CI, + // }, +}); diff --git a/tests/example.spec.ts b/tests/example.spec.ts new file mode 100644 index 0000000..4f9c34a --- /dev/null +++ b/tests/example.spec.ts @@ -0,0 +1,20 @@ +import { test, expect } from "@playwright/test"; + +test("has title", async ({ page }) => { + await page.goto("https://playwright.dev/"); + + // Expect a title "to contain" a substring. + await expect(page).toHaveTitle(/Playwright/); +}); + +test("get started link", { tag: "@first" }, async ({ page }) => { + await page.goto("https://playwright.dev/"); + + // Click the get started link. + await page.getByRole("link", { name: "Get started" }).click(); + + // Expects page to have a heading with the name of Installation. + await expect( + page.getByRole("heading", { name: "Installation" }), + ).toBeVisible(); +}); diff --git a/tests/test-1.spec.ts b/tests/test-1.spec.ts new file mode 100644 index 0000000..09e639f --- /dev/null +++ b/tests/test-1.spec.ts @@ -0,0 +1,11 @@ +import { test, expect } from "@playwright/test"; + +test("test", async ({ page }) => { + await page.goto("https://playwright.dev/"); + await page.getByRole("link", { name: "Community" }).click(); + await page + .getByLabel("Docs sidebar") + .getByRole("link", { name: "Ambassadors" }) + .click(); + await expect(page.locator("section")).toContainText("Butch Mayhew"); +}); diff --git a/tests/test-2.spec.ts b/tests/test-2.spec.ts new file mode 100644 index 0000000..c61b09b --- /dev/null +++ b/tests/test-2.spec.ts @@ -0,0 +1,8 @@ +import { test, expect } from '@playwright/test'; + +test('test', async ({ page }) => { + await page.goto('https://playwright.dev/'); + await page.getByRole('link', { name: 'Community' }).click(); + await page.getByLabel('Docs sidebar').getByRole('link', { name: 'Ambassadors' }).click(); + await expect(page.locator('section')).toContainText('Butch Mayhew'); +}); \ No newline at end of file diff --git a/tests/test-3.spec.ts b/tests/test-3.spec.ts new file mode 100644 index 0000000..67a2cf3 --- /dev/null +++ b/tests/test-3.spec.ts @@ -0,0 +1,6 @@ +import { test, expect } from '@playwright/test'; + +test('test', async ({ page }) => { + await page.goto('chrome-error://chromewebdata/'); + await page.getByRole('button', { name: 'Reload' }).click(); +}); \ No newline at end of file From 58b54369e43edef991416cb6f1911899d744a19a Mon Sep 17 00:00:00 2001 From: Haja Date: Mon, 2 Feb 2026 21:16:52 +0000 Subject: [PATCH 2/2] Git ignore --- .gitignore | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.gitignore b/.gitignore index 4b64bc3..614d303 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,10 @@ node_modules .tmp npm-debug.log + +# Playwright +/test-results/ +/playwright-report/ +/blob-report/ +/playwright/.cache/ +/playwright/.auth/