Appium 6.1.0 TouchActions 与 TouchAction

Leo*_*rov 5 appium appium-ios appium-android

我正在寻找使用最新(此时)Appium Java 客户端 6.1.0 创建 Tap/Swipe/Drag 等事件的“正确”或“最新”方式。我看到了不同的单证在Appium网站(点击使用TouchActions触摸使用TouchAction),并没有引用作为我应该使用(和将要过时?)。

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

new TouchActions(driver)
    .singleTap(myElement)
    .perform();
Run Code Online (Sandbox Code Playgroud)

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

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

感谢您的时间

Was*_*mla 4

使用类的最新方法TouchAction是使用AndroidTouchAction类而不是TouchAction类,因为类现在已成为通用的。这就是您@SuppressWarnings("rawtypes")在最后一个答案中看到使用的原因。

这是在 6.1.0 中点击元素的方式

对于安卓:

AndroidTouchAction touch = new AndroidTouchAction (driver);
touch.tap (TapOptions.tapOptions ()
    .withElement (ElementOption.element (e)))
  .perform ();
Run Code Online (Sandbox Code Playgroud)

对于 iOS:

IOSTouchAction touch = new IOSTouchAction (driver);
touch.tap (TapOptions.tapOptions ()
    .withElement (ElementOption.element (e)))
  .perform ();
Run Code Online (Sandbox Code Playgroud)