data-dr-hide
属性决定叠加层是否出现。
cy.get('.popup').invoke('attr', 'data-dr-hide', 'true')
.should('have.attr', 'data-dr-hide', 'true');
// the `true` may or may not need to be in quotes
如果您可以识别确定您是否是首次访问者的 cookie 或 本地存储或会话存储 值,则只需加载该值设置为表明您不是首次访问者的页面也可能会有所帮助第一次来访。
// pseudo-code
describe('My Tests', () => {
beforeEach(() => {
cy.visit('/url')
.then(() => {
window.localStorage.setItem('firstTimeVisitor', false);
window.sessionStorage.setItem('firstTimeVisitor', false);
}).setCookie('firstTimeVisitor', false);
});
it('validates X', () => {
// code here
});
});
这解决了我的问题:
cy.get('body').then(($body) => {
if ($body.find('.overlay').is(":visible")) {
cy.get('.overlay').click()
}
})