使用appium python在线调试session不断开真机

本文介绍如何通过调整Appium的desired_caps参数newCommandTimeout,解决在使用Appium+Python进行安卓测试时,因会话过早断开导致无法持续查找元素的问题。作者分享了在调试过程中发现该参数的过程,并提供了具体的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题

用appium+python在线调试安卓测试的时候总是需要从屏幕找元素,然后一一find,这总是需要花时间的,但是没等自己点好复制好,session直接断了,断之后就找不到元素了,很烦。

怎么人家可以?

但是如果是appium的图像界面,他就不会这么快断开,下面就是他的图形化界面。
在这里插入图片描述

所以他一定是有个参数的,我要找找这个参数在哪。
网上找了点文档,没找到。只能自己找了。

查控制台log

于是看appium的log找到了,从控制台这里找了log。
在这里插入图片描述
找到了这个

[BaseDriver] Shutting down because we waited 60 seconds for a command
[Appium] Closing session, cause was 'New Command Timeout of 60 seconds expired. Try customizing the timeout using the 'newCommandTimeout' desired capability'

哦那就明白了。所以想要长时间保持和安卓机的session不断开,设置下desired_caps中的newCommandTimeout,设置长一点就好了。

修改自己的desired-cap,加入参数

from appium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.support.wait import WebDriverWait
import time
from collections import OrderedDict

desired_caps = {
    "platformName": "Android",
    "platformVersion": "9.0.0",
    "deviceName": "PAR_AL00",
    "appPackage": 'com.eg.android.AlipayGphone',
    "appActivity": 'com.eg.android.AlipayGphone.AlipayLogin',
    "resetKeyboard": True,
    "automationName": "UIAutomator2",
	# make session waits for next command much longer, default 60 seconds.
    "newCommandTimeout":10000,
    "noReset": True,
	# disable phone keyboard and send chars in unicode
	"unicodeKeyboard":True,
	"resetKeyboard":True,

}

driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)

就可以了!


2020.08.21更新
昨天使用了newcommand timeout,设置了3600,但是还是在几分钟之内断了连接,我怀疑是有什么bug出现。人家文档中都写明了这个参数。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值