python-3.x - Pytest 和 Tox ADB 连接问题 - 设备未经授权
问题描述
场景:我正在尝试通过在 os.popen() 中使用 shell 命令将 ADB 连接到 Android 手机,作为自动化框架测试的一部分,我能够连接,但“adb 设备”将设备返回为已连接但未经授权,例如代码:
def test_connect_phone(self, phone):
connect_stream = os.popen(f'adb connect {phone.host}:{phone.port}')
print(connect_stream.read())
install_stream = os.popen('adb devices')
output = install_stream.read()
print(output)
assert output
# output
connected to <HOST>:<PORT>
List of devices attached
<HOST>:<PORT> unauthorized
直接从终端运行相同的命令可以工作并且设备已获得授权:
adb connect <HOST>:<PORT>
adb devices
#output
connected to <HOST>:<PORT>
List of devices attached
<HOST>:<PORT> device
注意:我将 tox 用于 pytest,这让我认为这可能是一个环境问题,但在测试中我在运行时看到我的主目录保持不变。任何帮助表示赞赏。
解决方案
找到了解决方案,显然我需要在“adb connect”之后添加 sleep(1),因为设备需要一段时间才能获得授权
推荐阅读
- c# - 是否可以从 C# 中的 Microsoft Identity Manager 获取信息?
- python - 如何通过使用 python selenium 单击链接按钮来访问在新选项卡中打开的元素?
- python - 将 GridSearchCV(或任何其他 Sklearn 对象)输出重定向到文件
- android - 适用于 iOS 和 android 的经典蓝牙包可能吗?
- python - Flask 使用 PyTube Youtube 下载应用程序引发 JSON 序列化错误
- flutter - 如何解决此错误:在 null 上调用了方法“[]”。接收者:null 尝试调用:[]("name")
- sql-server - 数据存在时 SSDT 更新架构
- java - 如何在括号中查找元素
- javascript - 如何设置 Material UI 表头的样式?
- python - 澄清 PyTorch 上的 TorchScripts 和 JIT