Testing is the systematic process of verifying and validating that a software application or system meets specified requirements and functions correctly.
Types of Testing
Unit Testing
Integration Testing
System Testing
Acceptance Testing
End-to-End (E2E) Testing
Accessibility Testing
Visual Testing
Component Testing
UI Testing Best Practices
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 Challenges
Testing is hard
Testing takes time to learn
Testing time to build
Testing culture
Tests are slow
Tests are brittle
Tests are flaky
Lets try to make testing easier... with
What is Playwright?
Open Source released by Microsoft in 2020
A Modern web test framework
Works with Headless or Headed Browsers
Chromium - Chrome/Edge
Firefox
WebKit
Language Support
Bindings for:
Python
Javascript/Typescript
Java
.NET
Playwright Architecture
Language Bindings
Single Automation Protocol
Abstracts debugging protocols
Benefits of Using Playwright
Reliable & Stable
Automatically waits for UI to be ready.
Handles dynamic content, animations, and AJAX requests gracefully.
Minimizes flaky tests.
Isolation with Browser Contexts
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.
// Get frame using the frame's name attributeconst frame = page.frame('frame-login');
// Get frame using frame's URLconst frame = page.frame({ url: /.*domain.*/ });
// Interact with the frameawait frame.fill('#username-input', 'John');
Fast Execution
Tests are executed swiftly, reducing waiting time.
Parallel test execution.
Optimal performance due to its architecture.
Isolation with Browser Contexts
Auto-Waiting
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
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.
Web-First Assertions
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()
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()
Visual evidence
Screenshot support
Video Recording
Rich Tooling Ecosystem
VS Code Extension
Integrations with popular CI/CD services.
Compatible with multiple assertion libraries.
Playwright Extension
Integration with IDE Testing
Codegen
Playwright Test Generator is a GUI tool that helps you record Playwright tests
UI Mode
Run tests and visually see how it runs
Playwright Best Practices
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
Playwright Best Practices
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
DEMOS
Microsoft Playwright Testing
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.