Подскажите как можно реализовать swipe на iOS по средствам: Appium, java, selenium.

Пробывал через TouchAction и driver.swipe();. TouchAction отрабатывает, но выбирает не корректный элемент для свайпа, а driver.swipe(); совсем не работает.

А можете показать код. Как именно использовали TouchAction и swipe и вывод консоли с последствиями?

TouchAction:

driver.findElementByXPath("xpath");
TouchAction touchAction4 = new TouchAction(driver);
touchAction4.press(100,0).moveTo(100,0).release();
driver.performTouchAction(touchAction4);

Консоль:

[HTTP] --> POST /wd/hub/session/323bec73-2077-48db-bb65-ecf92cb7d99f/touch/perform {"actions":[{"action":"press","options":{"x":100,"y":0}},{"action":"moveTo","options":{"x":100,"y":0}},{"action":"release","options":{}}]}
[MJSONWP] Calling AppiumDriver.performTouch() with args: [[{"action":"press","options":{"x":100,"y":0}},{"action":"moveTo","options":{"x":100,"y":0}},{"action":"release","options":{}}],"323bec73-2077-48db-bb65-ecf92cb7d99f"]
[XCUITest] Executing command 'performTouch'
[XCUITest] Received the following touch action: press(options={"x":100,"y":0})-moveTo(options={"x":100,"y":0})-release(options={})
[XCUITest] Found matching gesture: scroll
[JSONWP Proxy] Proxying [POST /wda/dragfromtoforduration] to [POST http://localhost:8100/session/C8C82395-FAA0-49CB-B502-EB45F904CA59/wda/dragfromtoforduration] with body: {"fromX":100,"fromY":0,"toX":200,"toY":0,"duration":0}
[JSONWP Proxy] Got response with status 200: {"value":{},"sessionId":"C8C82395-FAA0-49CB-B502-EB45F904CA59","status":0}
[MJSONWP] Responding to client with driver.performTouch() result: null

Swipe:

driver.findElementByXPath("xpath");
driver.swipe(0,0,233,0,2000);

Swipe консоль:

[HTTP] --> POST /wd/hub/session/9afd628f-ef0b-420f-b059-dd4c5419eccc/touch/perform {"actions":[{"action":"press","options":{"x":0,"y":0}},{"action":"wait","options":{"ms":2000}},{"action":"moveTo","options":{"x":233,"y":0}},{"action":"release","options":{}}]}
[MJSONWP] Calling AppiumDriver.performTouch() with args: [[{"action":"press","options":{"x":0,"y":0}},{"action":"wait","options":{"ms":2000}},{"action":"moveTo","options":{"x":233,"y":0}},{"action":"release","options":{}}],"9afd628f-ef0b-420f-b059-dd4c5419eccc"]
[XCUITest] Executing command 'performTouch'
[XCUITest] Received the following touch action: press(options={"x":0,"y":0})-wait(options={"ms":2000})-moveTo(options={"x":233,"y":0})-release(options={})
[XCUITest] Found matching gesture: drag
[JSONWP Proxy] Proxying [POST /wda/dragfromtoforduration] to [POST http://localhost:8100/session/A046D568-C6FE-4726-8E72-A538F6AA6CD5/wda/dragfromtoforduration] with body: {"fromX":0,"fromY":0,"toX":233,"toY":0,"duration":2}
[JSONWP Proxy] Got response with status 200: {"value":{},"sessionId":"A046D568-C6FE-4726-8E72-A538F6AA6CD5","status":0}
[MJSONWP] Responding to client with driver.performTouch() result: null

press(100,0) - здесь задаете стартовые координаты
moveTo(100,0) - здесь конечные
по факту, одна и та же точка, должен быть вектор…

У Вас есть какой-то пример для свайпа конкретного элемента таблицы (p.s. Мне нужно удалить элемент в таблице после свайпа)

Мимо - moveTo на iOS это оффсет.

1 лайк

Когда-то давно мы делали так:

public void swipeCardLeft(int cardIndex) {
   IOSElement element = (IOSElement)  find(MobileBy.IosUIAutomation(
           ".scrollViews()[0].tableViews()[" + cardIndex + "]"));
   element.swipe(SwipeElementDirection.LEFT, 500);
}

Уже так “не можно” :slight_smile:

а как можно?)

Нашел решение здесь: https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/ios-xctest-mobile-gestures.md

Если тема еще актуальная, то я у себе на проекте так реализовала:

public void swipe() throws InterruptedException {
Dimension size = driver.manage().window().getSize();
int startx = (int) (size.width * 0.90);
int endx = (int) (size.width * 0.10);
int starty = size.height / 2;
driver.swipe(startx, starty, endx, starty, 1000);
// Thread.sleep(1500);
}

1 лайк