【问题标题】:How to test the functionality of clicking away from a dropdown menu, and it closing如何测试从下拉菜单中单击并关闭的功能
【发布时间】:2019-02-27 22:46:22
【问题描述】:

我正在测试 cypress 中下拉窗口的功能。一旦下拉菜单打开并测试它是可见的。如何测试在菜单外单击会关闭下拉菜单?据我所知,您只能在可点击元素上调用 .click() ,否则会引发错误。

it('Clicking on away from the dropdown menu should close the menu', () => {
    cy.get('???????').click()
    cy.get('#menu').should('not.be.visible')
  })

【问题讨论】:

    标签: e2e-testing cypress


    【解决方案1】:

    我假设您的下拉菜单确实在听 blur。在这种情况下,您可以执行以下任一操作:

    cy.get('#menu').blur()
    

    cy.get('body').focus()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-24
      • 1970-01-01
      • 2021-11-17
      • 2014-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多