测试按下的按钮是否执行正确页面的重定向?

3

我正在使用Playwright编写一项测试,想知道在按下按钮后检查它是否发出预期URL的重定向,以通过测试的最正确的方法。

我发现这个代码片段虽然可行,但会被卡住:

const [request] = await Promise.all([
    // Waits for the next request with the specified url
    page.waitForRequest('*URL*'),
    // Triggers the request
    page.click('button'),
  ]);

它首先点击按钮,重定向发生,但是之后它仍在等待请求。

1个回答

4

waitForNavigation() 对你来说可以吗?

const [response] = await Promise.all([
    // Waits for the main frame navigation and returns the main resource response 
    page.waitForNavigation({url: '*URL*'}),
    // Triggers the request
    page.click('button'),
]);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接