Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@
node_modules
.tmp
npm-debug.log

# Playwright
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
/playwright/.auth/
91 changes: 91 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
93 changes: 93 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -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,
// },
});
20 changes: 20 additions & 0 deletions tests/example.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});
11 changes: 11 additions & 0 deletions tests/test-1.spec.ts
Original file line number Diff line number Diff line change
@@ -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");
});
8 changes: 8 additions & 0 deletions tests/test-2.spec.ts
Original file line number Diff line number Diff line change
@@ -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');
});
6 changes: 6 additions & 0 deletions tests/test-3.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});