4

I have Hammer listener on a div, listening for tap and press. I'm writing tests with Cypress and I'm having a deal of trouble to simulate the tap. I'm fiddling with trigger(). I've tried trigger('tap'), trigger('mousedown').trigger(mouseup'), and trigger('touchstart').trigger('touchend'), with no success. Is anyone successfully producing Hammer taps with Cypress ?

The tap calls a function, which sets window.location = new-page.html, like this...

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

Unfortunately, if I call the function directly from Cypress, like this...

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

the Cypress url stem is taken as the base url, not the current location in the application being tested, and I get a steaming 404. This seems very tricky.

bbsimonbb
  • 27,056
  • 15
  • 80
  • 110
  • 1
    Could it be related to an issue I opened them? https://github.com/cypress-io/cypress/issues/2521 – NoriSte Mar 11 '19 at 17:50
  • 1
    Also, see [Erik Zeedijk](https://gitter.im/cypress-io/cypress?at=591d9fd000efc2bb3e7de1af) *We're still trying to get Hammer.js to trigger on a click() or any other event send from Cypress for that matter. From what I understand Cypress cannot send native events. Hammer seems not to recognise the JQuery events, so we're stuck. Also trying custom .invoke actions do not work. Combination of Hammer and Cypress seems to be an issue. Since Hammer events are used in the app everywhere we might need to look back to Selenium for our testing.* –  Mar 12 '19 at 04:36

1 Answers1

2

Try to add property type: 'touch' , to event trigger

 const pointerEvent = {
    force: true,
    pointerType: 'touch',
    x: 11.1386137008667,
    y: 653.46533203125,

}

 cy.get('[data-cy=body]')
            .trigger('pointerdown', pointerEvent)
            .trigger('pointerup', pointerEvent)

In my case I have to press or tap the corners:

const pointerEvent = {
            force: true,
            pointerType: 'touch',
        };
        cy.wait(3000);
        cy.get('[data-cy=body]')
            .trigger('pointerdown', 'topLeft', pointerEvent)
            .trigger('pointerup', 'topLeft', pointerEvent)
            .wait(5000);
silvelo
  • 377
  • 1
  • 7