v1.40.0

microsoft/playwrightv1.40.0Nov 16, 2023by dgozman

AI Summary

Enhanced the Test Generator with assertion tools. Added options for close reasons, Firefox user preferences, and updated the Docker image to Node.js v20.

Key Highlights

  • New Test Generator tools: Assert visibility, value, and text
  • New 'reason' option for close operations
  • Node.js v20 included in Playwright Docker image

New Features

  • Test Generator assertion tools
  • page.close() reason option
  • firefoxUserPrefs option
  • Node.js v20 in Docker

Full Release Notes

## Test Generator Update

![Playwright Test Generator](https://github.com/microsoft/playwright/assets/9881434/e8d67e2e-f36d-4301-8631-023948d3e190)

New tools to generate assertions:
- "Assert visibility" tool generates [expect(locator).toBeVisible()](https://playwright.dev/docs/api/class-locatorassertions#locator-assertions-to-be-visible).
- "Assert value" tool generates [expect(locator).toHaveValue(value)](https://playwright.dev/docs/api/class-locatorassertions#locator-assertions-to-have-value).
- "Assert text" tool generates [expect(locator).toContainText(text)](https://playwright.dev/docs/api/class-locatorassertions#locator-assertions-to-contain-text).

Here is an example of a generated test with assertions:

```js
import { test, expect } from '@playwright/test';

test('test', async ({ page }) => {
  await page.goto('https://playwright.dev/');
  await page.getByRole('link', { name: 'Get started' }).click();
  await expect(page.getByLabel('Breadcrumbs').getByRole('list')).toContainText('Installation');
  await expect(page.getByLabel('Search')).toBeVisible();
  await page.getByLabel('Search').click();
  await page.getByPlaceholder('Search docs').fill('locator');
  await expect(page.getByPlaceholder('Search docs')).toHaveValue('locator');
});
```

## New APIs
- Option `reason` in [page.close()](https://playwright.dev/docs/api/class-page#page-close), [browserContext.close()](https://playwright.dev/docs/api/class-browsercontext#browser-context-close) and [browser.close()](https://playwright.dev/docs/api/class-browser#browser-close). Close reason is reported for all operations interrupted by the closure.
- Option `firefoxUserPrefs` in [browserType.launchPersistentContext(userDataDir)](https://playwright.dev/docs/api/class-browsertype#browser-type-launch-persistent-context).

## Other Changes
- Methods [download.path()](https://playwright.dev/docs/api/class-download#download-path) and [download.createReadStream()](https://playwright.dev/docs/api/class-download#download-create-read-stream) throw an error for failed and cancelled downloads.
- Playwright [docker image](https://playwright.dev/docs/docker) now comes with Node.js v20.

## Browser Versions
* Chromium 120.0.6099.28
* Mozilla Firefox 119.0
* WebKit 17.4

This version was also tested against the following stable channels:
* Google Chrome 119
* Microsoft Edge 119