一台机器同时运行多个appium实例
测试需要同时在多个android设备上运行,就需要启动多个appium
第一台是运行微信:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName", "c4072fb8090b");
capabilities.setCapability("udid", "c4072fb8090b");
//设置每次运行不重新启动被测试app
capabilities.setCapability("noReset","true");
capabilities.setCapability("fullReset","false");
//设置安卓系统版本
capabilities.setCapability("platformVersion", "4.4");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("device", "selendroid");
capabilities.setCapability("app", app.getAbsolutePath());
String abc = app.getAbsolutePath();
//设置app的主包名和主类名 微信程序包名和activity 名
capabilities.setCapability("appPackage", "com.tencent.mm");
capabilities.setCapability("appActivity", "com.tencent.mm.ui.LauncherUI");
//启动
try {
driver = new AndroidDriver(new URL("http://127.0.0.1:4725/wd/hub"),capabilities);
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName", "c4072fb8090b");
capabilities.setCapability("udid", "c4072fb8090b");
//设置每次运行不重新启动被测试app
capabilities.setCapability("noReset","true");
capabilities.setCapability("fullReset","false");
//设置安卓系统版本
capabilities.setCapability("platformVersion", "4.4");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("device", "selendroid");
capabilities.setCapability("app", app.getAbsolutePath());
String abc = app.getAbsolutePath();
//设置app的主包名和主类名 微信程序包名和activity 名
capabilities.setCapability("appPackage", "com.tencent.mm");
capabilities.setCapability("appActivity", "com.tencent.mm.ui.LauncherUI");
//启动
try {
driver = new AndroidDriver(new URL("http://127.0.0.1:4725/wd/hub"),capabilities);
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
第二台是测试机配置:
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "app");
// 微信程序
File app = new File(appDir, "xxxx_xxx_test2.apk");
File appDir = new File(classpathRoot, "app");
// 微信程序
File app = new File(appDir, "xxxx_xxx_test2.apk");
//设置自动化相关参数
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName", "192.168.56.101:5555");
capabilities.setCapability("udid", "192.168.56.101:5555");
//设置每次运行不重新启动被测试app
capabilities.setCapability("noReset","true");
capabilities.setCapability("fullReset","false");
//设置安卓系统版本
capabilities.setCapability("platformVersion", "4.4");
capabilities.setCapability("platformName", "Android");
// session 延迟时间
capabilities.setCapability("newCommandTimeout",24000);
capabilities.setCapability("device", "selendroid");
capabilities.setCapability("app", app.getAbsolutePath());
String abc = app.getAbsolutePath();
//设置app的主包名和主类名 微信程序包名和activity 名
capabilities.setCapability("appPackage", "com.xx.xx");
capabilities.setCapability("appActivity", "com.xx.xx.EntryActivity");
//启动
try {
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName", "192.168.56.101:5555");
capabilities.setCapability("udid", "192.168.56.101:5555");
//设置每次运行不重新启动被测试app
capabilities.setCapability("noReset","true");
capabilities.setCapability("fullReset","false");
//设置安卓系统版本
capabilities.setCapability("platformVersion", "4.4");
capabilities.setCapability("platformName", "Android");
// session 延迟时间
capabilities.setCapability("newCommandTimeout",24000);
capabilities.setCapability("device", "selendroid");
capabilities.setCapability("app", app.getAbsolutePath());
String abc = app.getAbsolutePath();
//设置app的主包名和主类名 微信程序包名和activity 名
capabilities.setCapability("appPackage", "com.xx.xx");
capabilities.setCapability("appActivity", "com.xx.xx.EntryActivity");
//启动
try {
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
主要是要加一条配置:capabilities.setCapability("udid", "192.168.56.101:5555");
启动多个appium ,设置不同的端口号,就可以同时运行多个appium driver了。