Appium服务器在等待时自动退出会话 [英] Appium server automatically quit session while waiting

查看:1021
本文介绍了Appium服务器在等待时自动退出会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Android平台上的Appium进行自动化.由于某些原因,我需要在测试过程中等待一段时间.但是,如果Appium在4秒钟左右未收到命令,它将自动退出会话.谁能帮我告诉我如何使Appium不退出驱动程序.

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.

我尝试将"newCommandTimeout"添加到功能中,但是它不起作用.

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

capabilities.setCapability("newCommandTimeout", 120000);

Appium版本:v1.9.1

Appium version: v1.9.1

这是会话退出时的appium日志:

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

2019年1月29日更新:

正如大多数人所建议的那样,我尝试将300设置为newCommandTimeout

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

capabilities.setCapability("newCommandTimeout", 300);

会话仍在退出.我使用Thread.sleep(5000)使脚本等待.以下是在Appium中创建会话和关闭会话的日志.已添加时间戳.等待10秒后,会话似乎自动关闭了.

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

2019年1月29日更新II: 经过几次试用和错误,我发现根本原因是睡眠后的driver.currentActivity().我收到此异常.因为我们的框架抓住了这一点,所以它向Appium发送了关闭信号.

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)

仅当我在等待10秒后执行driver.currentActivity()时,才会发生此异常.我的目标是让脚本等到看到其他活动为止.目前,我的解决方法是:

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");

推荐答案

以下是此问题的正确答案.

Here is the correct answer to this question.

capabilities.setCapability("newCommandTimeout", 300);

感谢@Rajesh Chaudhary.

Thanks @Rajesh Chaudhary.

我将针对在driver.currentActivity()期间遇到的异常创建一个单独的问题.

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

这篇关于Appium服务器在等待时自动退出会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