Docs · API reference · Motus.Assertions

LocatorAssertions Class#

Assertions about a single locator, obtained from That(ILocator).

public sealed class LocatorAssertions

Inheritance System.Object → LocatorAssertions

Remarks#

Every assertion here re-evaluates its condition until it holds or the timeout elapses, so a value the page has not settled on yet is waited for rather than failed on, which makes an assertion after a navigation or an interaction safe. The element itself is a separate question: these need it present already and fail at once when the locator matches nothing, rather than waiting for it to appear, so wait for one that has still to render with ToBeAttachedAsync first. The timeout and the message on failure come from the AssertionOptions each method accepts.

Properties#

Not Property#

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

public Motus.Assertions.LocatorAssertions Not { get; }

Property Value#

LocatorAssertions

Remarks#

The retry still applies, inverted with it: a negated assertion waits for the condition to stop holding rather than passing the moment it does not hold yet.

Methods#

ToBeAttachedAsync(AssertionOptions) Method#

Asserts that at least one element matches the locator in the DOM.

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

Parameters#

options AssertionOptions

Timeout and failure message overrides.

Returns#

System.Threading.Tasks.Task

Remarks#

Attachment says nothing about visibility. An element behind a closed accordion is attached; use ToBeVisibleAsync(AssertionOptions) when the question is whether it can be seen.

ToBeCheckedAsync(AssertionOptions) Method#

Asserts that the checkbox or radio button is checked.

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

Parameters#

options AssertionOptions

Timeout and failure message overrides.

Returns#

System.Threading.Tasks.Task

ToBeDetachedAsync(AssertionOptions) Method#

Asserts that no element matches the locator in the DOM.

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

Parameters#

options AssertionOptions

Timeout and failure message overrides.

Returns#

System.Threading.Tasks.Task

ToBeDisabledAsync(AssertionOptions) Method#

Asserts that the element is disabled and will not accept interaction.

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

Parameters#

options AssertionOptions

Timeout and failure message overrides.

Returns#

System.Threading.Tasks.Task

ToBeEditableAsync(AssertionOptions) Method#

Asserts that the element accepts typed input rather than being read-only.

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

Parameters#

options AssertionOptions

Timeout and failure message overrides.

Returns#

System.Threading.Tasks.Task

ToBeEmptyAsync(AssertionOptions) Method#

Asserts that the element has no text and no child elements.

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

Parameters#

options AssertionOptions

Timeout and failure message overrides.

Returns#

System.Threading.Tasks.Task

ToBeEnabledAsync(AssertionOptions) Method#

Asserts that the element accepts interaction rather than being disabled.

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

Parameters#

options AssertionOptions

Timeout and failure message overrides.

Returns#

System.Threading.Tasks.Task

ToBeHiddenAsync(AssertionOptions) Method#

Asserts that the element is absent from the DOM or not visible on the page.

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

Parameters#

options AssertionOptions

Timeout and failure message overrides.

Returns#

System.Threading.Tasks.Task

ToBeVisibleAsync(AssertionOptions) Method#

Asserts that the element is present in the DOM and visible on the page.

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

Parameters#

options AssertionOptions

Timeout and failure message overrides.

Returns#

System.Threading.Tasks.Task

ToContainTextAsync(string, AssertionOptions) Method#

Asserts that the element's text content contains the expected substring.

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

Parameters#

expected System.String

The substring the text must contain.

options AssertionOptions

Timeout and failure message overrides.

Returns#

System.Threading.Tasks.Task

ToHaveAccessibleNameAsync(string, AssertionOptions) Method#

Asserts that the element's accessible name, as the browser computes it, equals the expected string.

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

Parameters#

expected System.String

The accessible name required.

options AssertionOptions

Timeout and failure message overrides.

Returns#

System.Threading.Tasks.Task

Remarks#

The accessible name is what a screen reader announces, which is not always the element's text: a label, an aria-label, or an image's alt text can supply it instead.

ToHaveAttributeAsync(string, string, AssertionOptions) Method#

Asserts that the element carries an attribute with the expected value.

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

Parameters#

name System.String

The attribute name.

expected System.String

The value the attribute must hold.

options AssertionOptions

Timeout and failure message overrides.

Returns#

System.Threading.Tasks.Task

ToHaveClassAsync(string, AssertionOptions) Method#

Asserts that the element's class list includes the named class.

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

Parameters#

className System.String

The single class name to look for.

options AssertionOptions

Timeout and failure message overrides.

Returns#

System.Threading.Tasks.Task

ToHaveCountAsync(int, AssertionOptions) Method#

Asserts that the locator matches exactly the expected number of elements.

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

Parameters#

expected System.Int32

The number of matches required.

options AssertionOptions

Timeout and failure message overrides.

Returns#

System.Threading.Tasks.Task

ToHaveCSSAsync(string, string, AssertionOptions) Method#

Asserts that a computed CSS property resolves to the expected value.

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

Parameters#

property System.String

The CSS property name, as the browser computes it.

expected System.String

The computed value to match, in the browser's own serialization.

options AssertionOptions

Timeout and failure message overrides.

Returns#

System.Threading.Tasks.Task

Remarks#

The comparison is against the computed value rather than the authored one, so a color written as a keyword or a hex triple is reported in the browser's normalized form.

ToHaveRoleAsync(string, AssertionOptions) Method#

Asserts that the element's computed ARIA role equals the expected role.

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

Parameters#

expected System.String

The ARIA role required, such as button or navigation.

options AssertionOptions

Timeout and failure message overrides.

Returns#

System.Threading.Tasks.Task

Remarks#

The role is the computed one, so an element carries its implicit role without an explicit role attribute: a <nav> reports navigation.

ToHaveTextAsync(string, AssertionOptions) Method#

Asserts that the element's text content equals the expected string exactly.

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

Parameters#

expected System.String

The full text the element must carry.

options AssertionOptions

Timeout and failure message overrides.

Returns#

System.Threading.Tasks.Task

ToHaveTextAsync(Regex, AssertionOptions) Method#

Asserts that the element's text content matches the expected pattern.

public System.Threading.Tasks.Task ToHaveTextAsync(System.Text.RegularExpressions.Regex expected, Motus.Abstractions.AssertionOptions? options=null);

Parameters#

expected System.Text.RegularExpressions.Regex

The pattern the text must match.

options AssertionOptions

Timeout and failure message overrides.

Returns#

System.Threading.Tasks.Task

ToHaveValueAsync(string, AssertionOptions) Method#

Asserts that the input element's current value equals the expected string.

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

Parameters#

expected System.String

The value the input must hold.

options AssertionOptions

Timeout and failure message overrides.

Returns#

System.Threading.Tasks.Task