English · .NET
Appearance
English · .NET
Appearance
Playwright gives you Web-First Assertions with convenience methods for creating assertions that will wait and retry until the expected condition is met.
Consider the following example:
using Microsoft.Playwright;
using Microsoft.Playwright.MSTest;
namespace PlaywrightTests;
[TestClass]
public class ExampleTests : PageTest
{
[TestMethod]
public async Task StatusBecomesSubmitted()
{
await Page.GetByRole(AriaRole.Button, new() { Name = "Submit" }).ClickAsync();
await Expect(Page.Locator(".status")).ToHaveTextAsync("Submitted");
}
}Playwright will be re-testing the node with the selector .status until fetched Node has the "Submitted" text. It will be re-fetching the node and checking it over and over, until the condition is met or until the timeout is reached. You can pass this timeout as an option.
By default, the timeout for assertions is set to 5 seconds.
Creates a APIResponseAssertions object for the given APIResponse.
Usage
Arguments
APIResponse object to use for assertions.
Returns
APIResponseAssertionsCreates a FunctionAssertions object for the given callback.
Usage
await Expect(async () =>
{
var response = await Page.APIRequest.GetAsync("https://api.example.com");
Assert.AreEqual(200, response.Status);
}).ToPassAsync();Arguments
Returns
FunctionAssertionsCreates a LocatorAssertions object for the given Locator.
Usage
await Expect(locator).ToBeVisibleAsync();Arguments
Locator object to use for assertions.
Returns
LocatorAssertionsCreates a PageAssertions object for the given Page.
Usage
await Expect(Page).ToHaveTitleAsync("News");Arguments
Page object to use for assertions.
Returns
PageAssertions