メインコンテンツへスキップ

アサーション

アサーション一覧

アサーション説明
Expect(Locator).ToBeAttachedAsync()要素がアタッチされている
Expect(Locator).ToBeCheckedAsync()チェックボックスがチェックされている
Expect(Locator).ToBeDisabledAsync()要素が無効になっている
Expect(Locator).ToBeEditableAsync()要素が編集可能である
Expect(Locator).ToBeEmptyAsync()コンテナが空である
Expect(Locator).ToBeEnabledAsync()要素が有効になっている
Expect(Locator).ToBeFocusedAsync()要素がフォーカスされている
Expect(Locator).ToBeHiddenAsync()要素が表示されていない
Expect(Locator).ToBeInViewportAsync()要素がビューポートと交差している
Expect(Locator).ToBeVisibleAsync()要素が表示されている
Expect(Locator).ToContainTextAsync()要素がテキストを含んでいる
Expect(Locator).ToHaveAccessibleDescriptionAsync()要素が一致するアクセシブルな説明を持っている
Expect(Locator).ToHaveAccessibleNameAsync()要素が一致するアクセシブルな名前を持っている
Expect(Locator).ToHaveAttributeAsync()要素が DOM 属性を持っている
Expect(Locator).ToHaveClassAsync()要素がクラスプロパティを持っている
Expect(Locator).ToHaveCountAsync()リストに正確な数の子要素がある
Expect(Locator).ToHaveCSSAsync()要素が CSS プロパティを持っている
Expect(Locator).ToHaveIdAsync()要素が ID を持っている
Expect(Locator).ToHaveJSPropertyAsync()要素が JavaScript プロパティを持っている
Expect(Locator).ToHaveRoleAsync()要素が特定のARIA ロールを持っている
Expect(Locator).ToHaveTextAsync()要素がテキストと一致する
Expect(Locator).ToHaveValueAsync()入力に値がある
Expect(Locator).ToHaveValuesAsync()セレクトにオプションが選択されている
Expect(Page).ToHaveTitleAsync()ページにタイトルがある
Expect(Page).ToHaveURLAsync()ページに URL がある
Expect(Response).ToBeOKAsync()レスポンスが OK ステータスである

カスタムタイムアウトの設定

アサーションのカスタムタイムアウトは、グローバルまたはアサーションごとに指定できます。デフォルトのタイムアウトは5秒です。

グローバルタイムアウト

UnitTest1.cs
using Microsoft.Playwright;
using Microsoft.Playwright.MSTest;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace PlaywrightTests;

[TestClass]
public class UnitTest1 : PageTest
{
[ClassInitialize]
public static void GlobalSetup(TestContext context)
{
SetDefaultExpectTimeout(10_000);
}
// ...
}

アサーションごとのタイムアウト

UnitTest1.cs
await Expect(Page.GetByText("Name")).ToBeVisibleAsync(new() { Timeout = 10_000 });