当前位置: 首页 > 知识库问答 >
问题:

TouchAction刷不工作的iOS模拟器-Appium Java

赫连棋
2023-03-14

我试图在iOS模拟器上用Appium 1.11.1做一些UITests,但Swipe不起作用

驱动程序连接看起来很好。。我可以测试driver.reloadApp(),它正在工作

我尝试了在堆栈溢出中找到的一些关于TouchActions的示例

public static void swipeHorizontal(MobileDriver driver, double startPercentage, double finalPercentage, int duration) throws Exception {
      Dimension size = driver.manage().window().getSize();
      int height =  (int) (size.height/2);
      int startPoint =  (int) (size.getWidth() * startPercentage);
      int endPoint =  (int) (size.getWidth() * finalPercentage);
      new TouchAction(driver).press(new PointOption().point(height, startPoint)).waitAction(new WaitOptions().waitOptions(Duration.ofMillis(duration))).moveTo(new PointOption().point(height, endPoint)).release().perform();
    }

@Test.....{
      swipeHorizontal(driver, 0.80, 0.20, 5);
}

测试通过了,但屏幕上什么也没发生

我也试过这个方法https://stackoverflow.com/a/50388361/7406696 我的模拟器不起作用

我的pom.xml是这个

<dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.appium</groupId>
        <artifactId>java-client</artifactId>
        <version>5.0.4</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.141.59</version>
    </dependency>
    <dependency>
        <groupId>io.appium</groupId>
        <artifactId>java-client</artifactId>
        <version>7.0.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.7</version>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.14.3</version>
        <scope>test</scope>
    </dependency>
 </dependencies>

共有1个答案

祝允晨
2023-03-14

最后,删除waitOptions并从press()更改为LongPress()

public static void swipeHorizontal(AppiumDriver driver, double startPercentage, double finalPercentage) throws Exception {
      Dimension size = driver.manage().window().getSize();
      int anchor =  (int) (size.height/2);
      int startPoint =  (int) (size.width * startPercentage);
      int endPoint =  (int) (size.width * finalPercentage);
      new TouchAction(driver).longPress(new PointOption().point(startPoint, anchor)).moveTo(new PointOption().point(endPoint, anchor)).release().perform();
  }


@Test..... {
      swipeHorizontal(driver, 0.80, 0.20);  
}
 类似资料:
  • 一旦我调整了应用程序图标的大小,我试图重新运行应用程序,我得到了这个错误,模拟器不会启动。我在Android模拟器上试了一下,效果不错。不确定我做错了什么。 来自油库:[✓] Flutter(Channel stable,v1.9.1 hotfix.6,在Mac OS X 10.15.1 19B88上,语言环境 恩-美国) [✓] Android工具链 - 针对Android设备开发(Androi

  • 这里有一个移动自动化的新人。。我正在尝试以下代码,使用触摸操作执行滑动操作以导航到第2页,但滑动不起作用。 其他一切都很好。由于刷卡不起作用,我为两个页面检索相同的内容。请纠正我哪里错了?

  • 你好,我正面临一个问题与世博反应本地。每当我试图启动iOS模拟器。我得到这个错误: 世博会结果截图 我的NPM版本是6.7。0本机cli:2.0。1:0.57。1世博会版本2.11。9 此外,我还确保我在Xcode上的命令行工具是完全由Xcode命令行工具设置的 最后,我还尝试运行命令 什么都不管用。。

  • 我使用的是Appium版本1.4.0(draco)和Xcode版本6.4。我无法让刷卡功能在我的自动测试中工作。iOS的模拟器设备是iPad air。任何有用的帖子将不胜感激。

  • 我在localhost中有一个wamp服务器。我试图从我的android应用程序发出http请求。但我不能把它弄对。许多人说10.0.2.2:8080将从emulator指向localhost。所以我试着从emulator在web浏览器中打开它。我输入的url是“10.0.2.2/cifi/test.php”。但emulator弹出错误为“网络:连接超时” 需要说明:如何使我的wamp服务器在本地

  • 这段代码在模拟器iphone 8 Plus上按预期运行,但当运行到iphone 8 Plus或iphone 6上时,这段控制台日志将失败,导致这种奇怪的结果。Mac和两款iPhone都运行当前的操作系统版本。 urlString为http://museum-dev.williams.edu:3003/id?labid=E8EE71C6F5822