How to trigger 'swipeleft' event in e2e test (protractor)
Asked Answered
T

2

9

For example, i have this html-code of application:

<div class="swipe-cover" ng-swipe-left="func()"></div>

and such test:

it('test', function() {
   browser.executeScript( 'angular.element(".swipe-cover").triggerHandler("swipeleft")' );
});

but it doesn't work.

If i use 'click' insteaf of 'swipeleft', it works.

How can i trigger 'swipeleft' event for e2e tests?

Trapezohedron answered 9/7, 2015 at 12:35 Comment(2)
I'm taking a stab here, but have you tried: .triggerHandler("touchstart");Tedesco
i have tried, so it didn't help.Trapezohedron
B
2

Simulating a gesture work better using a serie of actions:

driver.actions()
        .mouseDown(element(by.css('.filter-editorial-rating .ngrs-handle-max')))
        .mouseMove({x: -50, y: 0}) // try different value of x
        .mouseUp()
        .perform();

See https://github.com/angular/angular.js/blob/master/src/ngTouch/directive/ngSwipe.js#L74 to help tou figure out the right value if -50 does work out.

Brantley answered 25/8, 2015 at 1:41 Comment(0)
S
2

This is a solution I found.

var card = element(by.css('#card-container'));

browser.actions()
  .mouseMove(card, {x: 100, y: 100}) 
  .mouseDown()
  .mouseMove({x: -200, y: 0})
  .perform();

browser.sleep(500);

browser.actions()
  .mouseUp()
  .perform();
Strychnic answered 27/7, 2016 at 9:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.