3

我想知道是否可以使用赛普拉斯测试可覆盖的下拉菜单栏。

例如,当您访问 Ebay ( https://www.ebay.com ) 时,您会在页面右上角看到警告图标,如果您将鼠标悬停在该元素上,登录通知框将出现。

这是我的代码,我按照赛普拉斯告诉我的操作,但我得到了一个错误,比如......

AssertionError 重试超时:应找到元素:#ghn-err,但从未找到它。

 it('ebay hover test', () => {
        cy.visit('https://www.ebay.com')
        // 1. alert icon hover test.
        cy.get('#gh-Alerts-i').trigger('mouseover')
        cy.get('#ghn-err').should('be.visible')
        // 2. This is my another test.
        // cy.get('#gh-eb-My > .gh-menu > .gh-eb-li-a > .gh-sprRetina').trigger('mouseover')
        //cy.get('#gh-eb-My-o > .gh-eb-oa thrd').should('be.visible')
    })

我应该怎么做才能解决这个问题?

先感谢您!

4

2 回答 2

5

对我来说,鼠标悬停有效。这是一个有待解决的已知 Cypress 错误。但是,试试这些:

cy.get('#gh-Alerts-i').trigger('onmouseover')
cy.get('#gh-Alerts-i').trigger('mouseenter')
cy.get('#gh-Alerts-i').invoke('trigger', 'contextmenu')
cy.get('#gh-Alerts-i').rightclick();
于 2021-01-25T15:49:33.990 回答
1

我遇到了同样的问题,我终于找到了这个插件,它完全符合我的要求:做真实事件而不是模拟事件(模拟 == 使用 javascript 启动)。

https://github.com/dmtrKovalenko/cypress-real-events#cyrealhover

只需安装它,在cypress/support/index.js文件中添加一行(不要忘记!)并使用cy.get(<element>).realHover().

于 2021-11-22T16:07:27.560 回答