AppiumDriver<WebElement> driver; File classpathRoot = new File(System.getProperty("user.dir")); File appDir = new File(classpathRoot, "app"); // 微信程序 File app = new File(appDir, "xxxx.sp1_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的主包名和主类名 capabilities.setCapability("appPackage", "com.sf.module.edms"); capabilities.setCapability("appActivity", "com.sf.module.edms.hibox.ui.entry.EntryActivity"); //启动 try { driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"),capabilities); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); }
多次运行,就会出错
01:5555","fullReset":"false","appActivity":"com.sf.module.edms.hibox.ui.entry.EntryActivity","newCommandTimeout":24000,"platformVersion":"4.4","browserName":"","udid":"192.168.56.101:5555","platformName":"Android","device":"selendroid"}}
> info: Client User-Agent string: Apache-HttpClient/4.5.1 (Java/1.8.0_45)
> error: Failed to start an Appium session, err was: Error: Requested a new session but one was in progress
增加语句
driver.closeApp();
driver.quit();
并且在appium里面设置
tool ->general settings- > select overriding existing sessions
在一个测试任务中,多次启动app driver 都能正常启动