首页 > 解决方案 > 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?

标签: javascripttestingautomated-testse2e-testingtestcafe

解决方案


推荐阅读