File: test-assertions.md | Updated: 11/18/2025
On this page
List of assertions
| Assertion | Description | | --- | --- | | 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).ToContainClassAsync() | Element has specified CSS classes | | Expect(Locator).ToContainTextAsync() | Element contains text | | Expect(Locator).ToHaveAccessibleDescriptionAsync() | Element has a matching accessible description | | Expect(Locator).ToHaveAccessibleNameAsync() | Element has a matching accessible name | | 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).ToHaveRoleAsync() | Element has a specific ARIA role | | Expect(Locator).ToHaveTextAsync() | Element matches text | | Expect(Locator).ToHaveValueAsync() | Input has a value | | Expect(Locator).ToHaveValuesAsync() | Select has options selected | | Expect(Locator).ToMatchAriaSnapshotAsync() | Element matches provided Aria snapshot | | 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.
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); } // ...}
UnitTest1.cs
using Microsoft.Playwright;using Microsoft.Playwright.MSTest;using Microsoft.VisualStudio.TestTools.UnitTesting;namespace PlaywrightTests;[TestClass]public class UnitTest1 : PageTest{ [ClassInitialize] public static void GlobalSetup(TestContext context) { SetDefaultExpectTimeout(10_000); } // ...}
UnitTest1.cs
using Microsoft.Playwright;using Microsoft.Playwright.Xunit;namespace PlaywrightTests;public class UnitTest1: PageTest{ UnitTest1() { SetDefaultExpectTimeout(10_000); } // ...}
UnitTest1.cs
using Microsoft.Playwright;using Microsoft.Playwright.Xunit.v3;namespace PlaywrightTests;public class UnitTest1: PageTest{ UnitTest1() { SetDefaultExpectTimeout(10_000); } // ...}
UnitTest1.cs
await Expect(Page.GetByText("Name")).ToBeVisibleAsync(new() { Timeout = 10_000 });