java - 收到意外响应 : {"code" :"ECONNRESET"} when executing appium script in android emulator

标签 java automation appium appium-android

我正在运行以下脚本: 这段代码是在android模拟器中打开PlayStore

DesiredCapabilities capabilities = new DesiredCapabilities();

        capabilities.setCapability("deviceName", "Nexus 5 API Q");
        capabilities.setCapability("automationName", "UiAutomator2");
        capabilities.setCapability("udid", "emulator-5554"); 
        capabilities.setCapability("platformVersion", "10");
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("appPackage","com.android.vending");
 capabilities.setCapability("appActivity","com.google.android.finsky.activities.MainActivity");
//        capabilities.setCapability(MobileCapabilityType.APP, fs.getAbsolutePath());
        capabilities.setCapability("noReset", "true");

        try {
            AppiumDriver<MobileElement> driver = new AndroidDriver<>(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);

        } catch (MalformedURLException e) {
            System.out.println(e.getMessage());
        }
    }

我的appium-doctor显示所有最新内容,但在appium服务器上我收到错误: [Appium日志] https://www.dropbox.com/s/s0mros5scj4mikx/Screenshot%202019-05-27%2018.25.26.png?dl=0 添加了完整的 appium 服务器日志。

 `[Appium] Welcome to Appium v1.13.0
[Appium] Non-default server args:
[Appium]   sessionOverride: true
[Appium] Appium REST http interface listener started on 0.0.0.0:4723
[HTTP] --> POST /wd/hub/session
[HTTP] {"desiredCapabilities":{"appActivity":"com.google.android.finsky.activities.MainActivity","appPackage":"com.android.vending","platformVersion":"10","automationName":"UiAutomator2","platformName":"Android","udid":"emulator-5554","deviceName":"Nexus 5 API Q"},"capabilities":{"firstMatch":[{"appium:appActivity":"com.google.android.finsky.activities.MainActivity","appium:appPackage":"com.android.vending","appium:automationName":"UiAutomator2","appium:deviceName":"Nexus 5 API Q","platformName":"android","appium:platformVersion":"10","appium:udid":"emulator-5554"}]}}
[W3C] Calling AppiumDriver.createSession() with args: [{"appActivity":"com.google.android.finsky.activities.MainActivity","appPackage":"com.android.vending","platformVersion":"10","automationName":"UiAutomator2","platformName":"Android","udid":"emulator-5554","deviceName":"Nexus 5 API Q"},null,{"firstMatch":[{"appium:appActivity":"com.google.android.finsky.activities.MainActivity","appium:appPackage":"com.android.vending","appium:automationName":"UiAutomator2","appium:deviceName":"Nexus 5 API Q","platformName":"android","appium:platformVersion":"10","appium:udid":"emulator-5554"}]}]
[BaseDriver] Event 'newSessionRequested' logged at 1559022178952 (11:12:58 GMT+0530 (IST))
[Appium] Appium v1.13.0 creating new AndroidUiautomator2Driver (v1.33.1) session
[Appium] Capabilities:
[Appium]   platformName: android
[Appium]   appActivity: com.google.android.finsky.activities.MainActivity
[Appium]   appPackage: com.android.vending
[Appium]   automationName: UiAutomator2
[Appium]   deviceName: Nexus 5 API Q
[Appium]   platformVersion: 10
[Appium]   udid: emulator-5554
[BaseDriver] W3C capabilities {"alwaysMatch":{"platformNa... and MJSONWP desired capabilities {"appActivity":"com.google.... were provided
[BaseDriver] Creating session with W3C capabilities: {"alwaysMatch":{"platformNa...
[BaseDriver] Session created with session id: 1cea5658-2748-4d09-964a-25687e221d84
[ADB] Using 'adb' from '/Users/shivam.somani/Library/Android/sdk/platform-tools/adb'
[AndroidDriver] Retrieving device list
[ADB] Trying to find a connected android device
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[AndroidDriver] Using device: emulator-5554
[ADB] Using 'adb' from '/Users/shivam.somani/Library/Android/sdk/platform-tools/adb'
[ADB] Setting device id to emulator-5554
[ADB] Running '/Users/shivam.somani/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell getprop ro.build.version.sdk'
[ADB] Current device property 'ro.build.version.sdk': 28
[ADB] Running '/Users/shivam.somani/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell getprop ro.build.version.release'
[ADB] Current device property 'ro.build.version.release': 10
[ADB] Device API level: 28
[UiAutomator2] Relaxing hidden api policy
[ADB] Running '/Users/shivam.somani/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell settings put global hidden_api_policy_pre_p_apps 1'
[ADB] Running '/Users/shivam.somani/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell settings put global hidden_api_policy_p_apps 1'
[ADB] Running '/Users/shivam.somani/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell settings put global hidden_api_policy 1'
[AndroidDriver] No app sent in, not parsing package/activity
[ADB] Running '/Users/shivam.somani/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 wait-for-device'
[ADB] Running '/Users/shivam.somani/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell echo ping'
[AndroidDriver] Pushing settings apk to device...
[ADB] Getting install status for io.appium.settings
[ADB] Running '/Users/shivam.somani/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell dumpsys package io.appium.settings'
[ADB] 'io.appium.settings' is installed
[ADB] Getting package info for 'io.appium.settings'
[ADB] Running '/Users/shivam.somani/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell dumpsys package io.appium.settings'
[ADB] Using 'aapt' from '/Users/shivam.somani/Library/Android/sdk/build-tools/28.0.3/aapt'
[ADB] The version name of the installed 'io.appium.settings' is greater or equal to the application version name ('2.14.0' >= '2.14.0')
[ADB] There is no need to install/upgrade '/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/io.appium.settings/apks/settings_apk-debug.apk'
[ADB] Getting IDs of all 'io.appium.settings' processes
[ADB] Running '/Users/shivam.somani/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell 'pgrep --help; echo $?''
[ADB] Running '/Users/shivam.somani/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell pgrep -f io\\.appium\\.settings'
[AndroidDriver] io.appium.settings is already running. There is no need to reset its permissions.
[ADB] Running '/Users/shivam.somani/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell appops set io.appium.settings android\:mock_location allow'
[Logcat] Starting logcat capture
[ADB] Getting install status for io.appium.uiautomator2.server
[ADB] Running '/Users/shivam.somani/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell dumpsys package io.appium.uiautomator2.server'
[ADB] 'io.appium.uiautomator2.server' is installed
[ADB] Getting package info for 'io.appium.uiautomator2.server'
[ADB] Running '/Users/shivam.somani/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell dumpsys package io.appium.uiautomator2.server'
[ADB] The version name of the installed 'io.appium.uiautomator2.server' is greater or equal to the application version name ('3.5.1' >= '3.5.1')
[UiAutomator2] io.appium.uiautomator2.server installation state: sameVersionInstalled
[ADB] Checking app cert for /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-v3.5.1.apk
[ADB] Using 'apksigner' from '/Users/shivam.somani/Library/Android/sdk/build-tools/28.0.3/apksigner'
[ADB] Starting '/Users/shivam.somani/Library/Android/sdk/build-tools/28.0.3/apksigner' with args '["verify","--print-certs","/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-v3.5.1.apk"]'
[ADB] apksigner stdout: Signer #1 certificate DN: EMAILADDRESS=android@android.com, CN=Android, OU=Android, O=Android, L=Mountain View, ST=California, C=US
[ADB] Signer #1 certificate SHA-256 digest: a40da80a59d170caa950cf15c18c454d47a39b26989d8b640ecd745ba71bf5dc
[ADB] Signer #1 certificate SHA-1 digest: 61ed377e85d386a8dfee6b864bd85b0bfaa5af81
[ADB] Signer #1 certificate MD5 digest: e89b158e4bcf988ebd09eb83f5378e87
[ADB] 
[ADB] '/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-v3.5.1.apk' is already signed.
[ADB] Getting install status for io.appium.uiautomator2.server.test
[ADB] Running '/Users/shivam.somani/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell dumpsys package io.appium.uiautomator2.server.test'
[ADB] 'io.appium.uiautomator2.server.test' is installed
[ADB] Checking app cert for /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk
[ADB] Starting '/Users/shivam.somani/Library/Android/sdk/build-tools/28.0.3/apksigner' with args '["verify","--print-certs","/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk"]'
[ADB] apksigner stdout: Signer #1 certificate DN: EMAILADDRESS=android@android.com, CN=Android, OU=Android, O=Android, L=Mountain View, ST=California, C=US
[ADB] Signer #1 certificate SHA-256 digest: a40da80a59d170caa950cf15c18c454d47a39b26989d8b640ecd745ba71bf5dc
[ADB] Signer #1 certificate SHA-1 digest: 61ed377e85d386a8dfee6b864bd85b0bfaa5af81
[ADB] Signer #1 certificate MD5 digest: e89b158e4bcf988ebd09eb83f5378e87
[ADB] 
[ADB] '/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk' is already signed.
[UiAutomator2] Server packages are not going to be (re)installed
[UiAutomator2] Waiting up to 30000ms for services to be available
[ADB] Running '/Users/shivam.somani/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell pm list instrumentation'
[UiAutomator2] Instrumentation target 'io.appium.uiautomator2.server.test/androidx.test.runner.AndroidJUnitRunner' is available
[UiAutomator2] Forwarding UiAutomator2 Server port 6790 to 8200
[ADB] Forwarding system: 8200 to device: 6790
[ADB] Running '/Users/shivam.somani/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 forward tcp\:8200 tcp\:6790'
[UiAutomator2] No app capability. Assuming it is already on the device
[ADB] Getting install status for com.android.vending
[ADB] Running '/Users/shivam.somani/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell dumpsys package com.android.vending'
[ADB] 'com.android.vending' is installed
[ADB] Running '/Users/shivam.somani/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell am force-stop com.android.vending'
[ADB] Running '/Users/shivam.somani/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell pm clear com.android.vending'
[AndroidDriver] Performed fast reset on the installed 'com.android.vending' application (stop and clear)
[UiAutomator2] Performing shallow cleanup of automation leftovers
[UiAutomator2] No obsolete sessions have been detected (Error: socket hang up)
[ADB] Running '/Users/shivam.somani/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell am force-stop io.appium.uiautomator2.server.test'
[UiAutomator2] Starting UIAutomator2 server 3.5.1
[UiAutomator2] Using UIAutomator2 server from '/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-v3.5.1.apk' and test from '/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk'
[UiAutomator2] Waiting up to 30000ms for UiAutomator2 to be online...
[ADB] Creating ADB subprocess with args: ["-P",5037,"-s","emulator-5554","shell","am","instrument","-w","io.appium.uiautomator2.server.test/androidx.test.runner.AndroidJUnitRunner"]
[Instrumentation] io.appium.uiautomator2.server.test.AppiumUiAutomator2Server:
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[WD Proxy] Got an unexpected response: {"code":"ECONNRESET"}
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[WD Proxy] Got an unexpected response: {"code":"ECONNRESET"}
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[WD Proxy] Got an unexpected response: {"code":"ECONNRESET"}
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[WD Proxy] Got an unexpected response: {"code":"ECONNRESET"}
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[WD Proxy] Got an unexpected response: {"code":"ECONNRESET"}
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[WD Proxy] Got an unexpected response: {"code":"ECONNRESET"}
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[WD Proxy] Got an unexpected response: {"code":"ECONNRESET"}
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[WD Proxy] Got an unexpected response: {"code":"ECONNRESET"}
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[WD Proxy] Got an unexpected response: {"code":"ECONNRESET"}
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[WD Proxy] Got an unexpected response: {"code":"ECONNRESET"}
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[WD Proxy] Got an unexpected response: {"code":"ECONNRESET"}
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[WD Proxy] Got an unexpected response: {"code":"ECONNRESET"}
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[WD Proxy] Got an unexpected response: {"code":"ECONNRESET"}
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[WD Proxy] Got an unexpected response: {"code":"ECONNRESET"}
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[WD Proxy] Got an unexpected response: {"code":"ECONNRESET"}
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[WD Proxy] Got an unexpected response: {"code":"ECONNRESET"}
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[WD Proxy] Got an unexpected response: {"code":"ECONNRESET"}
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[WD Proxy] Got an unexpected response: {"code":"ECONNRESET"}
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[WD Proxy] Got an unexpected response: {"code":"ECONNRESET"}
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[WD Proxy] Got an unexpected response: {"code":"ECONNRESET"}
[UiAutomator2] Error: The instrumentation process cannot be initialized within 30000ms timeout. Make sure the application under test does not crash and investigate the logcat output. You could also try to increase the value of 'uiautomator2ServerLaunchTimeout' capability. 
[UiAutomator2]     at Object.wrappedLogger.errorAndThrow (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-support/lib/logging.js:78:13)
[UiAutomator2]     at UiAutomator2Server.errorAndThrow [as startSession] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-uiautomator2-driver/lib/uiautomator2.js:192:15)
[UiAutomator2]     at process._tickCallback (internal/process/next_tick.js:68:7)
[UiAutomator2] Deleting UiAutomator2 session
[UiAutomator2] Deleting UiAutomator2 server session
[WD 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
[ADB] Running '/Users/shivam.somani/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell am force-stop com.android.vending'
[Logcat] Stopping logcat capture
[ADB] Removing forwarded port socket connection: 8200 
[ADB] Running '/Users/shivam.somani/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 forward --remove tcp\:8200'
[UiAutomator2] Restoring hidden api policy to the device default configuration
[ADB] Running '/Users/shivam.somani/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell settings delete global hidden_api_policy_pre_p_apps'
[ADB] Running '/Users/shivam.somani/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell settings delete global hidden_api_policy_p_apps'
[ADB] Running '/Users/shivam.somani/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell settings delete global hidden_api_policy'
[BaseDriver] Event 'newSessionStarted' logged at 1559022211907 (11:13:31 GMT+0530 (IST))
[W3C] Encountered internal error running command: Error: The instrumentation process cannot be initialized within 30000ms timeout. Make sure the application under test does not crash and investigate the logcat output. You could also try to increase the value of 'uiautomator2ServerLaunchTimeout' capability. 
[W3C]     at Object.wrappedLogger.errorAndThrow (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-support/lib/logging.js:78:13)
[W3C]     at UiAutomator2Server.errorAndThrow [as startSession] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-uiautomator2-driver/lib/uiautomator2.js:192:15)
[W3C]     at process._tickCallback (internal/process/next_tick.js:68:7)
[HTTP] <-- POST /wd/hub/session 500 32957 ms - 1132
[HTTP]

我使用的是 Java 11 和 appium 1.13

最佳答案

从模拟器中卸载 uiautomator-serveruiautomator-server-test 应用,然后尝试再次运行脚本。

在命令提示符中运行以下命令来卸载应用程序:

adb uninstall io.appium.uiautomator2.server
adb uninstall io.appium.uiautomator2.server.test

然后运行您的自动化脚本。当我收到 ECONNRESET 错误时,这对我有用。

关于java - 收到意外响应 : {"code" :"ECONNRESET"} when executing appium script in android emulator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56326620/

相关文章:

java - 无效的 cookie header : Unable to parse expires attribute when expires attribute is empty

php - 是否有与 Perl 的 WWW::Mechanize 等效的 PHP?

python - 用于 selenium 浏览器自动化的 Flask Web 应用程序输入

java - 如何有效地划分测试用例以在使用 appium 的移动应用程序中自动化它们

node.js - Ubuntu Node 错误

android - 获取 UI 层次结构 XML 文件时出错 : com. android.ddmlib.SyncException : Remote object doesn't exist!“,为具有动态定位器的应用程序显示

java - 存储带有未知字符的字符串

java - Package.getImplementationVersion() 返回 NULL

JAVA客户端-服务器-从ObjectInputStreamReader读取对象

javascript - 在手动页面上启动 Puppeteer