Docs · API reference · Motus.Assertions

PageAssertions Class#

Assertions about a page as a whole, obtained from That(IPage).

public sealed class PageAssertions

Inheritance System.Object → PageAssertions

Remarks#

The URL, title and performance assertions re-evaluate until they hold or the timeout elapses, so a navigation still in flight is waited for rather than failed on. The accessibility audit is the exception and is evaluated once, since it describes the document as it stands.

Properties#

Not Property#

Inverts the assertion that follows, so it passes when the condition does not hold.

public Motus.Assertions.PageAssertions Not { get; }

Property Value#

PageAssertions

Methods#

ToHaveClsBelowAsync(double, AssertionOptions) Method#

Asserts that Cumulative Layout Shift, how much the page moved under the reader while loading, is at or below the given threshold.

public System.Threading.Tasks.Task ToHaveClsBelowAsync(double threshold, Motus.Abstractions.AssertionOptions? options=null);

Parameters#

threshold System.Double

The upper bound, as an unitless score rather than a duration.

options AssertionOptions

Timeout and failure message overrides.

Returns#

System.Threading.Tasks.Task

ToHaveFcpBelowAsync(double, AssertionOptions) Method#

Asserts that First Contentful Paint, the time until any content first appears, is at or below the given threshold.

public System.Threading.Tasks.Task ToHaveFcpBelowAsync(double thresholdMs, Motus.Abstractions.AssertionOptions? options=null);

Parameters#

thresholdMs System.Double

The upper bound in milliseconds.

options AssertionOptions

Timeout and failure message overrides.

Returns#

System.Threading.Tasks.Task

ToHaveInpBelowAsync(double, AssertionOptions) Method#

Asserts that Interaction to Next Paint, how long the page took to respond visibly to the reader, is at or below the given threshold.

public System.Threading.Tasks.Task ToHaveInpBelowAsync(double thresholdMs, Motus.Abstractions.AssertionOptions? options=null);

Parameters#

thresholdMs System.Double

The upper bound in milliseconds.

options AssertionOptions

Timeout and failure message overrides.

Returns#

System.Threading.Tasks.Task

Remarks#

The metric only exists once something has been interacted with, so a page that has merely been loaded reports none and the assertion fails rather than passing vacuously.

ToHaveLcpBelowAsync(double, AssertionOptions) Method#

Asserts that Largest Contentful Paint, the time until the largest element in the viewport has rendered, is at or below the given threshold.

public System.Threading.Tasks.Task ToHaveLcpBelowAsync(double thresholdMs, Motus.Abstractions.AssertionOptions? options=null);

Parameters#

thresholdMs System.Double

The upper bound in milliseconds.

options AssertionOptions

Timeout and failure message overrides.

Returns#

System.Threading.Tasks.Task

ToHaveTitleAsync(string, AssertionOptions) Method#

Asserts that the document title equals the expected string.

public System.Threading.Tasks.Task ToHaveTitleAsync(string expected, Motus.Abstractions.AssertionOptions? options=null);

Parameters#

expected System.String

The title the document must carry.

options AssertionOptions

Timeout and failure message overrides.

Returns#

System.Threading.Tasks.Task

ToHaveTtfbBelowAsync(double, AssertionOptions) Method#

Asserts that Time To First Byte, the wait before the server's response begins arriving, is at or below the given threshold.

public System.Threading.Tasks.Task ToHaveTtfbBelowAsync(double thresholdMs, Motus.Abstractions.AssertionOptions? options=null);

Parameters#

thresholdMs System.Double

The upper bound in milliseconds.

options AssertionOptions

Timeout and failure message overrides.

Returns#

System.Threading.Tasks.Task

ToHaveUrlAsync(string, AssertionOptions) Method#

Asserts that the page's current URL equals or matches the expected pattern.

public System.Threading.Tasks.Task ToHaveUrlAsync(string urlOrGlob, Motus.Abstractions.AssertionOptions? options=null);

Parameters#

urlOrGlob System.String

A full URL, or a pattern containing * for any run of characters.

options AssertionOptions

Timeout and failure message overrides.

Returns#

System.Threading.Tasks.Task

Remarks#

Three forms are accepted, and which one applies depends on the pattern. A pattern equal to the URL matches it. A pattern containing * is matched against the whole URL, so https://example.com/orders/* matches any order page but not the site root. A pattern containing no * at all matches when the URL merely contains it, which is worth knowing: /orders also matches https://example.com/orders/17/edit.

ToMeetPerformanceBudgetAsync(AssertionOptions) Method#

Asserts that every metric in the active performance budget is within its threshold, and names the ones that are not when it fails.

public System.Threading.Tasks.Task ToMeetPerformanceBudgetAsync(Motus.Abstractions.AssertionOptions? options=null);

Parameters#

options AssertionOptions

Timeout and failure message overrides.

Returns#

System.Threading.Tasks.Task

Exceptions#

System.InvalidOperationException
No performance budget is in effect.

Remarks#

The budget is resolved in order from the one applied to the page, then the one carried by the ambient test context, then the thresholds in configuration. When none of those supplies a budget the call throws System.InvalidOperationException rather than passing, since an assertion with nothing to assert would otherwise report success.

ToPassAccessibilityAuditAsync(Action<AccessibilityAssertionOptions>, AssertionOptions) Method#

Asserts that the page raises no accessibility violations, and reports every violation it found when it does.

public System.Threading.Tasks.Task ToPassAccessibilityAuditAsync(System.Action<Motus.Assertions.AccessibilityAssertionOptions>? configure=null, Motus.Abstractions.AssertionOptions? options=null);

Parameters#

configure System.Action<AccessibilityAssertionOptions>

Narrows what counts as a failure: rules to skip, and whether warnings fail alongside errors.

options AssertionOptions

Failure message override. The timeout is unused, since no retry occurs.

Returns#

System.Threading.Tasks.Task

Remarks#

A result already collected by the audit hook is reused; without one, an audit runs here against the rules registered on the context. Unlike the other page assertions this is evaluated once rather than retried, so wait for the page to settle before calling it.