javascript - Testcafe:多个没有存储事件的 Windows
问题描述
我的应用程序使用 localStorage 事件跨浏览器窗口“通信”。但似乎 testcafe 并没有将存储事件推送到其他浏览器实例。
例子:
<button onClick="setData()">Set</button>
<div id="test"></div>
<script>
window.addEventListener('storage', function(e) {
console.log('storage event');
document.querySelector("#test").textContent = "received";
});
function setData(){
console.log('SET');
localStorage.setItem('superpower', 'heatvision');
document.querySelector("#test").textContent = "clicked";
}
</script>
测试:
const { Selector } = require("testcafe");
fixture `Test`
.page `http://localhost:8081`;
test("test", async t => {
await t.openWindow("http://localhost:8081")
await t.click("button")
await t.expect(Selector("div").innerText).eql("clicked")
await t.switchToPreviousWindow();
await t.expect(Selector("div").innerText).eql("received")
})
有谁知道这是否可以使用testcafe?
解决方案
推荐阅读
- c# - C#获取bool类型的所有属性的值和名称
- regex - Visual Studio Code - 删除包含条件的行
- python - 如何遍历pandas列并将单元格替换为下一行的信息
- apache - 配置 CSP 和 iframe 有什么问题
- angular - 在 angular.json 中扁平化资产
- python - 是否可以在一定时间后停止 Python 中的 exec 或 eval ?
- python - 如何使用 python 从 Maya 内部搜索外部文件结构
- python - 在 Pandas 中将特定列的行除以 date+n
- java - 在Java中的循环内替换字符串中特定位置的字符
- javascript - 根据搜索查询更改远程 URL