PlaywrightAssertionException
Added in: v1.65Extends: PlaywrightException
- extends: PlaywrightException
PlaywrightAssertionException is thrown when an assertion is not met, e.g. LocatorAssertions.ToBeVisibleAsync() times out waiting for the element. It inherits from PlaywrightException, so catch (PlaywrightException) blocks catch it as well.
csharp
try
{
await Expect(page.GetByRole(AriaRole.Button)).ToBeVisibleAsync();
}
catch (PlaywrightAssertionException e)
{
Console.WriteLine($"Assertion failed: {e.Message}");
}