Appium [已解决] Mac + Appium + java,为了获取 Toast 在配置参数时加上 ["automationName","Uiautomator2"] 后,运行报错

Tester-Owen · 2019年01月31日 · 最后由 Tester-Owen 回复于 2019年02月01日 · 2259 次阅读

环境

1、Appium:1.9.1
2、JAVA Client:6.1.0
3、JAVA:1.8
4、Android 模拟器:7.0
5、SDK

Code

capabilities.setCapability("automationName","Uiautomator2");

报错日志

org.openqa.selenium.WebDriverException: It is impossible to create a new session because 'createSession' which takes HttpClient, InputStream and long was not found or it is not accessible
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'
System info: host: 'test', ip: 'fe80:0:0:0:41:3d3:5a4e:df7%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.6', java.version: '1.8.0_181'
Driver info: driver.version: AndroidDriver

    at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:195)
    at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:209)
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:231)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
    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:207)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:130)
    at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:38)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:84)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:94)
    at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:93)
    at ApiDemo.beforeClass(ApiDemo.java:40)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:185)
    ... 27 more
Caused by: org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Error executing adbExec. Original error: 'Command '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 pull /data/app/ApiDemos/ApiDemos.apk /var/folders/gf/jjhn56c97293xtjvtwlnwr8h0000gp/T/com.example.android.apis.apk' exited with code 1'; Stderr: ''; Code: '1'
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'
System info: host: 'test', ip: 'fe80:0:0:0:41:3d3:5a4e:df7%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.6', java.version: '1.8.0_181'
Driver info: driver.version: AndroidDriver
remote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: Error executing adbExec. Original error: 'Command '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 pull /data/app/ApiDemos/ApiDemos.apk /var/folders/gf/jjhn56c97293xtjvtwlnwr8h0000gp/T/com.example.android.apis.apk' exited with code 1'; Stderr: ''; Code: '1'
    at getResponseForW3CError (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/errors.js:826:9)
    at asyncHandler$ (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/protocol.js:404:37)
    at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
    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:423)
    at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$new$0(W3CHandshakeResponse.java:57)
    at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$getResponseFunction$2(W3CHandshakeResponse.java:104)
    at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
    at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
    at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
    ... 32 more

Appium log 日志

