断言
断言列表
设置自定义超时
您可以全局或按断言指定自定义断言超时。默认超时为 5 秒。
全局超时
- MSTest
- NUnit
UnitTest1.cs
using Microsoft.Playwright;
using Microsoft.Playwright.NUnit;
using NUnit.Framework;
namespace PlaywrightTests;
[Parallelizable(ParallelScope.Self)]
[TestFixture]
public class Tests : PageTest
{
[OneTimeSetUp]
public void GlobalSetup()
{
SetDefaultExpectTimeout(10_000);
}
// ...
}
UnitTest1.cs
using Microsoft.Playwright;
using Microsoft.Playwright.MSTest;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace PlaywrightTests;
[TestClass]
public class UnitTest1 : PageTest
{
[ClassInitialize]
public static void GlobalSetup(TestContext context)
{
SetDefaultExpectTimeout(10_000);
}
// ...
}
按断言超时
UnitTest1.cs
await Expect(Page.GetByText("Name")).ToBeVisibleAsync(new() { Timeout = 10_000 });