jeudi 25 février 2021

Testcafe: Multiple Windows with no storage events

My app uses the localStorage event to "communicate" across browser windows. But it seems that testcafe does not pulish the storage event to other browser instances.

Example:

<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>

Test:

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")
})

Does anyone know if this is possible using testcafe?

Aucun commentaire:

Enregistrer un commentaire