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?

Alexandr Alex
  • 91
  • 1
  • 2

2 Answers2

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.

Julien Bérubé
  • 1,256
  • 1
  • 13
  • 22
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();