Javascript cypress get在重新加载后不查询新dom
我想使用Javascript cypress get在重新加载后不查询新dom,javascript,html,cypress,Javascript,Html,Cypress,我想使用cy.get在重新渲染后查询新DOM。但是DOM被更新了,但是cypress似乎在初始加载时缓存了DOM。cy.get在重新渲染后仍然返回第一次加载中的元素,而不是更新元素 有没有办法强制cy.get查询新的DOMcy.get仅在cy.reload(true)之后拾取正确的值但这不是用户会做的。因为用户不需要重新加载页面来显示更改 这里有一个例子 // first load <div id='first-name'> John Smith </div> 你能发
cy.get
在重新渲染后查询新DOM。但是DOM被更新了,但是cypress似乎在初始加载时缓存了DOM。cy.get
在重新渲染后仍然返回第一次加载中的元素,而不是更新元素
有没有办法强制cy.get
查询新的DOMcy.get
仅在cy.reload(true)之后拾取正确的值代码>但这不是用户会做的。因为用户不需要重新加载页面来显示更改
这里有一个例子
// first load
<div id='first-name'>
John Smith
</div>
你能发布完整的测试吗?你在两次进站之间等得怎么样?我已经发布了工作测试。是的,我可以在两天之间等。当轮询更新存储时,我的应用程序重新呈现页面。为了模拟数据更改,我在下一次投票中更改了响应数据。我可以看到反映新数据的页面。但cypress仍然使用旧DOM。
// after 10 seconds
<div id='first-name'>
Grace Smith
</div>
cy.get('[data-testid=slot1-text] > tspan').then(text => {
expect(text.text()).equal('PARKINGFRESERVED');
});
cy.get('[data-testid=slot1-text] > tspan:last-child').then(text => {
cy.wrap(text).should('have.class', 'parking-status-reserved');
expect(text.text()).equal('RESERVED');
});
cy.server();
cy.route('GET', '/mocks/parkingLotConfigs.json', parkingLotConfigsMock).as(
'parkingLotConfigs'
);
// @TODO remove reload, when there is a better way.
// Without using reload the page is updated because of pooling. But cypress does not
// pick up the change in the re-rendered DOM. reload is used as work around only.
// https://stackoverflow.com/questions/62205766/cypress-get-not-querying-the-new-dom-after-rerender
cy.reload(true);
cy.wait('@parkingLotConfigs');
cy.get('[data-testid=slot1-text] > tspan').then(text => {
expect(text.text()).equal('PARKINGFRESERVED');
});
cy.get('[data-testid=slot1-text] > tspan:last-child').then(text => {
cy.wrap(text).should('have.class', 'parking-status-reserved');
expect(text.text()).equal('RESERVED');
});