一. appium自带的Chromedriver版本和设备Android System Webview版本不一致的问题
报错信息:
io.appium.java_client.NoSuchContextException: An unknown server-side error occurred while processing the command. Original error: Failed to start Chromedriver session: An unknown server-side error occurred while processing the command. Original error: unknown error: unable to discover open pages
(Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.17134 x86_64)
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'LAPTOP-4E93JJO7', ip: '192.168.1.16', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_191'
Driver info: appium.ctyun.base.AndroidTestBase.AndroidCtyunDriver
Capabilities {appActivity: com.ctg.itrdc.ecloud.module..., appPackage: com.ctg.itrdc.ecloud.test, appiumVersion: 1.8.1, automationName: uiautomator2, browserName: , databaseEnabled: false, desired: {appActivity: com.ctg.itrdc.ecloud.module..., appPackage: com.ctg.itrdc.ecloud.test, appiumVersion: 1.8.1, automationName: uiautomator2, browserName: , deviceName: XEGNW18315004797, locationContextEnabled: true, noReset: true, noSign: true, platformName: android, platformVersion: 8.0.0, resetKeyboard: true, unicodeKeyboard: true}, deviceApiLevel: 26, deviceManufacturer: HUAWEI, deviceModel: FLA-AL10, deviceName: XEGNW18315004797, deviceScreenDensity: 540, deviceScreenSize: 1080x2160, deviceUDID: XEGNW18315004797, javascriptEnabled: true, locationContextEnabled: true, networkConnectionEnabled: true, noReset: true, noSign: true, pixelRatio: 3.375, platform: LINUX, platformName: Android, platformVersion: 8.0.0, resetKeyboard: true, statBarHeight: 72, takesScreenshot: true, unicodeKeyboard: true, viewportRect: {height: 1966, left: 0, top: 72, width: 1080}, warnings: {}, webStorageEnabled: false}
Session ID: 31ca153d-22d7-41a8-9171-7517a9747a34
关键词:
chromedriver=2.40.565498 查看了手机的webview版本为: 66.0
版本对应表
chromedriver版本 | 支持的Chrome版本 |
---|---|
v2.37 | v64-66 |
v2.36 | v63-65 |
v2.35 | v62-64 |
v2.34 | v61-63 |
v2.33 | v60-62 |
v2.32 | v59-61 |
v2.31 | v58-60 |
v2.30 | v58-60 |
v2.29 | v56-58 |
v2.28 | v55-57 |
v2.27 | v54-56 |
v2.26 | v53-55 |
v2.25 | v53-55 |
v2.24 | v52-54 |
v2.23 | v51-53 |
v2.22 | v49-52 |
v2.21 | v46-50 |
v2.20 | v43-48 |
v2.19 | v43-47 |
v2.18 | v43-46 |
v2.17 | v42-43 |
v2.13 | v42-45 |
v2.15 | v40-43 |
chromedriver下载地址http://chromedriver.storage.googleapis.com/index.html
appium存放chromedriver的路径
../node_modules/appium/node_modules/appium-chromedriver/chromedriver/win
下载对应的版本进行覆盖
---------------------------出现该问题很蛋疼,如果appium更新的话就会自动覆盖之前的chromedriver,大家切记别随意更新版本---------------------
二. 如何获取手机上弹出的toast内容
获取toast,必须使用appium的新的元素定位方式: uiautomator2 , 默认是uiautomator
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME,"uiautomator2");
但是你发现设置了上面的属性后,启动手机直接报错,无法启动appium了。
原因:没有安卓uiautomator2-driver
安装方式:(FQ可以用npm ,否则用国内镜像cnpm)
cnpm install appium-uiautomator2-driver
安装好了之后, 启动程序会提示手机安装uiautomator2 的server ,安装完之后可以正常启动你测试的APP了。
附上获取toast的代码
public static String getToast() {
WebDriverWait wait = new WebDriverWait(driver, 10, 10);
WebElement target = wait.until(
ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@class='android.widget.Toast']")));
if (target != null) {
return target.getText();
} else
Log.logInfo("Can't get toast !!");
return null;
}