Skip to main content

Assertions

List of assertions

AssertionDescription
Expect(Locator).ToBeAttachedAsync()Element is attached
Expect(Locator).ToBeCheckedAsync()Checkbox is checked
Expect(Locator).ToBeDisabledAsync()Element is disabled
Expect(Locator).ToBeEditableAsync()Element is editable
Expect(Locator).ToBeEmptyAsync()Container is empty
Expect(Locator).ToBeEnabledAsync()Element is enabled
Expect(Locator).ToBeFocusedAsync()Element is focused
Expect(Locator).ToBeHiddenAsync()Element is not visible
Expect(Locator).ToBeInViewportAsync()Element intersects viewport
Expect(Locator).ToBeVisibleAsync()Element is visible
Expect(Locator).ToContainTextAsync()Element contains text
Expect(Locator).ToHaveAttributeAsync()Element has a DOM attribute
Expect(Locator).ToHaveClassAsync()Element has a class property
Expect(Locator).ToHaveCountAsync()List has exact number of children
Expect(Locator).ToHaveCSSAsync()Element has CSS property
Expect(Locator).ToHaveIdAsync()Element has an ID
Expect(Locator).ToHaveJSPropertyAsync()Element has a JavaScript property
Expect(Locator).ToHaveTextAsync()Element matches text
Expect(Locator).ToHaveValueAsync()Input has a value
Expect(Locator).ToHaveValuesAsync()Select has options selected
Expect(Page).ToHaveTitleAsync()Page has a title
Expect(Page).ToHaveURLAsync()Page has a URL
Expect(Response).ToBeOKAsync()Response has an OK status

Setting a custom timeout

You can specify a custom timeout for assertions either globally or per assertion. The default timeout is 5 seconds.

Global timeout

UnitTest1.cs
using Microsoft.Playwright;
using Microsoft.Playwright.NUnit;
using NUnit.Framework;

namespace PlaywrightTests;

[Parallelizable(ParallelScope.Self)]
[TestFixture]
public class Tests : PageTest
{
[OneTimeSetUp]
public void GlobalSetup()
{
SetDefaultExpectTimeout(10_000);
}
// ...
}

Per assertion timeout

UnitTest1.cs
await Expect(Page.GetByText("Name")).ToBeVisibleAsync(new() { Timeout = 10_000 });