| marp | true |
|---|---|
| theme | custom-default |
| footer | https://chris-ayers.com |
BlueSky: @chris-ayers.com
LinkedIn: - chris-l-ayers
Blog: https://chris-ayers.com/
GitHub: Codebytes
Mastodon: @Chrisayers@hachyderm.io
Twitter: @Chris_L_Ayers
- What is Testing?
- What is Playwright?
- Benefits of Using Playwright
- Creating End-to-End Tests with Playwright
- Integrating with Continuous Integration
Testing is the systematic process of verifying and validating that a software application or system meets specified requirements and functions correctly.
- Unit Testing
- Integration Testing
- System Testing
- Acceptance Testing
- End-to-End (E2E) Testing
- Accessibility Testing
- Visual Testing
- Component Testing
- Test user-visible behavior
- Make tests as isolated as possible
- Avoid testing third-party dependencies
- If you test with a database, control the data
- Testing is hard
- Testing takes time to learn
- Testing time to build
- Testing culture
- Tests are slow
- Tests are brittle
- Tests are flaky
- A Modern web test framework
- Works with Headless or Headed Browsers
- Chromium - Chrome/Edge
- Firefox
- WebKit
- Bindings for:
- Python
- Javascript/Typescript
- Java
- .NET
- Language Bindings
- Single Automation Protocol
- Abstracts debugging protocols
- Automatically waits for UI to be ready.
- Handles dynamic content, animations, and AJAX requests gracefully.
- Minimizes flaky tests.
- Isolation with Browser Contexts
Browser Contexts provide a way to operate multiple independent browser sessions.
If a page opens another page, e.g. with a window.open call, the popup will belong to the parent page's browser context.
- Easily emulate various mobile devices.
- Mobile Chrome
- Mobile Safari
- Emulate Viewports and Scale
- Test responsiveness and mobile-specific features.
- Ability to emulate location via geolocation

- Network request interception.
- Create custom scenarios (e.g., offline mode, slow network).
- API Mocking
- HAR file support
- Automate beyond the browser:
- Upload & download files
- Work with iframes and shadow DOM
// Get frame using the frame's name attribute
const frame = page.frame('frame-login');
// Get frame using frame's URL
const frame = page.frame({ url: /.*domain.*/ });
// Interact with the frame
await frame.fill('#username-input', 'John');- Tests are executed swiftly, reducing waiting time.
- Parallel test execution.
- Optimal performance due to its architecture.
- Isolation with Browser Contexts
For example, for page.click(), Playwright will ensure that:
- element is Attached to the DOM
- element is Visible
- element is Stable, as in not animating or completed animation
- element Receives Events, as in not obscured by other elements
- element is Enabled
See a full list of actions at: https://playwright.dev/docs/actionability
| Method | Description |
|---|---|
page.getByRole() |
Locate by explicit and implicit accessibility attributes. |
page.getByText() |
Locate by text content. |
page.getByLabel() |
Locate a form control by associated label's text. |
page.getByPlaceholder() |
Locate an input by placeholder. |
page.getByAltText() |
Locate an element, usually image, by its text alternative. |
page.getByTitle() |
Locate an element by its title attribute. |
page.getByTestId() |
Locate an element based on its data-testid attribute. |
<style scoped> /* Reset table styling provided by theme */ table, tr, td, th { /* all: unset; */ /* Override contextual styling */ /* border: 0 !important; */ /* background: transparent !important; */ font-size: 24px; } table { display: table; } tr { display: table-row; } td { display: table-cell; } th { display: none; } /* ...and layout freely :) */ table { width: 100%; } td { text-align: center; vertical-align: middle; } </style>
| expect(locator) | expect(locator/page/response) |
| expect(locator).toBeAttached() | expect(locator).toHaveClass() |
| expect(locator).toBeChecked() | expect(locator).toHaveCount() |
| expect(locator).toBeDisabled() | expect(locator).toHaveCSS() |
| expect(locator).toBeEditable() | expect(locator).toHaveId() |
| expect(locator).toBeEmpty() | expect(locator).toHaveJSProperty() |
| expect(locator).toBeEnabled() | expect(locator).toHaveScreenshot() |
<style scoped> table { display: table; width: 100%; font-size: 24px; } th { display: none; } td { text-align: center; vertical-align: middle; } </style>
| expect(locator) | expect(locator/page/response) |
| expect(locator).toBeFocused() | expect(locator).toHaveText() |
| expect(locator).toBeHidden() | expect(locator).toHaveValue() |
| expect(locator).toBeInViewport() | expect(locator).toHaveValues() |
| expect(locator).toBeVisible() | expect(page).toHaveTitle() |
| expect(locator).toContainText() | expect(page).toHaveURL() |
| expect(locator).toHaveAttribute() | expect(response).toBeOK() |
<style scoped> .video-poster { display: none; } @media print { video { display: none; } .video-poster { display: block; width: 100%; } } </style>
- VS Code Extension
- Integrations with popular CI/CD services.
- Compatible with multiple assertion libraries.
Playwright Test Generator is a GUI tool that helps you record Playwright tests
Run tests and visually see how it runs
- Use locators
- Use chaining and filtering
- Prefer user-facing attributes to XPath or CSS selectors
- Generate locators
- Use codegen to generate locators
- Use the VS Code extension to generate locators
- Use web first assertions
- Don't use manual assertions
- Configure debugging
- Local debugging
- Debugging on CI
- Use Playwright's Tooling
- Test across all browsers
- Keep your Playwright dependency up to date
- Run tests on CI
- Lint your tests
- Use parallelism and sharding
Join the waitlist for Microsoft Playwright Testing private preview • New Azure service for running Playwright tests. • Cloud enabled to run Playwright tests at scale. • High parallelization across operating system-browser combinations. • Speed up delivery of features without sacrificing quality.
To learn more about Microsoft Playwright Testing, refer to: https://aka.ms/mpt/private-preview-blog.
BlueSky: @chris-ayers.com
LinkedIn: - chris-l-ayers
Blog: https://chris-ayers.com/
GitHub: Codebytes
Mastodon: @Chrisayers@hachyderm.io
Twitter: @Chris_L_Ayers










