简体   繁体   English

如何使用Java中的iOS模拟器自动为iOS移动应用程序滑动手势?

[英]How to automate swipe gestures for iOS mobile app using iOS simulator in java?

  1. I need to automate swipe gesture for both side(Right To Left and Left to Right) in iOS mobile app. 我需要在iOS移动应用程序中自动进行两侧(从右到左和从左到右)的滑动手势。

  2. I am using appium version 1.4.8 , iOS simulator 6 and platform version as 8.3. 我正在使用appium版本1.4.8,iOS模拟器6和平台版本8.3。

  3. I am writing test cases using java language. 我正在使用Java语言编写测试用例。

  4. I have tried with below coding for swipe gestures. 我已经尝试过使用下面的滑动手势编码。 But, the swipe action doesn't happens for me. 但是,滑动动作对我而言不会发生。

  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); } 

You can also use TouchAction class to perform this operation. 您还可以使用TouchAction类执行此操作。 Try this: 尝试这个:

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

For me below code worked for case "swipe from left to right on ios real device" I think just changing the "direction" value as "left" will be enough for case "swipe from right to left" Ps: If you are using webwiev application, then before applying below code, you should switch to native view I hope it helps 对于我来说,下面的代码适用于“在iOS真实设备上从左向右滑动”的情况下,我认为只需将“ direction”值更改为“ left”就足以解决“从右向左滑动”的情况。ps:如果您使用的是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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM