Appium 测试启动在多个设备上失败
Appium test launch fails on multiple devices
我正在 Windows 7 台机器上工作,并尝试实施 Appium 测试以在 2 个真实的 Android 设备上并行启动。
我能够分别在 2 台设备中的每台设备上启动并按预期执行测试,但使用 JUnit 同时启动失败,其中一台设备的堆栈跟踪如下:
info: [debug] Pushing command to appium work queue: ["element:getText",{"elementId":"2"}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:getText","params":{"elementId":"2"}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: getText
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"Sign up","status":0}
info: [debug] Responding to client with success: {"status":0,"value":"Sign up","sessionId":"c730d16f-ca7f-42aa-be23-da33bbefd9f0"}
info: <-- GET /wd/hub/session/c730d16f-ca7f-42aa-be23-da33bbefd9f0/element/2/text 200 56.413 ms - 81 {"status":0,"value":"Sign up","sessionId":"c730d16f-ca7f-42aa-be23-da33bbefd9f0"}
info: --> DELETE /wd/hub/session/c730d16f-ca7f-42aa-be23-da33bbefd9f0 {}
info: Shutting down appium session
info: [debug] Pressing the HOME button
info: [debug] executing cmd: C:\Users\Kristaps.Mezavilks\AppData\Local\Android\sdk\platform-tools\adb.exe -s 192.168.1.204:5555 shell "input keyevent 3"
info: [debug] Stopping logcat capture
info: [debug] Logcat terminated with code null, signal SIGTERM
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"shutdown"}
info: [debug] [BOOTSTRAP] [debug] Got command of type SHUTDOWN
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"OK, shutting down","status":0}
info: [debug] [BOOTSTRAP] [debug] Closed client connection
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=.
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 0
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
info: [debug] [UIAUTOMATOR STDOUT] Test results for WatcherResultPrinter=.
info: [debug] [UIAUTOMATOR STDOUT] Time: 6.985
info: [debug] [UIAUTOMATOR STDOUT] OK (1 test)
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: -1
info: [debug] Sent shutdown command, waiting for UiAutomator to stop...
info: [debug] UiAutomator shut down normally
info: [debug] Cleaning up android objects
info: [debug] Cleaning up appium session
info: [debug] Responding to client with success: {"status":0,"value":null,"sessionId":"c730d16f-ca7f-42aa-be23-da33bbefd9f0"}
在发布之前,我执行了以下操作:
- 启动 Selenium 网格:
java -jar selenium-server-standalone-2.46.0.jar -role -hub -throwOnCapabilityNotPresent
- 启动 2 个 Appium 节点:
node appium --nodeconfig C:\Users\Kristaps.Mezavilks\selenium\node_p.json -p 4728 --udid 192.168.219:5555
和
node appium --nodeconfig C:\Users\Kristaps.Mezavilks\selenium\node_c.json -p 4730 --udid 192.168.204:5555
配置文件示例node_c.json:
{
"capabilities":[
{
"browserName":"android",
"version":"4.4.2",
"maxInstances":3,
"platform":"ANDROID",
"deviceName":"192.168.1.204:5555"
}
],
"configuration":{
"cleanUpCycle":2000,
"timeout":30000,
"proxy":"org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"url":"http://localhost:4730/wd/hub",
"host":"localhost",
"port":4730,
"maxSession":1,
"register":true,
"registerCycle":5000,
"hubPort":4444,
"hubHost":"192.168.1.216"
}
}
正在获取 Android 驱动程序:
static AndroidDriver get() {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setPlatform(Platform.ANDROID)
capabilities.setBrowserName("")
capabilities.setVersion(mobileVersion)
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, deviceID);
capabilities.setCapability(MobileCapabilityType.APP, appPath);
capabilities.setCapability(MobileCapabilityType.UDID, deviceID)
def URL remoteAddress = new URL("http://localhost:4444/wd/hub")
new AndroidDriver(remoteAddress, capabilities)
}
你知道问题出在哪里吗,或者至少你能指出正确的方向来查找问题吗?
非常感谢。
编辑:
在@Ageoffan 建议解决了第一个问题之后,现在出现了连接重置问题:
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
info: [debug] [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1
info: [debug] [BOOTSTRAP] [debug] Socket opened on port 4724
info: [debug] [BOOTSTRAP] [debug] Appium Socket Server Ready
info: [debug] [BOOTSTRAP] [debug] Loading json...
info: [debug] Waking up device if it's not alive
info: [debug] Pushing command to appium work queue: ["wake",{}]
info: [debug] [BOOTSTRAP] [debug] json loading complete.
info: [debug] [BOOTSTRAP] [debug] Registered crash watchers.
error: Unhandled error: Error: read ECONNRESET
at exports._errnoException (util.js:746:11)
at TCP.onread (net.js:559:26) context: [POST /wd/hub/session {"desiredCapabilities":{"app":"C:\Users\Kristaps.Mezavilks\Workspace\android-app\project\build\outputs\apk\project-debug2.apk","browserName":"","udid":"192.168.1.219:5555","platformName":"Android]
我认为当您 运行 并行时,JUnit 对您的两个测试用例使用相同的端口。尝试参数化端口号。
Post编辑,试试看你声明能力的部分是否准确。由于错误日志似乎指向该位置。我知道我想要的 android 测试功能如下所示:
File app = new File("pathway to your apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName", "Android Emulator");
capabilities.setCapability("platformVersion", "4.4.2");
capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
driver = new AndroidDriver(new URL("your server url here"),capabilities);
我在一个星期内处理了这个问题,但最后我专注于以下堆栈跟踪行 info: [debug] [BOOTSTRAP] [debug] Socket opened on port 4724
并发现所有实例都连接到同一个套接字端口(所有 tcp 转发命令对所有实例都是相同的).
所以过了一会儿,我设法找到了一种方法,通过使用添加到节点命令的 bootstrap 端口参数 -bp <post_number>
来定义自定义端口上的转发。设置自定义端口后,我什至可以在 4 台设备上实时启动同步并行测试。
感谢@Ageoffan 的帮助!
我正在 Windows 7 台机器上工作,并尝试实施 Appium 测试以在 2 个真实的 Android 设备上并行启动。 我能够分别在 2 台设备中的每台设备上启动并按预期执行测试,但使用 JUnit 同时启动失败,其中一台设备的堆栈跟踪如下:
info: [debug] Pushing command to appium work queue: ["element:getText",{"elementId":"2"}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:getText","params":{"elementId":"2"}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: getText
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"Sign up","status":0}
info: [debug] Responding to client with success: {"status":0,"value":"Sign up","sessionId":"c730d16f-ca7f-42aa-be23-da33bbefd9f0"}
info: <-- GET /wd/hub/session/c730d16f-ca7f-42aa-be23-da33bbefd9f0/element/2/text 200 56.413 ms - 81 {"status":0,"value":"Sign up","sessionId":"c730d16f-ca7f-42aa-be23-da33bbefd9f0"}
info: --> DELETE /wd/hub/session/c730d16f-ca7f-42aa-be23-da33bbefd9f0 {}
info: Shutting down appium session
info: [debug] Pressing the HOME button
info: [debug] executing cmd: C:\Users\Kristaps.Mezavilks\AppData\Local\Android\sdk\platform-tools\adb.exe -s 192.168.1.204:5555 shell "input keyevent 3"
info: [debug] Stopping logcat capture
info: [debug] Logcat terminated with code null, signal SIGTERM
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"shutdown"}
info: [debug] [BOOTSTRAP] [debug] Got command of type SHUTDOWN
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"OK, shutting down","status":0}
info: [debug] [BOOTSTRAP] [debug] Closed client connection
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=.
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 0
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
info: [debug] [UIAUTOMATOR STDOUT] Test results for WatcherResultPrinter=.
info: [debug] [UIAUTOMATOR STDOUT] Time: 6.985
info: [debug] [UIAUTOMATOR STDOUT] OK (1 test)
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: -1
info: [debug] Sent shutdown command, waiting for UiAutomator to stop...
info: [debug] UiAutomator shut down normally
info: [debug] Cleaning up android objects
info: [debug] Cleaning up appium session
info: [debug] Responding to client with success: {"status":0,"value":null,"sessionId":"c730d16f-ca7f-42aa-be23-da33bbefd9f0"}
在发布之前,我执行了以下操作:
- 启动 Selenium 网格:
java -jar selenium-server-standalone-2.46.0.jar -role -hub -throwOnCapabilityNotPresent
- 启动 2 个 Appium 节点:
node appium --nodeconfig C:\Users\Kristaps.Mezavilks\selenium\node_p.json -p 4728 --udid 192.168.219:5555
和
node appium --nodeconfig C:\Users\Kristaps.Mezavilks\selenium\node_c.json -p 4730 --udid 192.168.204:5555
配置文件示例node_c.json:
{
"capabilities":[
{
"browserName":"android",
"version":"4.4.2",
"maxInstances":3,
"platform":"ANDROID",
"deviceName":"192.168.1.204:5555"
}
],
"configuration":{
"cleanUpCycle":2000,
"timeout":30000,
"proxy":"org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"url":"http://localhost:4730/wd/hub",
"host":"localhost",
"port":4730,
"maxSession":1,
"register":true,
"registerCycle":5000,
"hubPort":4444,
"hubHost":"192.168.1.216"
}
}
正在获取 Android 驱动程序:
static AndroidDriver get() {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setPlatform(Platform.ANDROID)
capabilities.setBrowserName("")
capabilities.setVersion(mobileVersion)
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, deviceID);
capabilities.setCapability(MobileCapabilityType.APP, appPath);
capabilities.setCapability(MobileCapabilityType.UDID, deviceID)
def URL remoteAddress = new URL("http://localhost:4444/wd/hub")
new AndroidDriver(remoteAddress, capabilities)
}
你知道问题出在哪里吗,或者至少你能指出正确的方向来查找问题吗? 非常感谢。
编辑: 在@Ageoffan 建议解决了第一个问题之后,现在出现了连接重置问题:
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
info: [debug] [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1
info: [debug] [BOOTSTRAP] [debug] Socket opened on port 4724
info: [debug] [BOOTSTRAP] [debug] Appium Socket Server Ready
info: [debug] [BOOTSTRAP] [debug] Loading json...
info: [debug] Waking up device if it's not alive
info: [debug] Pushing command to appium work queue: ["wake",{}]
info: [debug] [BOOTSTRAP] [debug] json loading complete.
info: [debug] [BOOTSTRAP] [debug] Registered crash watchers.
error: Unhandled error: Error: read ECONNRESET
at exports._errnoException (util.js:746:11)
at TCP.onread (net.js:559:26) context: [POST /wd/hub/session {"desiredCapabilities":{"app":"C:\Users\Kristaps.Mezavilks\Workspace\android-app\project\build\outputs\apk\project-debug2.apk","browserName":"","udid":"192.168.1.219:5555","platformName":"Android]
我认为当您 运行 并行时,JUnit 对您的两个测试用例使用相同的端口。尝试参数化端口号。
Post编辑,试试看你声明能力的部分是否准确。由于错误日志似乎指向该位置。我知道我想要的 android 测试功能如下所示:
File app = new File("pathway to your apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName", "Android Emulator");
capabilities.setCapability("platformVersion", "4.4.2");
capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
driver = new AndroidDriver(new URL("your server url here"),capabilities);
我在一个星期内处理了这个问题,但最后我专注于以下堆栈跟踪行 info: [debug] [BOOTSTRAP] [debug] Socket opened on port 4724
并发现所有实例都连接到同一个套接字端口(所有 tcp 转发命令对所有实例都是相同的).
所以过了一会儿,我设法找到了一种方法,通过使用添加到节点命令的 bootstrap 端口参数 -bp <post_number>
来定义自定义端口上的转发。设置自定义端口后,我什至可以在 4 台设备上实时启动同步并行测试。
感谢@Ageoffan 的帮助!