我在 div 上有 Hammer 监听器,监听点击和按下。我正在使用 Cypress 编写测试,但在模拟水龙头时遇到了很多麻烦。我正在摆弄 trigger()
。我尝试过 trigger('tap')
、trigger('mousedown').trigger(mouseup')
和 trigger('touchstart').trigger ('touchend')
,没有成功。有人用 Cypress 成功生产 Hammer Tap 吗?
点击调用一个函数,该函数设置window.location = new-page.html
,如下所示...
function changePage(id) {
window.location.href = "FraisEnListe.aspx?idnote=" + id;
}
不幸的是,如果我直接从 Cypress 调用该函数,就像这样......
cy.window().then((win) => {
win.changePage(29312);
})
Cypress url 茎被视为基本 url,而不是正在测试的应用程序中的当前位置,我得到了一个热气腾腾的 404。这看起来非常棘手。
最佳答案
尝试添加属性 type: 'touch' 到事件触发器
const pointerEvent = {
force: true,
pointerType: 'touch',
x: 11.1386137008667,
y: 653.46533203125,
}
cy.get('[data-cy=body]')
.trigger('pointerdown', pointerEvent)
.trigger('pointerup', pointerEvent)
就我而言,我必须按下或点击角落:
const pointerEvent = {
force: true,
pointerType: 'touch',
};
cy.wait(3000);
cy.get('[data-cy=body]')
.trigger('pointerdown', 'topLeft', pointerEvent)
.trigger('pointerup', 'topLeft', pointerEvent)
.wait(5000);
关于cypress - 如何让 Cypress 模拟 Hammer Tap?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55104495/