跳到正文
本页尚未翻译成中文,以下为英文原文。 查看英文版

PlaywrightAssertionException ​

Added in: v1.65

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}");
}

基于 Apache 2.0 许可证发布。