From 696e3c66730cd5e22bdfa85a119c1465178d5129 Mon Sep 17 00:00:00 2001 From: dimaprokop Date: Tue, 17 Oct 2017 09:54:59 +0300 Subject: [PATCH] refactoring swipes --- .../colibri/ui/steps/general/SwipeSteps.java | 69 +++++++------------ 1 file changed, 26 insertions(+), 43 deletions(-) diff --git a/src/main/java/ru/colibri/ui/steps/general/SwipeSteps.java b/src/main/java/ru/colibri/ui/steps/general/SwipeSteps.java index d29ab2a..04f502b 100644 --- a/src/main/java/ru/colibri/ui/steps/general/SwipeSteps.java +++ b/src/main/java/ru/colibri/ui/steps/general/SwipeSteps.java @@ -1,43 +1,26 @@ -//package ru.colibri.ui.steps.general; -// -//import io.appium.java_client.MobileElement; -//import io.appium.java_client.SwipeElementDirection; -//import org.jbehave.core.annotations.Named; -//import org.jbehave.core.annotations.When; -//import org.openqa.selenium.WebElement; -//import org.springframework.stereotype.Component; -//import ru.colibri.ui.core.steps.AbsSteps; -//import ru.yandex.qatools.allure.annotations.Step; -// -//@Component -//public class SwipeSteps extends AbsSteps { -// private static final int SWIPE_DURATION = 2000; -// -// @Step -// @When("вертикальный свайп \"$elementName\" вниз") -// public void swipingDown(@Named("$elementName") String elementName) { -// WebElement webElement = getWebElementByName(elementName); -// ((MobileElement) webElement).swipe(SwipeElementDirection.DOWN, 1, 1, SWIPE_DURATION); -// } -// -// @Step -// @When("вертикальный свайп \"$elementName\" вверх") -// public void swipingUp(@Named("$elementName") String elementName) { -// WebElement webElement = getWebElementByName(elementName); -// ((MobileElement) webElement).swipe(SwipeElementDirection.UP, 1, 1, SWIPE_DURATION); -// } -// -// @Step -// @When("горизонтальный свайп \"$elementName\" вправо") -// public void swipingRight(@Named("$elementName") String elementName) { -// WebElement webElement = getWebElementByName(elementName); -// ((MobileElement) webElement).swipe(SwipeElementDirection.RIGHT, 1, 1, SWIPE_DURATION); -// } -// -// @Step -// @When("горизонтальный свайп \"$elementName\" влево") -// public void swipingLeft(@Named("$elementName") String elementName) { -// WebElement webElement = getWebElementByName(elementName); -// ((MobileElement) webElement).swipe(SwipeElementDirection.LEFT, 1, 1, SWIPE_DURATION); -// } -//} \ No newline at end of file +package ru.colibri.ui.steps.general; + +import io.appium.java_client.TouchAction; +import org.openqa.selenium.WebElement; +import org.springframework.stereotype.Component; +import ru.colibri.ui.core.steps.AbsSteps; + +import java.time.Duration; + +@Component +public class SwipeSteps extends AbsSteps { + + + protected void verticalSwipe(String elementName, int swipeLength) { + WebElement webElement = getWebElementByName(elementName); + new TouchAction(driver).press(webElement).moveTo(0, swipeLength).release().perform(); + + } + + protected void horizontalSwip(String elementName, int swipeLength, int duration) { + WebElement webElement = getWebElementByName(elementName); + new TouchAction(driver).press(webElement).waitAction(Duration.ofSeconds(duration)). + moveTo(swipeLength, 0).release().perform(); + } + +} \ No newline at end of file