appium +uiautomator2 遇到deviceName can't be blank 提示的解决

行是知之始,知是行之成。这篇文章主要讲述appium +uiautomator2 遇到deviceName can' t be blank 提示的解决相关的知识,希望能为你提供帮助。
为了获取android toast ,需要升级selenium 到 3.4.0 和appium 5.0.0-BETA9 到最新版本,并在启动代码前面追加一行代码:
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.ANDROID_UIAUTOMATOR2);
获取toast 需要在android api   level 在20 及20 以上才能正常工作。
【appium +uiautomator2 遇到deviceName can' t be blank 提示的解决】添加必要的语句后,执行自动化代码,报错:  The desiredCapabilities object was not valid for the following reason(s): deviceName can‘t be blank
org.openqa.selenium.SessionNotCreatedException: A new session could not be created. Details: The desiredCapabilities object was not valid for the following reason(s): deviceName can‘t be blank, (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: ‘3.3.0‘, revision: ‘b526bd5b41‘, time: ‘2017-03-07 19:26:04 +0000‘
System info: host: ‘windows7‘, ip: ‘192.168.59.1‘, os.name: ‘Windows 7‘, os.arch: ‘x86‘, os.version: ‘6.1‘, java.version: ‘1.8.0_45‘
Driver info: driver.version: AndroidDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
at io.appium.java_client.remote.AppiumProtocolHandShake.createSession(AppiumProtocolHandShake.java:161)
at io.appium.java_client.remote.AppiumProtocolHandShake.lambda$2(AppiumProtocolHandShake.java:88)
at io.appium.java_client.remote.AppiumProtocolHandShake$$Lambda$5/23545302.get(Unknown Source)
at java.util.Optional.orElseGet(Optional.java:267)
at io.appium.java_client.remote.AppiumProtocolHandShake.lambda$0(AppiumProtocolHandShake.java:83)
at io.appium.java_client.remote.AppiumProtocolHandShake$$Lambda$4/10853795.get(Unknown Source)
at java.util.Optional.orElseGet(Optional.java:267)
at io.appium.java_client.remote.AppiumProtocolHandShake.createSession(AppiumProtocolHandShake.java:78)
at io.appium.java_client.remote.AppiumCommandExecutor.doExecute(AppiumCommandExecutor.java:111)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:162)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:604)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:244)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:131)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:144)
at io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:38)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:88)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:112)
at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:73)
 
问题原因,appium server端升级到1.6.5 后,appium 安装目录下的子模块\appium\node_modules\appium-uiautomator2-driver   的文件夹uiautomator2下面没有  2个必要的安卓apk文件:
appium-uiautomator2-server-debug-androidTest.apk
appium-uiautomator2-server-v0.1.5.apk
这个时候在appium 安装目录下 执行命令:npm  install  appium-uiautomator2-driver   安装appium-uiautomator2-driver
 
安装完成后,npm\node_modules\appium\node_modules\appium-uiautomator2-driver\uiautomator2 目录下应该有2个apk文件

appium +uiautomator2 遇到deviceName can't be blank 提示的解决

文章图片

































    推荐阅读