LoginSignup
1
0

Playwright v1.44.0の新機能をまとめてみる

Posted at

はじめに

2024年5月7日にplaywright version 1.44.0がリリースされました。
この記事ではv1.44.0の新機能について紹介します。

assertionsの新機能

toHaveAccessibleName

どんな機能か

locatorが指定されたアクセシブル名を持つ要素かどうかをみる。aria-labelaria-labelledby の名前を見る

サンプルコード

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

test('sample toHaveAccessibleName', async ({ page }) => {
  await page.goto('https://hotel.testplanisphere.dev/ja/');

  const locator = page.getByRole('button')
  await expect(locator).toHaveAccessibleName('ログイン');
});

ドキュメント: https://playwright.dev/docs/api/class-locatorassertions#locator-assertions-to-have-accessible-name
アクセシブル名について: https://developer.mozilla.org/ja/docs/Glossary/Accessible_name

toHaveAccessibleDescription

どんな機能か

locatorが指定されたアクセシブル説明を持つ要素かどうかをみる。aria-describedby属性の説明をみる

サンプルコード

test('sample toHaveAccessibleDescription', async ({ page }) => {
  await page.goto('https://bttb.jp/bootstrap5/index.php?strkey=aria-describedby');

  const locator = page.getByPlaceholder('メールアドレスを入力');
  await expect(locator).toHaveAccessibleDescription('キャリアメールは届かない場合があります。');
});

ドキュメント: https://playwright.dev/docs/api/class-locatorassertions#locator-assertions-to-have-accessible-description
アクセシブル説明について: https://developer.mozilla.org/ja/docs/Glossary/Accessible_description

toHaveRole

どんな機能か

locatorが指定されたARIAロールを持つ要素かどうかをみる。

サンプルコード

test('sample toHaveRole', async ({ page }) => {
  await page.goto('https://hotel.testplanisphere.dev/ja/signup.html');

  const locator = page.locator('button[type=submit]');
  await expect(locator).toHaveRole('button');
});

ドキュメント: https://playwright.dev/docs/api/class-locatorassertions#locator-assertions-to-have-role
ARIAロールについて: https://www.w3.org/TR/wai-aria-1.2/#roles

locator handlerの新機能

  • page.addLocatorHandler()で追加されたハンドラを実行した後、Playwrightはハンドラをトリガーしたオーバーレイが表示されなくなるまで待機するようになった
  • 新しいnoWaitAfterオプションを使用することで、この動作を無効化することができる
  • page.addLocatorHandler()の新しいtimesオプションを使用することで、ハンドラを実行する最大回数を指定できる
  • page.addLocatorHandler()のハンドラは、引数としてロケータを受け取れるようになった
  • 以前に追加したロケーターハンドラーを削除するための新しいpage.removeLocatorHandler()メソッドが追加された

removeLocatorHandlerのドキュメント: https://playwright.dev/docs/api/class-page#page-remove-locator-handler

その他追加機能

  • apiRequestContext.fetch()multipartオプションで同じ名前のフィールドをサポートするようになった
  • expect(callback).toPass({ intervals })は、expect.toPass.intervalsオプションを使用して、グローバルにtestConfig.expect内またはプロジェクトごとにtestProject.expect内で設定できるようになった
  • expect(page).toHaveURL(url)は、ignoreCaseオプションをサポートするようになった
  • testProject.ignoreSnapshotsは、プロジェクトごとにスクリーンショットの期待値をスキップするかどうかを設定できるようになった
  • JUnitレポーターでincludeProjectInTestNameオプションをサポートするようになった
  • suite.entries()(v.1.44.0の新機能)は、子テストスイートとテストケースをその宣言順に返す
    • suite.typeおよびtestCase.typeを使用して、リスト内のテストケースとテストスイートを区別できる
  • Blobレポーターで単一のオプションoutputFileを使用してレポートファイルパスを上書きすることができるようになった

Command lineについて

--last-failedオプションで前回の実行で失敗したテストのみを実行することができるように

// コマンドの例
$ npx playwright test tests/example.spec.ts --headed --project chromium --last-failed
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0