1

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 and make a button visible and click on that button

it('should delete a product',function(){
        browser.driver.actions().mouseMove({x:-50,y:0}).perform();
browser.sleep(3000);
            });

could someone help me to swipe the delete button is

<ion-option-button ng-show="!userService.isOffline" class="button button-assertive button disable-user-behavior" on-tap="deleteLead(leads)">Delete</ion-option-button>
Yokesh Varadhan
  • 1,636
  • 4
  • 21
  • 47
  • Is the swipe action working successfully and you are not able to perform click action on the element? Or is it that you are not able to perform both swipe and click actions? – giri-sh Oct 19 '15 at 08:18
  • ya i could not perform swipe action my terminal shows success but in my browser i could not see any swipe action performed by protractor – Yokesh Varadhan Oct 19 '15 at 09:15

2 Answers2

1

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?

Boland
  • 1,531
  • 1
  • 14
  • 42
  • What platform are you running the above test on? Is that in the IOS simulator, or just in the regular Chrome browser? I keep getting "method had not yet been implemented" errors when I try and use this... – AlexZ May 23 '16 at 09:02
  • Also, what versions of Protractor/Selenium Server/ChromeDriver are you using? – AlexZ May 23 '16 at 09:08
  • It is not working for ios simulator, getting error tapAndHold method not yet been implemented – ygsankar Nov 21 '18 at 13:33
1

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};
Junaid Nazir
  • 173
  • 1
  • 11