PageAssertions Class

The assertions of a page, as the web-first assertions of Playwright: each assertion runs the event loop of the page until it passes, and throws an ExpectationFailedException when it still fails after the timeout.

public sealed class PageAssertions

Properties

NameDescription
NotGets the negated assertions (Expect(page).Not.ToHaveUrlAsync("http://localhost/sign-in")).

Gets the negated assertions (Expect(page).Not.ToHaveUrlAsync("http://localhost/sign-in")).

public PageAssertions Not { get; }

Property value

PageAssertions

Methods

NameDescription
ToHaveTitleAsync(string, TimeSpan?, CancellationToken)Waits until the title of the active document is a text, once the white space of both texts is collapsed.
ToHaveTitleAsync(Regex, TimeSpan?, CancellationToken)Waits until the title of the active document matches a regular expression.
ToHaveUrlAsync(string, TimeSpan?, CancellationToken)Waits until the URL of the active document is a URL.
ToHaveUrlAsync(Regex, TimeSpan?, CancellationToken)Waits until the URL of the active document matches a regular expression.

ToHaveTitleAsync overloads

ToHaveTitleAsync(string, TimeSpan?, CancellationToken)

PageAssertions.cs

Waits until the title of the active document is a text, once the white space of both texts is collapsed.

public Task ToHaveTitleAsync(string title, TimeSpan? timeout = null, CancellationToken cancellationToken = default)
Parameters
title string
The title.
timeout TimeSpan?
The maximum time to wait, or null for TestPage.DefaultTimeout.
cancellationToken CancellationToken
A token to cancel the wait.
Returns

Task A task completed once the assertion passes.

ToHaveTitleAsync(Regex, TimeSpan?, CancellationToken)

PageAssertions.cs

Waits until the title of the active document matches a regular expression.

public Task ToHaveTitleAsync(Regex title, TimeSpan? timeout = null, CancellationToken cancellationToken = default)
Parameters
title Regex
The regular expression.
timeout TimeSpan?
The maximum time to wait, or null for TestPage.DefaultTimeout.
cancellationToken CancellationToken
A token to cancel the wait.
Returns

Task A task completed once the assertion passes.

ToHaveUrlAsync overloads

ToHaveUrlAsync(string, TimeSpan?, CancellationToken)

PageAssertions.cs

Waits until the URL of the active document is a URL.

public Task ToHaveUrlAsync(string url, TimeSpan? timeout = null, CancellationToken cancellationToken = default)
Parameters
url string
The URL, or a path relative to the URL of the document (/profile).
timeout TimeSpan?
The maximum time to wait, or null for TestPage.DefaultTimeout.
cancellationToken CancellationToken
A token to cancel the wait.
Returns

Task A task completed once the assertion passes.

ToHaveUrlAsync(Regex, TimeSpan?, CancellationToken)

PageAssertions.cs

Waits until the URL of the active document matches a regular expression.

public Task ToHaveUrlAsync(Regex url, TimeSpan? timeout = null, CancellationToken cancellationToken = default)
Parameters
url Regex
The regular expression.
timeout TimeSpan?
The maximum time to wait, or null for TestPage.DefaultTimeout.
cancellationToken CancellationToken
A token to cancel the wait.
Returns

Task A task completed once the assertion passes.