Replacements for protractor
Motivation: protractor is deprecated and reached end-of-life in 2023. Its npm deprecation notice points to the Angular blog for other end-to-end testing options.
@playwright/test
@playwright/test runs tests in Chromium, Firefox and WebKit, and waits for elements automatically, so you don't need browser.waitForAngular() or explicit waits. Playwright has a migration guide from Protractor.
Protractor's baseUrl becomes use.baseURL in playwright.config.ts.
ts
import { browser, by, element } from 'protractor'
import { expect, test } from '@playwright/test'
it('shows a welcome message', async () => {
test('shows a welcome message', async ({ page }) => {
await browser.get('/login')
await page.goto('/login')
await element(by.css('#name')).sendKeys('Jane')
await page.locator('#name').fill('Jane')
await element(by.buttonText('Sign in')).click()
await page.getByRole('button', { name: 'Sign in' }).click()
expect(await element(by.css('.welcome')).getText()).toEqual('Welcome, Jane')
await expect(page.locator('.welcome')).toHaveText('Welcome, Jane')
})webdriverio
webdriverio uses WebDriver like Protractor does, so it is the closer fit if you depend on WebDriver or a Selenium grid. WebdriverIO has a migration guide from Protractor, and @wdio/codemod rewrites most Protractor calls for you:
sh
npm init wdio@latest .
npx jscodeshift -t ./node_modules/@wdio/codemod/protractor ./e2e/For TypeScript tests, add --parser=tsx.