Interface IPageAssertions
- Namespace
- Microsoft.Playwright
- Assembly
- Microsoft.Playwright.dll
The IPageAssertions class provides assertion methods that can be used to make assertions about the IPage state in the tests.
using System.Text.RegularExpressions;
using Microsoft.Playwright;
using Microsoft.Playwright.MSTest;
namespace PlaywrightTests;
[TestClass]
public class ExampleTests : PageTest
{
[TestMethod]
public async Task NavigatetoLoginPage()
{
await Page.GetByRole(AriaRole.Button, new() { Name = "Sign In" }).ClickAsync();
await Expect(Page).ToHaveURLAsync(new Regex(".*/login"));
}
}
public interface IPageAssertions
Properties
Not
Makes 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");
IPageAssertions Not { get; }
Property Value
Methods
ToHaveTitleAsync(string, PageAssertionsToHaveTitleOptions?)
Ensures the page has the given title.
**Usage**
await Expect(Page).ToHaveTitle("Playwright");
Task ToHaveTitleAsync(string titleOrRegExp, PageAssertionsToHaveTitleOptions? options = null)
Parameters
titleOrRegExp
stringExpected title or RegExp.
options
PageAssertionsToHaveTitleOptionsCall options
Returns
ToHaveTitleAsync(Regex, PageAssertionsToHaveTitleOptions?)
Ensures the page has the given title.
**Usage**
await Expect(Page).ToHaveTitle("Playwright");
Task ToHaveTitleAsync(Regex titleOrRegExp, PageAssertionsToHaveTitleOptions? options = null)
Parameters
titleOrRegExp
RegexExpected title or RegExp.
options
PageAssertionsToHaveTitleOptionsCall options
Returns
ToHaveURLAsync(string, PageAssertionsToHaveURLOptions?)
Ensures the page is navigated to the given URL.
**Usage**
await Expect(Page).ToHaveURL(new Regex(".*checkout"));
Task ToHaveURLAsync(string urlOrRegExp, PageAssertionsToHaveURLOptions? options = null)
Parameters
urlOrRegExp
stringExpected URL string or RegExp.
options
PageAssertionsToHaveURLOptionsCall options
Returns
ToHaveURLAsync(Regex, PageAssertionsToHaveURLOptions?)
Ensures the page is navigated to the given URL.
**Usage**
await Expect(Page).ToHaveURL(new Regex(".*checkout"));
Task ToHaveURLAsync(Regex urlOrRegExp, PageAssertionsToHaveURLOptions? options = null)
Parameters
urlOrRegExp
RegexExpected URL string or RegExp.
options
PageAssertionsToHaveURLOptionsCall options