Kur*_*son 6 javascript testing google-chrome cypress
我正在尝试编写 Cypress 测试来验证beforeunload当用户尝试从不完整的表单中导航时是否会出现对话框。
当用户在与表单交互后尝试离开页面时,我的站点会激活一个beforeunload对话框以警告他们未保存的数据可能会丢失。当我手动测试行为时,一切正常,但是当我尝试在 Cypress 中编写测试时,我得到
'[Intervention] Blocked attempt to show a 'beforeunload' confirmation panel for a frame that never had a user gesture since its load. https://www.chromestatus.com/feature/5082396709879808'.
这是在输入各种字段并模拟click()事件之后。看来 JS 不会触发真正的“用户手势”。我理解 Chrome 这样做的原因,但我希望仍然有一种编写测试的方法。我找到了解决视频播放类似问题的解决方法 @ https://github.com/cypress-io/cypress/issues/2376。但这不适用于“beforeunload”。我在这里找到的所有标志都无法工作https://peter.sh/experiments/chromium-command-line-switches/
on('before:browser:launch', (browser = {}, args) => {
if (browser.name === 'chrome') {
// Mac/Linux
args.push('--disable-gesture-requirement-for-presentation')
}
return args
})
Run Code Online (Sandbox Code Playgroud)
希望可能有解决方法。我可以在 Cypress 中模拟实际的“手势”或在 Chrome 中禁用该要求吗?任何帮助是极大的赞赏。
| 归档时间: |
|
| 查看次数: |
1202 次 |
| 最近记录: |