Skip to content

Instantly share code, notes, and snippets.

@codegino
Last active February 9, 2023 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codegino/42bca1eb2a22e5c19bb61df5fcb1ec22 to your computer and use it in GitHub Desktop.
Save codegino/42bca1eb2a22e5c19bb61df5fcb1ec22 to your computer and use it in GitHub Desktop.
Playwright - Writing a test
import { test, expect, chromium } from "@playwright/test";
test("get started link long version", async () => {
// Open a browser
const browser = await chromium.launch();
// Open a new page
const context = await browser.newContext();
const page = await context.newPage();
// Navigation
await page.goto("https://playwright.dev/");
// Wait for an element to load
await expect(page.getByText("Get started")).toBeVisible();
// Locating an element
const link = page.getByText("Get started");
// Interaction
await link.click();
// Assertion
await expect(page).toHaveURL(/.*intro/);
});
import { test, expect } from "@playwright/test";
test("get started link long version", async ({ page }) => {
// Navigation
await page.goto("https://playwright.dev/");
// Wait for an element to load
await expect(page.getByText("Get started")).toBeVisible();
// Locating an element
const link = page.getByText("Get started");
// Interaction
await link.click();
// Assertion
await expect(page).toHaveURL(/.*intro/);
});
import { test, expect } from "@playwright/test";
test("get started link long version", async ({ page }) => {
// Navigation
await page.goto("https://playwright.dev/");
// Locating an element + Interaction
await page.getByText("Get started").click();
// Assertion
await expect(page).toHaveURL(/.*intro/);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment