【问题标题】:How to automate swipe gestures for iOS mobile app using iOS simulator in java?java - 如何使用Java中的iOS模拟器为iOS移动应用程序自动滑动手势?
【发布时间】:2023-03-03 02:49:01
【问题描述】:
  1. 我需要在 iOS 移动应用程序中为两侧(从右到左和从左到右)自动滑动手势。

  2. 我正在使用 appium 1.4.8 版本,iOS 模拟器 6 和平台版本为 8.3。

  3. 我正在使用 java 语言编写测试用例。

  4. 我已经尝试使用下面的滑动手势编码。但是,滑动操作不会发生在我身上。

 public void swipeLeftToRight(AppiumDriver driver) {
     Dimension size = driver.manage().window().getSize();
     int endx = (int) (size.width * 0.8);
     int startx = (int) (size.width * 0.20);
     int starty = size.height / 2;

     driver.swipe(startx, starty, endx, starty, 1000);
 }

 public void swipeRightToLeft(AppiumDriver driver) {
     Dimension size = driver.manage().window().getSize();
     int startx = (int) (size.width * 0.8);
     int endx = (int) (size.width * 0.10);
     int starty = size.height / 2;

     driver.swipe(startx, starty, endx, starty, 1000);
 }

【问题讨论】:

    标签: java ios appium mobile-application swipe-gesture


    【解决方案1】:

    您也可以使用 TouchAction 类来执行此操作。试试这个:

    TouchAction action = new TouchAction(driver).longPress(longPress).moveTo().release();
    action.perform();
    

    【讨论】:

    【解决方案2】:

    对我来说,下面的代码适用于案例“在 ios 真实设备上从左向右滑动” 我认为只需将“方向”值更改为“左”就足以用于案例“滑动” 从右到左" P.s:如果您使用的是 webwiev 应用程序,那么在应用以下代码之前,您应该切换到原生视图 希望对你有帮助

    JavascriptExecutor js = (JavascriptExecutor) driver;
     HashMap<String, String> scrollObject = new HashMap<String, String>();
     scrollObject.put("direction", "right");
     WebElement element = ((IOSDriver) device.getDriver()).findElementById("id");
     scrollObject.put("element", ((RemoteWebElement) element).getId());
     js.executeScript("mobile: swipe", scrollObject);
    

    【讨论】:

      猜你喜欢
      • 2017-02-06
      • 2016-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-18
      • 1970-01-01
      • 2019-08-04
      • 2011-05-15
      相关资源
      最近更新 更多