Appium server automatically quit session while waiting

我怕爱的太早我们不能终老 提交于 2019-12-13 04:17:07

问题


I am doing automation with Appium on Android platform. Due to some reason, I need to wait for some time during the test. However, Appium automatically quit session if it does not receive commands in around 4 seconds. Can anyone help me tell me how to make Appium not quit my driver.

I have tried add "newCommandTimeout" to capability, but it does not work.

capabilities.setCapability("newCommandTimeout", 120000);

Appium version: v1.9.1

Here are appium logs while session is quiting:

[W3C] Calling AppiumDriver.deleteSession() with args: ["d9a0e702-f477-439b-8502-aa9d3c93737f"]
[BaseDriver] Event 'quitSessionRequested' logged at 1548332599830 (20:23:19 GMT+0800 (Malay Peninsula Standard Time))
[Appium] Removing session d9a0e702-f477-439b-8502-aa9d3c93737f from our master session list
[AndroidDriver] Shutting down Android driver

Jan 29 2019 UPDATE:

As suggested by most people, I have tried set 300 to newCommandTimeout

capabilities.setCapability("newCommandTimeout", 300);

Session is still quiting. I use Thread.sleep(5000) to make script wait. Here are logs for creating sessions and closing sessions in Appium. Timestamp is added. It looks like sessions are closed automatically after 10 seconds waiting.

[2019-01-29 01:03:51][Appium] Creating new AndroidDriver (v4.1.1) session
[2019-01-29 01:03:51][Appium] Capabilities:
[2019-01-29 01:03:51][Appium]   platform: ANDROID
[2019-01-29 01:03:51][Appium]   platformName: android
[2019-01-29 01:03:51][Appium]   appActivity: *****
[2019-01-29 01:03:51][Appium]   appPackage: *****
[2019-01-29 01:03:51][Appium]   deviceName: *****
[2019-01-29 01:03:51][Appium]   language: en
[2019-01-29 01:03:51][Appium]   locale: US
[2019-01-29 01:03:51][Appium]   newCommandTimeout: 300
<SOME LOGS OMITTED>
[2019-01-29 01:04:10][HTTP] <-- POST /wd/hub/session 200 18650 ms - 913
[2019-01-29 01:04:10][HTTP] 
[2019-01-29 01:04:10][HTTP] --> GET /wd/hub/session/f1dbcd92-fa13-4fc7-a9fd-e6a82b55f9e7
[2019-01-29 01:04:10][HTTP] {}
[2019-01-29 01:04:10][HTTP] <-- GET /wd/hub/session/f1dbcd92-fa13-4fc7-a9fd-e6a82b55f9e7 200 5 ms - 845
[2019-01-29 01:04:10][HTTP] 
[2019-01-29 01:04:10][HTTP] --> GET /wd/hub/session/f1dbcd92-fa13-4fc7-a9fd-e6a82b55f9e7
[2019-01-29 01:04:10][HTTP] <-- GET /wd/hub/session/f1dbcd92-fa13-4fc7-a9fd-e6a82b55f9e7 200 3 ms - 845
[2019-01-29 01:04:10][HTTP] 
[2019-01-29 01:04:20][HTTP] --> DELETE /wd/hub/session/f1dbcd92-fa13-4fc7-a9fd-e6a82b55f9e7
[2019-01-29 01:04:20][HTTP] {}
[2019-01-29 01:04:20][W3C] Calling AppiumDriver.deleteSession() with args: ["f1dbcd92-fa13-4fc7-a9fd-e6a82b55f9e7"]
[2019-01-29 01:04:20][BaseDriver] Event 'quitSessionRequested' logged at 1548738260177 (13:04:20 GMT+0800 (Malay Peninsula Standard Time))
[2019-01-29 01:04:20][Appium] Removing session f1dbcd92-fa13-4fc7-a9fd-e6a82b55f9e7 from our master session list
[2019-01-29 01:04:20][AndroidDriver] Shutting down Android driver

Jan 29 2019 UPDATE II: After a couple of trial & error, I found the root cause is the driver.currentActivity() after sleep. I am getting this Exception. Because our framework caught this, it sent the shut down signal to Appium.

org.openqa.selenium.WebDriverException: java.net.SocketException: Software caused connection abort: recv failed
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'localhost', ip: '', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_192'
Driver info: driver.version: AndroidDriver
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:233)

This Exception only happens when I do driver.currentActivity() after wait for 10 seconds. My goal is to let script wait until it sees another activity. Currently my workaround is this:

int counter = 0;
while(oDriver.currentActivity().contains("someActivity")) {
    Thread.sleep(1000);
    counter++;
    if ( counter >= 10 ) break;
}
if (oDriver.currentActivity().contains("someActivity"))
    System.out.println("Reached");

回答1:


Here is the correct answer to this question.

capabilities.setCapability("newCommandTimeout", 300);

Thanks @Rajesh Chaudhary.

I will create a separate question regarding exceptions encountered during driver.currentActivity().



来源:https://stackoverflow.com/questions/54346747/appium-server-automatically-quit-session-while-waiting

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!