v1.29.0

microsoft/playwrightv1.29.0Dec 16, 2022by aslushnikov

AI Summary

Introduces powerful new APIs for request interception, locator iteration, and automatic full-page screenshots on test failure.

Key Highlights

  • New `route.fetch()` method to fetch original requests and modify them.
  • New `locator.all()` method to iterate over all matching elements.
  • New `toPass()` assertion to retry blocks of code until they pass.
  • Automatic full-page screenshot capture on test failure.

Breaking Changes

  • Ubuntu 18.04 is no longer supported.

New Features

  • Route fetch with JSON modification support
  • Locator all() iteration
  • Retry assertion (toPass)
  • Automatic full-page screenshots on failure
  • jsconfig.json support

Full Release Notes

## New APIs

- New method [`route.fetch()`](https://playwright.dev/docs/api/class-route#route-fetch) and new option `json` for [`route.fulfill()`](https://playwright.dev/docs/api/class-route#route-fulfill):

    ```js
    await page.route('**/api/settings', async route => {
      // Fetch original settings.
      const response = await route.fetch();

      // Force settings theme to a predefined value.
      const json = await response.json();
      json.theme = 'Solorized';

      // Fulfill with modified data.
      await route.fulfill({ json });
    });
    ```

- New method [`locator.all()`](https://playwright.dev/docs/api/class-locator#locator-all) to iterate over all matching elements:

    ```js
    // Check all checkboxes!
    const checkboxes = page.getByRole('checkbox');
    for (const checkbox of await checkboxes.all())
      await checkbox.check();
    ```

- [`Locator.selectOption`](https://playwright.dev/docs/api/class-locator#locator-select-option) matches now by value or label:

  ```html
  <select multiple>
    <option value="red">Red</div>
    <option value="green">Green</div>
    <option value="blue">Blue</div>
  </select>
  ```

  ```js
  await element.selectOption('Red');
  ```

- Retry blocks of code until all assertions pass:

    ```js
    await expect(async () => {
      const response = await page.request.get('https://api.example.com');
      await expect(response).toBeOK();
    }).toPass();
    ```

  Read more in [our documentation](https://playwright.dev/docs/test-assertions#retrying).

- Automatically capture **full page screenshot** on test failure:
    ```js
    // playwright.config.ts
    import type { PlaywrightTestConfig } from '@playwright/test';

    const config: PlaywrightTestConfig = {
      use: {
        screenshot: {
          mode: 'only-on-failure',
          fullPage: true,
        }
      }
    };

    export default config;
    ```

## Miscellaneous

- Playwright Test now respects [`jsconfig.json`](https://code.visualstudio.com/docs/languages/jsconfig).
- New options `args` and `proxy` for [`androidDevice.launchBrowser()`](https://playwright.dev/docs/api/class-androiddevice#android-device-launch-browser).
- Option `postData` in method [`route.continue()`](https://playwright.dev/docs/api/class-route#route-continue) now supports [serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#description) values.
- Ubuntu 18.04 is not supported anymore

## Browser Versions

* Chromium 109.0.5414.46
* Mozilla Firefox 107.0
* WebKit 16.4

This version was also tested against the following stable channels:

* Google Chrome 108
* Microsoft Edge 108