下面是我的代码,我试图在新选项卡上执行一些操作,当单击原始选项卡上的链接时会出现这些操作。在打开新页面之前它工作正常,但之后在新页面上没有执行任何操作并且测试也没有停止,它只是进入了一些无限循环。
测试钩子
[BeforeScenario]
public async Task BeforeScenario()
{
var playwright = await Playwright.CreateAsync();
var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
{
Headless = false,
SlowMo = 1000,
});
var context = await browser.NewContextAsync(new BrowserNewContextOptions
{
IgnoreHTTPSErrors = true
});
var page = await context.NewPageAsync();
await Page.GotoAsync(URL);
}
页面对象
public async Task ClickAndNavigate(String linkText)
{
var playwright1 = await Playwright.CreateAsync();
var browser1 = await playwright1.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
{
Headless = false,
});
var context1 = await browser1.NewContextAsync(new BrowserNewContextOptions
{
IgnoreHTTPSErrors = true
});
var newPage = await context1.RunAndWaitForPageAsync(async () =>
{
await page.ClickAsync("text=linkText");
});
await newPage.WaitForLoadStateAsync();
Console.WriteLine(await newPage.TitleAsync());
await newPage.CloseAsync();
}