如何在e2e测试中触发'swipeleft'事件(量角器)

时间:2021-03-16 01:21:43

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

例如,我有这个应用程序的HTML代码:

<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.

如果我使用'click'insteaf'swipeleft',它就可以了。

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

如何为e2e测试触发'swipeleft'事件?

2 个解决方案

#1


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.

如果-50确实有效,请参阅https://github.com/angular/angular.js/blob/master/src/ngTouch/directive/ngSwipe.js#L74以帮助确定正确的值。

#2


1  

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();

#1


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.

如果-50确实有效,请参阅https://github.com/angular/angular.js/blob/master/src/ngTouch/directive/ngSwipe.js#L74以帮助确定正确的值。

#2


1  

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();