Table of Contents

Interface IPageAssertions

Namespace
Microsoft.Playwright
Assembly
Microsoft.Playwright.dll

The IPageAssertions class provides assertion methods that can be used to make assertions about the IPage state in the tests.

using System.Text.RegularExpressions;
using Microsoft.Playwright;
using Microsoft.Playwright.MSTest;

namespace PlaywrightTests;

[TestClass] public class ExampleTests : PageTest { [TestMethod] public async Task NavigatetoLoginPage() { await Page.GetByRole(AriaRole.Button, new() { Name = "Sign In" }).ClickAsync(); await Expect(Page).ToHaveURLAsync(new Regex(".*/login")); } }

public interface IPageAssertions

Properties

Not

Makes the assertion check for the opposite condition. For example, this code tests that the page URL doesn't contain "error":

await Expect(Page).Not.ToHaveURL("error");
IPageAssertions Not { get; }

Property Value

IPageAssertions

Methods

ToHaveTitleAsync(string, PageAssertionsToHaveTitleOptions?)

Ensures the page has the given title.

**Usage**

await Expect(Page).ToHaveTitle("Playwright");
Task ToHaveTitleAsync(string titleOrRegExp, PageAssertionsToHaveTitleOptions? options = null)

Parameters

titleOrRegExp string

Expected title or RegExp.

options PageAssertionsToHaveTitleOptions

Call options

Returns

Task

ToHaveTitleAsync(Regex, PageAssertionsToHaveTitleOptions?)

Ensures the page has the given title.

**Usage**

await Expect(Page).ToHaveTitle("Playwright");
Task ToHaveTitleAsync(Regex titleOrRegExp, PageAssertionsToHaveTitleOptions? options = null)

Parameters

titleOrRegExp Regex

Expected title or RegExp.

options PageAssertionsToHaveTitleOptions

Call options

Returns

Task

ToHaveURLAsync(string, PageAssertionsToHaveURLOptions?)

Ensures the page is navigated to the given URL.

**Usage**

await Expect(Page).ToHaveURL(new Regex(".*checkout"));
Task ToHaveURLAsync(string urlOrRegExp, PageAssertionsToHaveURLOptions? options = null)

Parameters

urlOrRegExp string

Expected URL string or RegExp.

options PageAssertionsToHaveURLOptions

Call options

Returns

Task

ToHaveURLAsync(Regex, PageAssertionsToHaveURLOptions?)

Ensures the page is navigated to the given URL.

**Usage**

await Expect(Page).ToHaveURL(new Regex(".*checkout"));
Task ToHaveURLAsync(Regex urlOrRegExp, PageAssertionsToHaveURLOptions? options = null)

Parameters

urlOrRegExp Regex

Expected URL string or RegExp.

options PageAssertionsToHaveURLOptions

Call options

Returns

Task