gpt4 book ai didi

Appium 6.1.0 TouchActions 与 TouchAction

转载 作者:行者123 更新时间:2023-12-04 18:55:59 25 4
gpt4 key购买 nike

我正在寻找使用最新(此时)Appium Java 客户端 6.1.0 创建 Tap/Swipe/Drag 等事件的“正确”或“最新”方式。
我在 Appium 站点( Tap using TouchActionsTouch using TouchAction )中看到了不同的文档,并且没有引用我应该使用哪个(哪个将被弃用?)。

new TouchAction(driver)
.tap(tapOptions()
.withElement(element(myElement)))
.perform();

new TouchActions(driver)
.singleTap(myElement)
.perform();

看起来TouchActions是Selenium项目的一部分,TouchAction是Appium的一部分,但这并不代表Appium就是正确的方式。

p.s 我目前正在使用适用于 Android/iOS 的 Chrome/Safari 浏览器进行测试,但这并不意味着我不需要对代码的 native 应用程序支持。

感谢您的时间

最佳答案

您想使用 TouchAction (Appium)。

下面是我的代码的一部分。第一个是将坐标作为参数的通用滚动函数。您通常不会直接调用该函数,它应该被其他函数调用,例如我在它下面包含的 scrollDown 函数,它计算坐标并调用通用滚动函数。

希望这可以帮助。

/**
* This method scrolls based upon the passed parameters
* @author Bill Hileman
* @param int startx - the starting x position
* @param int starty - the starting y position
* @param int endx - the ending x position
* @param int endy - the ending y position
*/
@SuppressWarnings("rawtypes")
public void scroll(int startx, int starty, int endx, int endy) {

TouchAction touchAction = new TouchAction(driver);

touchAction.longPress(PointOption.point(startx, starty))
.moveTo(PointOption.point(endx, endy))
.release()
.perform();

}

/**
* This method does a swipe upwards
* @author Bill Hileman
*/
public void scrollDown() {

//The viewing size of the device
Dimension size = driver.manage().window().getSize();

//Starting y location set to 80% of the height (near bottom)
int starty = (int) (size.height * 0.80);
//Ending y location set to 20% of the height (near top)
int endy = (int) (size.height * 0.20);
//x position set to mid-screen horizontally
int startx = (int) size.width / 2;

scroll(startx, starty, startx, endy);

}

关于Appium 6.1.0 TouchActions 与 TouchAction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53173642/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com