Table of Contents

Interface IPlaywrightAssertions

Namespace
Microsoft.Playwright
Assembly
Microsoft.Playwright.dll

Playwright gives you Web-First Assertions with convenience methods for creating assertions that will wait and retry until the expected condition is met.

Consider the following example:

using Microsoft.Playwright;
using Microsoft.Playwright.MSTest;

namespace PlaywrightTests;

[TestClass] public class ExampleTests : PageTest { [TestMethod] public async Task StatusBecomesSubmitted() { await Page.GetByRole(AriaRole.Button, new() { Name = "Submit" }).ClickAsync(); await Expect(Page.Locator(".status")).ToHaveTextAsync("Submitted"); } }

Playwright will be re-testing the node with the selector .status until fetched Node has the "Submitted" text. It will be re-fetching the node and checking it over and over, until the condition is met or until the timeout is reached. You can pass this timeout as an option.

By default, the timeout for assertions is set to 5 seconds.

public interface IPlaywrightAssertions

Methods

Expect(IAPIResponse)

Creates a IAPIResponseAssertions object for the given IAPIResponse.

**Usage**

IAPIResponseAssertions Expect(IAPIResponse response)

Parameters

response IAPIResponse

IAPIResponse object to use for assertions.

Returns

IAPIResponseAssertions

Expect(ILocator)

Creates a ILocatorAssertions object for the given ILocator.

**Usage**

await Expect(locator).ToBeVisibleAsync();
ILocatorAssertions Expect(ILocator locator)

Parameters

locator ILocator

ILocator object to use for assertions.

Returns

ILocatorAssertions

Expect(IPage)

Creates a IPageAssertions object for the given IPage.

**Usage**

await Expect(Page).ToHaveTitleAsync("News");
IPageAssertions Expect(IPage page)

Parameters

page IPage

IPage object to use for assertions.

Returns

IPageAssertions