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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With