我如何让赛普拉斯模拟锤头拍打?

时间:2019-03-11 14:48:43

标签: cypress hammer

我在div上有Hammer侦听器,正在监听点击。我正在用赛普拉斯(Cypress)编写测试,在模拟水龙头时遇到了很多麻烦。我不喜欢trigger()。我尝试了trigger('tap')trigger('mousedown').trigger(mouseup')trigger('touchstart').trigger('touchend'),但都没有成功。有人用赛普拉斯成功生产了锤头丝锥吗?

点击会调用一个函数,该函数会设置window.location = new-page.html,就像这样...

function changePage(id) {
    window.location.href = "FraisEnListe.aspx?idnote=" + id;
}

不幸的是,如果我直接从赛普拉斯调用该函数,就像这样...

cy.window().then((win) => {
  win.changePage(29312);
})

赛普拉斯url词干被用作基本url,而不是被测试应用程序中的当前位置,因此我得到了一个冒泡的404。这似乎很棘手。

1 个答案:

答案 0 :(得分:0)

尝试将属性类型:'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);
相关问题