一. 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, 1080}, warnings: {}, webStorageEnabled: false}
Session ID: 31ca153d-22d7-41a8-9171-7517a9747a34
关键词:
chromedriver=2.40.565498 查看了手机的webview版本为: 66.0
版本对应表: http://appium.io/docs/en/writing-running-appium/web/chromedriver/#chromedriverchrome-compatibility
appium存放chromedriver的路径
http://appium.io/docs/en/writing-running-appium/web/chromedriver/#chromedriverchrome-compatibility
chromedriver下载地址http://chromedriver.storage.googleapis.com/index.html
../node_modules/appium/node_modules/appium-chromedriver/chromedriver/win
下载对应的版本进行覆盖(这里注意,下载的版本尽量高一点点,例如你webview版本是66.0.XXX 至少下载2.38的版本, 2.37可能不匹配你的版本)
---------------------------出现该问题很蛋疼,如果appium更新的话就会自动覆盖之前的chromedriver,大家切记别随意更新版本---------------------
二. 如何获取手机上弹出的toast内容
获取toast,必须使用appium的新的元素定位方式: uiautomator2 , 默认是uiautomator
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME,"uiautomator2");
但是你发现设置了上面的属性后,启动手机直接报错,无法启动appium了。
原因:没有安卓uiautomator2-driver
安装方式:(翻墙可以用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;
}