swipe and click a button protractor

后端 未结 2 1739
-上瘾入骨i
-上瘾入骨i 2021-01-15 17:38

i need to swipe an item and need to click on a button in that item, i used this the test is success but i could not view that button this test case is written to swipe left

相关标签:
2条回答
  • 2021-01-15 18:18

    I am doing something similar, with an ion-list, with ion-items, and ion-option-buttons. My swipe works, and looks like this:

    var elements = element(by.id("item-list")).all(by.tagName("ion-item"));
    var item1 = elements.get(0);
    item1.getLocation().then((location) => {
      var startLocation = {
        x: location.x + 300,
        y: location.y + 50
      }
      var newLocation = {
        x: startLocation.x - 100,
        y: startLocation.y
      };
      browser.driver.touchActions()
                    .tapAndHold(startLocation)
                    .move(newLocation)
                    .perform();
    }
    

    So I think you should use touchActions() instead of actions()

    By the way, does on-tap work? Why not using ng-click?

    0 讨论(0)
  • 2021-01-15 18:19

    There is another solution if the above solution of using tapAndHold is not working for anyone. You can use also use flickElement.

    const offset = {x: -50, y: 0};
    const targetElement = element(by.css(`selector`)); // This should be the element which is visible on your screen and you want to swipe
    await browser.driver.touchActions()
        .flickElement(targetElement, offset, 200)
        .perform();
    

    The above code is to swipe left the element. To swipe right you can use:

    const offset = {x: 50, y: 0};
    
    0 讨论(0)
提交回复
热议问题