PageAssertions
The PageAssertions class provides assertion methods that can be used to make assertions about the Page state in the tests.
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.Playwright.NUnit;
using NUnit.Framework;
namespace PlaywrightTests;
[TestFixture]
public class ExampleTests : PageTest
{
[Test]
public async Task NavigatetoLoginPage()
{
// ..
await Page.GetByText("Sing in").ClickAsync();
await Expect(Page.Locator("div#foobar")).ToHaveURL(new Regex(".*/login"));
}
}
Methods
ToHaveTitleAsync
Added in: v1.20Ensures the page has the given title.
Usage
await Expect(page).ToHaveTitle("Playwright");
Arguments
titleOrRegExp
string|Regex Added in: v1.18#Expected title or RegExp.
options
PageAssertionsToHaveTitleOptions?
(optional)Timeout
[float]? (optional) Added in: v1.18#Time to retry the assertion for.
ToHaveURLAsync
Added in: v1.20Ensures the page is navigated to the given URL.
Usage
await Expect(page).ToHaveURL(new Regex(".*checkout"));
Arguments
urlOrRegExp
string|Regex Added in: v1.18#Expected URL string or RegExp.
options
PageAssertionsToHaveURLOptions?
(optional)Timeout
[float]? (optional) Added in: v1.18#Time to retry the assertion for.
Properties
Not
Added in: v1.20Makes the assertion check for the opposite condition. For example, this code tests that the page URL doesn't contain "error"
:
await Expect(page).Not.ToHaveURL("error");
Usage
Expect(Page).Not
Type