[debug] [W3C] Calling AppiumDriver.createSession() with args: [{"appActivity":".ApiDemos","appPackage":"com.example.android.apis","automationName":"Uiautomator2","platformName":"Android","deviceName":"emulator-5554"},null,{"alwaysMatch":{"appium:appActivity":".ApiDemos","appium:appPackage":"com.example.android.apis","appium:automationName":"Uiautomator2","appium:deviceName":"emulator-5554","platformName":"android"},"firstMatch":[{}]}]
[debug] [BaseDriver] Event 'newSessionRequested' logged at 1548926366177 (17:19:26 GMT+0800 (GMT+08:00))
[Appium] Creating new AndroidUiautomator2Driver (v1.19.0) session
[Appium] Capabilities:
[Appium]   platformName: android
[Appium]   appActivity: .ApiDemos
[Appium]   appPackage: com.example.android.apis
[Appium]   automationName: Uiautomator2
[Appium]   deviceName: emulator-5554
[debug] [BaseDriver] W3C capabilities {"alwaysMatch":{"platformNa... and MJSONWP desired capabilities {"appActivity":".ApiDemos",... were provided
[debug] [BaseDriver] Creating session with W3C capabilities: {"alwaysMatch":{"platformNa...
[BaseDriver] Session created with session id: 4cb8465d-adf7-422c-bb9d-7257240150b0
[AndroidDriver] Java version is: 1.8.0_181
[AndroidDriver] Retrieving device list
[debug] [ADB] Trying to find a connected android device
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[AndroidDriver] Using device: emulator-5554
[debug] [ADB] Setting device id to emulator-5554
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell getprop ro.build.version.sdk'
[debug] [ADB] Current device property 'ro.build.version.sdk': 24
[debug] [ADB] Device API level: 24
[AndroidDriver] No app sent in, not parsing package/activity
[ADB] Getting device platform version
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell getprop ro.build.version.release'
[debug] [ADB] Current device property 'ro.build.version.release': 7.0
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell wm size'
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell wm density'
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell getprop ro.product.model'
[debug] [ADB] Current device property 'ro.product.model': Android SDK built for x86
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell getprop ro.product.manufacturer'
[debug] [ADB] Current device property 'ro.product.manufacturer': Google
[debug] [ADB] Device API level: 24
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell am force-stop io.appium.uiautomator2.server'
[debug] [ADB] Checking app cert for /usr/local/lib/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-v1.18.0.apk
[debug] [ADB] Starting '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/build-tools/28.0.3/apksigner' with args '["verify","--print-certs","/usr/local/lib/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-v1.18.0.apk"]'
[debug] [ADB] apksigner stdout: Signer #1 certificate DN: EMAILADDRESS=android@android.com, CN=Android, OU=Android, O=Android, L=Mountain View, ST=California, C=US
[debug] [ADB] Signer #1 certificate SHA-256 digest: a40da80a59d170caa950cf15c18c454d47a39b26989d8b640ecd745ba71bf5dc
[debug] [ADB] Signer #1 certificate SHA-1 digest: 61ed377e85d386a8dfee6b864bd85b0bfaa5af81
[debug] [ADB] Signer #1 certificate MD5 digest: e89b158e4bcf988ebd09eb83f5378e87
[debug] [ADB] WARNING: META-INF/INDEX.LIST not protected by signature. Unauthorized modifications to this JAR entry will not be detected. Delete or move the entry outside of META-INF/.
[debug] [ADB] WARNING: META-INF/io.netty.versions.properties not protected by signature. Unauthorized modifications to this JAR entry will not be detected. Delete or move the entry outside of META-INF/.
[debug] [ADB]
[debug] [ADB] '/usr/local/lib/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-v1.18.0.apk' is already signed.
[debug] [ADB] Checking app cert for /usr/local/lib/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk
[debug] [ADB] Starting '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/build-tools/28.0.3/apksigner' with args '["verify","--print-certs","/usr/local/lib/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk"]'
[debug] [ADB] apksigner stdout: Signer #1 certificate DN: EMAILADDRESS=android@android.com, CN=Android, OU=Android, O=Android, L=Mountain View, ST=California, C=US
[debug] [ADB] Signer #1 certificate SHA-256 digest: a40da80a59d170caa950cf15c18c454d47a39b26989d8b640ecd745ba71bf5dc
[debug] [ADB] Signer #1 certificate SHA-1 digest: 61ed377e85d386a8dfee6b864bd85b0bfaa5af81
[debug] [ADB] Signer #1 certificate MD5 digest: e89b158e4bcf988ebd09eb83f5378e87
[debug] [ADB]
[debug] [ADB] '/usr/local/lib/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk' is already signed.
[debug] [ADB] Getting install status for io.appium.uiautomator2.server
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell pm list packages io.appium.uiautomator2.server'
[debug] [ADB] App is installed
[debug] [ADB] Getting package info for 'io.appium.uiautomator2.server'
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell dumpsys package io.appium.uiautomator2.server'
[debug] [ADB] The installed 'io.appium.uiautomator2.server' package does not require upgrade ('1.18.0' >= '1.18.0')
[debug] [ADB] Getting install status for io.appium.uiautomator2.server.test
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell pm list packages io.appium.uiautomator2.server.test'
[debug] [ADB] App is installed
[debug] [ADB] Getting package info for 'io.appium.uiautomator2.server.test'
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell dumpsys package io.appium.uiautomator2.server.test'
[ADB] Cannot read version codes of '/usr/local/lib/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk' and/or 'io.appium.uiautomator2.server.test'
[ADB] Cannot read version names of '/usr/local/lib/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk' and/or 'io.appium.uiautomator2.server.test'. Assuming correct app version is already installed
[debug] [UiAutomator2] Waiting up to 20000ms for instrumentation 'io.appium.uiautomator2.server.test/android.support.test.runner.AndroidJUnitRunner' to be available
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell pm list instrumentation'
[debug] [UiAutomator2] Instrumentation 'io.appium.uiautomator2.server.test/android.support.test.runner.AndroidJUnitRunner' available
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 wait-for-device'
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell echo ping'
[debug] [AndroidDriver] Pushing settings apk to device...
[debug] [ADB] Getting install status for io.appium.settings
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell pm list packages io.appium.settings'
[debug] [ADB] App is installed
[debug] [ADB] Getting package info for 'io.appium.settings'
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell dumpsys package io.appium.settings'
[debug] [ADB] The installed 'io.appium.settings' package does not require upgrade (13 > 5)
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell ps'
[debug] [AndroidDriver] io.appium.settings is already running. There is no need to reset its permissions.
[debug] [ADB] Device API level: 24
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell appops set io.appium.settings android\:mock_location allow'
[AndroidDriver] setDeviceLanguageCountry requires language or country.
[AndroidDriver] Got language: 'null' and country: 'null'
[debug] [Logcat] Starting logcat capture
[debug] [AndroidDriver] Pushing unlock helper app to device...
[debug] [ADB] Getting install status for io.appium.unlock
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell pm list packages io.appium.unlock'
[debug] [ADB] App is installed
[debug] [ADB] Getting package info for 'io.appium.unlock'
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell dumpsys package io.appium.unlock'
[debug] [ADB] The installed 'io.appium.unlock' package does not require upgrade ('2.0.0' >= '2.0.0')
[debug] [UiAutomator2] Forwarding UiAutomator2 Server port 6790 to 8200
[debug] [ADB] Forwarding system: 8200 to device: 6790
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 forward tcp\:8200 tcp\:6790'
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell rm -rf /data/local/tmp/strings.json'
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell pm path com.example.android.apis'
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 pull /data/app/ApiDemos/ApiDemos.apk /var/folders/gf/jjhn56c97293xtjvtwlnwr8h0000gp/T/com.example.android.apis.apk'
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 pull /data/app/ApiDemos/ApiDemos.apk /var/folders/gf/jjhn56c97293xtjvtwlnwr8h0000gp/T/com.example.android.apis.apk'
[debug] [UiAutomator2] Deleting UiAutomator2 session
[debug] [UiAutomator2] Deleting UiAutomator2 server session
[debug] [JSONWP Proxy] Matched '/' to command name 'deleteSession'
[UiAutomator2] Did not get confirmation UiAutomator2 deleteSession worked; Error was: UnknownError: An unknown server-side error occurred while processing the command. Original error: Trying to proxy a session command without session id
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell am force-stop com.example.android.apis'
[debug] [Logcat] Stopping logcat capture
[debug] [ADB] Removing forwarded port socket connection: 8200
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 forward --remove tcp\:8200'
[debug] [BaseDriver] Event 'newSessionStarted' logged at 1548926370387 (17:19:30 GMT+0800 (GMT+08:00))
[debug] [W3C] Encountered internal error running command: Error: Error executing adbExec. Original error: 'Command '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 pull /data/app/ApiDemos/ApiDemos.apk /var/folders/gf/jjhn56c97293xtjvtwlnwr8h0000gp/T/com.example.android.apis.apk' exited with code 1'; Stderr: ''; Code: '1'
[debug] [W3C]     at ADB.execFunc$ (/usr/local/lib/node_modules/appium/node_modules/appium-adb/lib/tools/system-calls.js:327:13)
[debug] [W3C]     at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
[debug] [W3C]     at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
[debug] [W3C]     at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
[debug] [W3C]     at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
[HTTP] <-- POST /wd/hub/session 500 4214 ms - 1677

已解决,参考下面

最佳回复
bauul 回复

使用 Appium1.10.0 版本和加一个 noReset=True 参数,试试看

默默无闻 回复

重新安装 1.10.0 版本的就可以了没问题了,网上查找了一下,好像说是路径的问题,之前我的 appium1.9.1 放在路径【/usr/local/bin/appium】下面,但是这次重装的路径在【/Users/个人账户/.nvm/versions/node/v10.15.0/lib/node_modules/appium/node_modul】个人账户路径下,参考文章:https://blog.csdn.net/lsp84ch80/article/details/81214705

下面是我的具体操作:
1、先卸载 Mac 中的 appium:npm unistall -g appium
2、查看电脑中还有没有 appium:appium -v
3、如果第二步还存在说明 appium 安装到其他目录下了,查看 appium 路径:which appium
此时可能会输出路径为【/usr/local/bin/appium】,进到这个目录下手动删除 appium 文件夹
4、再输入:appium -v,此时应该就没有

zsh: command not found: appium

5、再重新安装 appium 指定版本:cnpm install -g appium@1.10.0
6、再输入:appium -v,此时应该就有

1.10.0

7、最后启动 appium 服务,运行代码就不报错了,并且可以获取到 Toast 信息了
8、java 代码:

@BeforeClass
    public static void beforeClass() throws MalformedURLException {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("platformName","android");
        capabilities.setCapability("deviceName","emulator-5554");
        capabilities.setCapability("appPackage","com.example.android.apis");
        capabilities.setCapability("appActivity",".ApiDemos");


        **只加了这一行,没有加【capabilities.setCapability("noReset",true);**
        capabilities.setCapability("automationName","uiautomator2");


        // driver实例
        driver = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
        driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
    }
共收到 7 条回复 时间 点赞

应该是 uiautomator2 server 的 app 打包失败导致的

bauul 回复

意思是他自动下载的 apk 包失败是吗

bauul 回复

使用 Appium1.10.0 版本和加一个 noReset=True 参数,试试看

bauul 回复

我看了一下,有这两个 apk 包

6楼 已删除

下面是我的具体操作:
1、先卸载 Mac 中的 appium:npm unistall -g appium
2、查看电脑中还有没有 appium:appium -v
3、如果第二步还存在说明 appium 安装到其他目录下了,查看 appium 路径:which appium
此时可能会输出路径为【/usr/local/bin/appium】,进到这个目录下手动删除 appium 文件夹
4、再输入:appium -v,此时应该就没有

zsh: command not found: appium

5、再重新安装 appium 指定版本:cnpm install -g appium@1.10.0
6、再输入:appium -v,此时应该就有

1.10.0

7、最后启动 appium 服务,运行代码就不报错了,并且可以获取到 Toast 信息了
8、java 代码:

@BeforeClass
    public static void beforeClass() throws MalformedURLException {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("platformName","android");
        capabilities.setCapability("deviceName","emulator-5554");
        capabilities.setCapability("appPackage","com.example.android.apis");
        capabilities.setCapability("appActivity",".ApiDemos");


        **只加了这一行,没有加【capabilities.setCapability("noReset",true);**
        capabilities.setCapability("automationName","uiautomator2");


        // driver实例
        driver = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
        driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
    }
8楼 已删除
默默无闻 回复

重新安装 1.10.0 版本的就可以了没问题了,网上查找了一下,好像说是路径的问题,之前我的 appium1.9.1 放在路径【/usr/local/bin/appium】下面,但是这次重装的路径在【/Users/个人账户/.nvm/versions/node/v10.15.0/lib/node_modules/appium/node_modul】个人账户路径下,参考文章:https://blog.csdn.net/lsp84ch80/article/details/81214705

Tester-Owen 关闭了讨论 02月01日 14:22
Tester-Owen 重新开启了讨论 02月01日 14:24
Tester-Owen 关闭了讨论 02月01日 14:25
Tester-Owen 重新开启了讨论 02月01日 14:26
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册