【问题标题】:TouchAction to swipe not working iOS Simulator - Appium JavaTouchAction 滑动不工作 iOS 模拟器 - Appium Java
【发布时间】:2019-08-04 06:50:29
【问题描述】:

我正在尝试在 iOS 模拟器上使用 Appium 1.11.1 进行一些 UITests 并且 Swipe 不起作用

driver connexion 看起来不错。我可以测试 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>

【问题讨论】:

    标签: selenium appium appium-ios xcuitest


    【解决方案1】:

    终于删除了 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);  
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-17
      • 1970-01-01
      • 1970-01-01
      • 2019-04-09
      • 2016-12-17
      • 2011-11-13
      • 2019-09-25
      • 2021-12-17
      相关资源
      最近更新 更多