gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 02:38:51 24 4
gpt4 key购买 nike

我正在与 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'),
]);

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

最佳答案

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

关于javascript - 测试按下的按钮是否执行重定向到正确的页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69433210/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com