appium - Appium 6.1.0 TouchAction 与 TouchAction
问题描述
我正在寻找使用最新(此时)Appium Java-client 6.1.0 来创建 Tap/Swipe/Drag 等事件的“正确”或“最新”方式。我在 Appium 网站上看到了不同的文档(使用 TouchActions 进行点击,使用 TouchAction进行触摸),并且没有参考我应该使用哪个(以及哪些将被弃用?)。
new TouchAction(driver)
.tap(tapOptions()
.withElement(element(myElement)))
.perform();
new TouchActions(driver)
.singleTap(myElement)
.perform();
看起来 TouchActions 是 Selenium 项目的一部分,而 TouchAction 是 Appium 的一部分,但这并不意味着 Appium 是正确的方法。
ps 我目前正在使用适用于 Android/iOS 的 Chrome/Safari 浏览器进行测试,但这并不意味着我不需要本机应用程序支持代码。
感谢您的时间
解决方案
您想使用 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);
}
推荐阅读
- c# - DownloadText() 和 DownloadTextAsync() 有什么区别?
- apiconnect-test-monitor - API Connect 测试和监控桌面客户端
- asp.net-mvc - OWIN SSO 和 error=access_denied 的外部登录信息为空
- mysql - 为什么我不能在 mysql 中使用 join 和正则表达式?
- arm - 为什么存储在 NMI Vector 地址中的 NMI 函数地址以 ARM 皮质中的位 1 结尾?
- javascript - 如何在javascript中监听mousdown事件 - react-materialize?
- codeigniter - 如何使用 Codeigniter 框架上传图像?
- c# - 如何在 Linq 中将 select 和 group by 子句与条件 where 结合起来
- python - 包装 Python cProfile runctx API 以参数化任何地方的运行
- r - ggplot 省略了缺少数据的日期