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

查看:38
本文介绍了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天全站免登陆