在 appium java 客户端 7.0.0 中使用坐标水平滑动
Horizontal swipe using co-ordinates in appium java client 7.0.0
我正在尝试在 appium android - java-client 7.0.0 中水平滑动。没用
//Horizontal Swipe by percentages
public void horizontalSwipeByPercentages(double startPercentage, double endPercentage, double anchorPercentage) {
Dimension size = driver.manage().window().getSize();
int anchor = (int) (size.height * anchorPercentage);
int startPoint = (int) (size.width * startPercentage);
int endPoint = (int) (size.width * endPercentage);
new TouchAction(driver)
.press(PointOption.point(endPoint, startPoint))
.waitAction(new WaitOptions().withDuration(Duration.ofMillis(600)))
.moveTo(PointOption.point(startPoint, endPoint))
.release().perform();
}
在我的测试中调用如下。
horizontalSwipeByPercentages(0.2,0.5,0.5);
通过这样做,代码正在拉动通知栏
试试这个也许可以解决您的问题。
new TouchAction(driver)
.longPress(start_x,start_y)
.waitAction()
.moveTo(PointOption.point(end_x,end_y)
.release().perform();
}
@akbar,来自 experitest example provided 你可以试试吗
TouchAction ta = new TouchAction(driver);
ta.press(434, 468).waitAction(Duration.ofMillis(1000)).moveTo(471, 312).release().perform();
====================================
或者(方法 #2)
考虑 this example
public static void swipeHorizontal(AppiumDriver driver, double startPercentage, double finalPercentage, double anchorPercentage, int duration) throws Exception {
Dimension size = driver.manage().window().getSize();
int anchor = (int) (size.height * anchorPercentage);
int startPoint = (int) (size.width * startPercentage);
int endPoint = (int) (size.width * finalPercentage);
new TouchAction(driver).press(startPoint, anchor)
.waitAction(duration)
.moveTo(endPoint, anchor)
.release()
.perform();
//In documentation they mention moveTo coordinates are relative to initial ones, but thats not happening. When it does we need to use the function below
//new TouchAction(driver).press(startPoint, anchor).waitAction(duration).moveTo(endPoint-startPoint,0).release().perform();
}
用您主题中的值调用它是:
swipeHorizontal(driver,0.9,0.01,0.5,3000);
注意关于 absolute/relative 值的评论
===================================
还有另一种方法(方法#3)
Appium 1.9.1 版本和客户端升级到 7.0.0 swipe 使用以下代码工作(垂直滑动。对于水平滑动 - 将 getHeight()
更改为 getWidth()
来自 'dimensions' ):
TouchAction action = new TouchAction(driver);
PointOption p1= new PointOption();
Dimension dimensions = driver.manage().window().getSize();
Double screenHeightStart = dimensions.getHeight() * 0.5;
int h1 = screenHeightStart.intValue();
Double screenHeightEnd = dimensions.getHeight() * 0.2;
int h2 = screenHeightEnd.intValue();
action.press(PointOption.point(0,h1))
.waitAction(new WaitOptions().withDuration(Duration.ofMillis(600)))
.moveTo(PointOption.point(0, h2))
.release()
.perform();
这对我来说非常有效。
希望这有帮助,
此致,
尤金
我正在尝试在 appium android - java-client 7.0.0 中水平滑动。没用
//Horizontal Swipe by percentages
public void horizontalSwipeByPercentages(double startPercentage, double endPercentage, double anchorPercentage) {
Dimension size = driver.manage().window().getSize();
int anchor = (int) (size.height * anchorPercentage);
int startPoint = (int) (size.width * startPercentage);
int endPoint = (int) (size.width * endPercentage);
new TouchAction(driver)
.press(PointOption.point(endPoint, startPoint))
.waitAction(new WaitOptions().withDuration(Duration.ofMillis(600)))
.moveTo(PointOption.point(startPoint, endPoint))
.release().perform();
}
在我的测试中调用如下。 horizontalSwipeByPercentages(0.2,0.5,0.5);
通过这样做,代码正在拉动通知栏
试试这个也许可以解决您的问题。
new TouchAction(driver)
.longPress(start_x,start_y)
.waitAction()
.moveTo(PointOption.point(end_x,end_y)
.release().perform();
}
@akbar,来自 experitest example provided 你可以试试吗
TouchAction ta = new TouchAction(driver);
ta.press(434, 468).waitAction(Duration.ofMillis(1000)).moveTo(471, 312).release().perform();
====================================
或者(方法 #2) 考虑 this example
public static void swipeHorizontal(AppiumDriver driver, double startPercentage, double finalPercentage, double anchorPercentage, int duration) throws Exception {
Dimension size = driver.manage().window().getSize();
int anchor = (int) (size.height * anchorPercentage);
int startPoint = (int) (size.width * startPercentage);
int endPoint = (int) (size.width * finalPercentage);
new TouchAction(driver).press(startPoint, anchor)
.waitAction(duration)
.moveTo(endPoint, anchor)
.release()
.perform();
//In documentation they mention moveTo coordinates are relative to initial ones, but thats not happening. When it does we need to use the function below
//new TouchAction(driver).press(startPoint, anchor).waitAction(duration).moveTo(endPoint-startPoint,0).release().perform();
}
用您主题中的值调用它是:
swipeHorizontal(driver,0.9,0.01,0.5,3000);
注意关于 absolute/relative 值的评论
===================================
还有另一种方法(方法#3)
Appium 1.9.1 版本和客户端升级到 7.0.0 swipe 使用以下代码工作(垂直滑动。对于水平滑动 - 将 getHeight()
更改为 getWidth()
来自 'dimensions' ):
TouchAction action = new TouchAction(driver);
PointOption p1= new PointOption();
Dimension dimensions = driver.manage().window().getSize();
Double screenHeightStart = dimensions.getHeight() * 0.5;
int h1 = screenHeightStart.intValue();
Double screenHeightEnd = dimensions.getHeight() * 0.2;
int h2 = screenHeightEnd.intValue();
action.press(PointOption.point(0,h1))
.waitAction(new WaitOptions().withDuration(Duration.ofMillis(600)))
.moveTo(PointOption.point(0, h2))
.release()
.perform();
这对我来说非常有效。 希望这有帮助,
此致, 尤金