Effortless End-to-End Testing with Microsoft Playwright
We. Make. Tests. π
Unit testsIntegration testsEnd-to-End tests (E2E)
What Really Are End-to-End Tests? π€
We can test…
Example 1: registering for a serviceExample 2: sign in or out of a serviceExample 3: add products to basket and checkout the purchase
Behaviour-Driven Development (BDD) π€
Feature: Calculator
Scenario: β+β should add to current total.
Given the current total is β5β.
When I enter β7β.
Then the current total should be β12β.
…specs produce tests.
describe('Calculator', () => {
it('+ should add to current total', () => {
initialTotal = 5
number = 7
click('.plus')
fill('.input', number)
click('.run')
newTotal = $('.total').innerText
expect(newTotal).toBe(initialTotal + number)
})
})
If it’s so simple, why the lack of tests?
It Doesn’t Have to Hurt! π€
What happens when tests areβ¦
Unstable?Slow to execute?Difficult to write?Painful to maintain?
You likely don’t run or maintain them. π
Different teams produce different tests. βοΈ
How Playwright Solves the Issues?
Speed and Stability Matter
Perform multiple actions concurrently β never sleep again.
// wait for inputs to be filled with Promise.all() or Promise.allSettled()
await Promise.all([
page.fill('[data-test-id=username]', username),
page.fill('[data-test-id=password]', password),
]);
// Executed last
await page.click('[data-test-id=login]');
Support for Modern Languages
Benefit from all the features of TypeScriptSet breakpoints and debug in VS CodeSupport for Python, C#, and Go languages are in preview
Extend How You See Fit
Use any assertion library (eg. assert, chai, or expect)Use any test runner (for now Jest is recommended)Import 3rd party NPM modules
Easy Maintenance
The earlier login example becomes…
const loginPage = new LoginPage(page);
loginPage.fillCredentials(user)
loginPage.login();