最近在写 Java appium case,现在大部分自动化脚本都很稳定了,但是在跑脚本过程中花费时间较长,大概跑 5 个多小时,知道 appiium 同时支持多个手机,自己也想过用多线程,在网上搜了半天没有发现如何做多个手机同时运行,所以就写了这个帖子,希望大家帮忙解决一下
如下是 启动代码:
public static AppiumDriver driver;
public static String configXYPath = "src/config/configXY.xml";
public static String runSettingPath = "src/config/runSetting.xml";
@BeforeSuite
public static void SetUp() {
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "apps");
File app = new File(appDir, "zm4.4.0.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName", "4df04b421d093033");
capabilities.setCapability("platformVersion", "4.3");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "com.gaiay.mobilecard");
capabilities.setCapability("appActivity",
"com.gaiay.businesscard.StartPage");
capabilities.setCapability("unicodeKeyboard", "True");
capabilities.setCapability("resetKeyboard", "True");
try {
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),
capabilities);
Thread.sleep(8000);
GetData.Screenshot(driver, "C:\\photo\\", "登陆第一页");
for (int i = 0; i < 3; i++) {
int Sx = GetData.GetXmlConfig(
GetData.GetXmlSetting("phoneType"), "start", "startX");
int Sy = GetData.GetXmlConfig(
GetData.GetXmlSetting("phoneType"), "start", "startY");
int Ex = GetData.GetXmlConfig(
GetData.GetXmlSetting("phoneType"), "start", "endX");
int Ey = GetData.GetXmlConfig(
GetData.GetXmlSetting("phoneType"), "start", "endY");
driver.swipe(Sx, Sy, Ex, Ey, 2000);
Thread.sleep(1000);
}
Login.definedEle.GYWaitFindEle(driver,
By.id("com.gaiay.mobilecard:id/mTvOpen")).click();
Thread.sleep(5000);
} catch (Exception e) {
e.printStackTrace();
}
}