如何删除覆盖层

问题描述 投票:0回答:2

我从 API 收到一系列产品名称,我将其反复输入到“主搜索栏”中。

在模拟首次访问该页面的行为时,我遇到了一个弹出叠加层,它使除自身之外的所有元素都无响应。

html css popup cypress overlay
2个回答
0
投票

您还可以修改元素以使其不出现,假设

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

0
投票

这解决了我的问题:

cy.get('body').then(($body) => {
                      if ($body.find('.overlay').is(":visible")) {
                          cy.get('.overlay').click()
                      }
                  })
© www.soinside.com 2019 - 2024. All rights reserved.