赛普拉斯:你如何在悬停时定位元素?
Cypress: How do you locate element on hover?
我有一个“反应”应用程序,#controlsBar
鼠标悬停时应该可见 #video-container
,但以下代码失败了
cy.get("#controlsBar").should("be.hidden");
cy.get("#video-container")
.trigger("mouseover")
.then((elem) => {
cy.get(elem).children().eq(3).should("be.visible"); //this is #controlsBar
//cy.get("#controlsBar").should("be.visible"); //this failed also
cy.get("#controlsBar").invoke("show");
});
我建议您使用 cypress-real-events 包。
安装使用npm install cypress-real-events
.
然后在cypress/support/index.js
文件下写入import "cypress-real-events/support";
.
那么在你的测试中你可以这样写:
cy.get("#video-container").realHover()
我有一个“反应”应用程序,#controlsBar
鼠标悬停时应该可见 #video-container
,但以下代码失败了
cy.get("#controlsBar").should("be.hidden");
cy.get("#video-container")
.trigger("mouseover")
.then((elem) => {
cy.get(elem).children().eq(3).should("be.visible"); //this is #controlsBar
//cy.get("#controlsBar").should("be.visible"); //this failed also
cy.get("#controlsBar").invoke("show");
});
我建议您使用 cypress-real-events 包。
安装使用
npm install cypress-real-events
.然后在
cypress/support/index.js
文件下写入import "cypress-real-events/support";
.那么在你的测试中你可以这样写:
cy.get("#video-container").realHover()