javascript - 检查按下的按钮是否使用 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'),
]);
推荐阅读
- serial-port - RX/TX 串行通信
- sql - 查询 eloquent 不能 where id = value
- arrays - 如何从数组的最后一个元素开始迭代循环并按顺序进行到下一个?(不倒车)
- java - 在 Spring Boot 中使用 RestClient 对 Rest API 页面进行反序列化
- java - 使用 Spring Boot 战争启动外部 Tom Cat 时出现错误“无法获取 jdbcUrl 的驱动程序实例”
- angular - 用户注销后 Angular Locked 用户名和密码输入
- c - 为什么条件 x!=15 被评估为真给出输出 1
- javascript - 减少Angular Material标签标签宽度的正确方法?
- git - 在现有的 aws 桩线中用 Git 替换 CodeCommit
- python - 如何拆分数据以在 python 中获得所需的输出?