首页 > 解决方案 > 检查按下的按钮是否使用 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'),
  ]);

但它被卡住了,因为它首先单击按钮,重定向发生,但无论如何它一直在等待请求。

标签: javascripttypescriptredirectautomated-testsplaywright

解决方案


waitForNaviation()为你工作吗?

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'),
]);

推荐阅读