setNativeDialogHandler 来处理 ie11 访问剪贴板



我有一个测试,可以启动复制到剪贴板。 在 IE11 中,生成对话框 https://i.stack.imgur.com/VSEIT.jpg

我无法清除它。 这是我的代码

fixture.only`Downloads`
.page`${page.page}`
.beforeEach(async (t) => {
await t
.maximizeWindow()
.setNativeDialogHandler((type, text, url) => {
if (type === 'confirm') { return false } return true
})
await page.loginAdmin()
})
.afterEach(async (t) => {
await t.setNativeDialogHandler(null)
})

但它不会清除对话框。 我也试过

.setNativeDialogHandler(() => true)

但对话框仍然存在,测试超时

可以使用以下方法进行剪贴板交互:  

const overrideClipboardCopy = ClientFunction(() => {
const execCommand = document.execCommand;
document.execCommand = (action, ...args) => {
if (action === 'copy') {
//handle copy here
}
else
return execCommand.call(document, ...args);
}
});

另请参阅:允许在测试中使用 HTML5 剪贴板 API

最新更新