cypress - 如何让 Cypress 模拟 Hammer Tap?

标签 cypress hammer

我在 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/

相关文章:

cypress:带有标签和 CSS 定位器的条件

cypress - 在 Cypress 中,如何等待页面加载?

variables - Cypress 如何将全局常量存储在可以跨所有规范文件使用的文件中?

java - 有哪些(好的)Java RADIUS 服务器库?

javascript - 使用hammer.js使克隆交换到html元素

Python:用#字符分割文本文件并汇总总数

angular - Cypress 安装因代理设置而失败

typescript - Cypress 10 : Custom command is not a function