AirtestProject / Airtest

UI Automation Framework for Games and Apps
http://airtest.netease.com/
Apache License 2.0
8.2k stars 1.29k forks source link

connect_device. Device not ready #345

Closed chelovekley closed 5 years ago

chelovekley commented 5 years ago

When using the connect_device("Android:///127.0.0.1:5037") command, the device is not connected

[DEBUG][Start debugging...]
C:\AirtestIDE20\airtest\core\android\static\adb\windows\adb.exe devices
C:\AirtestIDE20\airtest\core\android\static\adb\windows\adb.exe devices
C:\AirtestIDE20\airtest\core\android\static\adb\windows\adb.exe -s ce0117113c62108d0c wait-for-device
C:\AirtestIDE20\airtest\core\android\static\adb\windows\adb.exe -s ce0117113c62108d0c shell getprop ro.build.version.sdk
C:\AirtestIDE20\airtest\core\android\static\adb\windows\adb.exe -s ce0117113c62108d0c forward --no-rebind tcp:17767 tcp:5001
[rpc]connected
C:\AirtestIDE20\airtest\core\android\static\adb\windows\adb.exe -s 127.0.0.1:5037 get-state
C:\AirtestIDE20\airtest\core\android\static\adb\windows\adb.exe -s 127.0.0.1:5037 connect 127.0.0.1:5037
failed to connect to 127.0.0.1:5037

C:\AirtestIDE20\airtest\core\android\static\adb\windows\adb.exe -s 127.0.0.1:5037 wait-for-device
Traceback (most recent call last):
  File "app\widgets\code_runner\run_manager.py", line 206, in my_exec
  File "<string>", line 17, in <module>
  File "airtest\core\api.py", line 62, in connect_device
  File "airtest\core\api.py", line 32, in init_device
  File "airtest\core\android\android.py", line 39, in __init__
  File "airtest\core\android\adb.py", line 297, in wait_for_device
airtest.core.error.DeviceConnectionError: 'device not ready'

Expected behavior The device does not connect

Screenshots If applicable, add screenshots to help explain your problem.

python version: python3.6

airtest version: 1.2.0

Smartphone (please complete the following information):

chelovekley commented 5 years ago

But if I use connect_device ("Android: ///"), then the code initializes well, but does not connect

[rpc]connected
C:\AirtestIDE20\airtest\core\android\static\adb\windows\adb.exe devices
C:\AirtestIDE20\airtest\core\android\static\adb\windows\adb.exe devices
C:\AirtestIDE20\airtest\core\android\static\adb\windows\adb.exe -s ce0117113c62108d0c wait-for-device
C:\AirtestIDE20\airtest\core\android\static\adb\windows\adb.exe -s ce0117113c62108d0c shell getprop ro.build.version.sdk
Device:ce0117113c62108d0c updated <airtest.core.android.android.Android object at 0x0000028D4A636198> -> <airtest.core.android.android.Android object at 0x0000028D4A6EDA90>

[DEBUG][End debugging....]

image

EraChen233 commented 5 years ago

Here is the detail of device argument http://airtest.netease.com/docs/en/1_online_help/running_scripts.html#about-the-device-argument

What do you mean about " the code initializes well, but does not connect".

image

chelovekley commented 5 years ago

Yes, I'm sorry, I did not put it correctly.

I meant that the code that comes after the device is connected does not play.

Maybe I do not correctly imagine how this should work. But I think that after connecting the device, all the same should happen if I myself pressed the "connect" button in the "Mobile phone connection" section. That is, a screen with the device's desktop should appear and the hierarchy of my application will appear in the "poco assistant"

But now this does not happen and the code written for "Poco" does not want to be executed, since it does not find a single element.

Meteorix commented 5 years ago

@chelovekley in AirtestIDE, you do need to use connect_device api. Just leave the initial code generated when you new a file.

chelovekley commented 5 years ago

@Meteorix I do not quite understand what source code you are talking about. image

chelovekley commented 5 years ago

@Meteorix Do you mean it? http://airtest.netease.com/docs/en/1_online_help/running_scripts.html#running-scripts-using-the-command-line

chelovekley commented 5 years ago

I used the command: airtest run №3.1.air --device Android: /// ce0117113c62108d0c --log log /

And after the part is executed, an error is issued "[WinError 10054] An existing connection was forcibly closed by the remote host"

Meteorix commented 5 years ago
--device Android:///ce0117113c62108d0c
chelovekley commented 5 years ago

@Meteorix Yes i use it

But my test written in poco does not run from the console.

ERROR: runTest (airtest.cli.runner.AirtestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "c:\python\python36\lib\site-packages\airtest\cli\runner.py", line 65, in runTest
    six.reraise(*sys.exc_info())
  File "c:\python\python36\lib\site-packages\six.py", line 693, in reraise
    raise value
  File "c:\python\python36\lib\site-packages\airtest\cli\runner.py", line 61, in runTest
    exec(compile(code.encode("utf-8"), pyfilepath, 'exec'), self.scope)
  File "C:\Users\wazzapps_user\№3.1.air\№3.1.py", line 28, in <module>
    TutorLop_1=poco('tutorHand').attr('visible')
  File "c:\python\python36\lib\site-packages\poco\proxy.py", line 39, in wrapped
    return func(self, *args, **kwargs)
  File "c:\python\python36\lib\site-packages\poco\proxy.py", line 734, in attr
    nodes = self._do_query(multiple=False)
  File "c:\python\python36\lib\site-packages\poco\proxy.py", line 872, in _do_query
    self._nodes = self.poco.agent.hierarchy.select(self.query, multiple)
  File "c:\python\python36\lib\site-packages\poco\freezeui\hierarchy.py", line 90, in select
    return self.selector.select(query, multiple)
  File "c:\python\python36\lib\site-packages\poco\sdk\Selector.py", line 78, in select
    return self.selectImpl(cond, multiple, self.getRoot(), 9999, True, True)
  File "c:\python\python36\lib\site-packages\poco\sdk\Selector.py", line 71, in getRoot
    return self.dumper.getRoot()
  File "c:\python\python36\lib\site-packages\poco\freezeui\hierarchy.py", line 35, in getRoot
    root = Node(self.dumpHierarchy())
  File "c:\python\python36\lib\site-packages\poco\utils\simplerpc\utils.py", line 12, in new_func
    cb = func(*args, **kwargs)
  File "c:\python\python36\lib\site-packages\poco\drivers\std\dumper.py", line 13, in dumpHierarchy
    return self.rpcclient.call("Dump", onlyVisibleNode)
  File "c:\python\python36\lib\site-packages\poco\utils\simplerpc\rpcclient.py", line 58, in call
    self.conn.send(msg)
  File "c:\python\python36\lib\site-packages\poco\utils\simplerpc\transport\tcp\main.py", line 32, in send
    self.c.send(msg_bytes)
  File "c:\python\python36\lib\site-packages\poco\utils\simplerpc\transport\tcp\safetcp.py", line 32, in send
    sent = self.sock.send(msg[totalsent:])
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host 

The part of the code that uses the airtest API works, but the next one is not executed with poco.

Added in Python pip install airtest and pip install uipoco

yimelia commented 5 years ago

http://airtest.netease.com/docs/en/3_faq/android_connection_new.html#adb-version-conflict-in-airtest

Coolwhitex commented 5 years ago

What about such a mistake and Shows adb unavailable

[05:52:49][DEBUG] C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\airtest\core\android\static\adb\windows\adb.exe -P 5037 -s 1447b941 wait-for-device Traceback (most recent call last): File "D:/python项目/efuzhou/e_fuzhou.py", line 186, in e.parse_enterprise_demands() File "D:/python项目/efuzhou/e_fuzhou.py", line 81, in parse_enterprise_demands connect_device("Android://127.0.0.1:5037/1447b941") File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\airtest\core\api.py", line 63, in connect_device dev = init_device(platform, uuid, params) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\airtest\core\api.py", line 33, in init_device dev = cls(uuid, kwargs) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\airtest\core\android\android.py", line 39, in init self.adb.wait_for_device() File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\airtest\core\android\adb.py", line 297, in wait_for_device raise DeviceConnectionError("device not ready") airtest.core.error.DeviceConnectionError: 'device not ready'

yimelia commented 5 years ago

@Coolwhitex 是否是在IDE中运行?是否使用了本地自定义的python.exe路径?

Coolwhitex commented 5 years ago

@yimelia 知道了, 是ide和python不能同时运行 不然就会报adb停止运行

yimelia commented 5 years ago

@Coolwhitex 如果是win7系统,因为目前使用的新版adb在win7下有点问题,所以ide会自动替换一个旧版本的ADB,如果同时在用python.exe跑,会因为版本不同造成冲突,统一使用同一个版本就可以了。 http://airtest.netease.com/docs/cn/2_device_connection/2_android_faq.html#airtestadb

a3247858 commented 5 years ago

为什么我的oppo手机在pycharm上用connect_device(**)连接设备,进入游戏内会在运行脚本 会一直弹[rpc]connect 连接不上,在游戏登录界面就能连接上

yimelia commented 5 years ago

@a3247858 如果不是本issue相同问题,建议另开一个帖子询问。 你的这个问题可能是因为,游戏接入了poco之后,需要等到游戏内创建了挂载着poco的节点之后,外部才能连上游戏内部的poco service。所以有的项目在刚启动游戏时连不上,需要进入到某个场景后才能连。

AxelHu commented 4 years ago

@yimelia 你好,我也遇到相同问题了,不知道在这个issue里问是否合适。 大概是这样一个状况,PC系统是win10-2004,python使用的是3.7.7,AirTestIDE使用的是官网下载的最新版本的,命令行工具使用的是pip安装的最新版,测试用的手机是pixel4 xl 安卓10。 我是在局域网通过 adb connect ip:port 连接的手机(port是5555),经过测试发现无论是命令行工具还是AirTestIDE,init_device("Android")和connect_device("android:///")都可以正确连接到手机并运行后面的测试代码,但connect_device("android://ip:port/serialno")这个不行(ip,port,serialno我都输入了的),提示信息是和这个issue一样的Device not ready。 想了解下具体是什么原因,有没有解决办法。

Coolwhitex commented 4 years ago

@yimelia 你好,我也遇到相同问题了,不知道在这个issue里问是否合适。 大概是这样一个状况,PC系统是win10-2004,python使用的是3.7.7,AirTestIDE使用的是官网下载的最新版本的,命令行工具使用的是pip安装的最新版,测试用的手机是pixel4 xl 安卓10。 我是在局域网通过 adb connect ip:port 连接的手机(port是5555),经过测试发现无论是命令行工具还是AirTestIDE,init_device("Android")和connect_device("android:///")都可以正确连接到手机并运行后面的测试代码,但connect_device("android://ip:port/serialno")这个不行(ip,port,serialno我都输入了的),提示信息是和这个issue一样的Device not ready。 想了解下具体是什么原因,有没有解决办法。

你好 你可以看一下 IDE和Python是不能同时运行的 你运行Python的时候 要把IDE先给停掉 然后再试一下

AxelHu commented 4 years ago

你好 你可以看一下 IDE和Python是不能同时运行的 你运行Python的时候 要把IDE先给停掉 然后再试一下

这个我确定的,不是因为这个原因,我搜到这个issue的时候都看了一遍,而且我测试结果是文档里其他两个方法都可以连接,就IP的那个有问题。

AxelHu commented 4 years ago

这么久都没有回复么...原因我大概知道了,昨天花了一个下午看了一遍python语法,检查了一下源码... 在使用connect_device("android://ip:port/serialno")的时候,所有adb指令都会用使用adb -H ip -P port -s serial xxx这条。 我测试了一下 adb -s ip:port xxx是没有问题的,但adb -H ip -P port xxx会卡住。 按照adb的帮助文本来看,这两条应该没有什么本质上的区别,表现应该是一样的才对。 我在google上提了一条adb的bug,有兴趣可以关注一下 https://issuetracker.google.com/issues/160916909

yimelia commented 4 years ago

@AxelHu device not ready有非常多种可能性,你的问题和这个题主是不一样的,建议另外开新帖。 从你现有的问题描述来看,暂时我没有办法看出是什么原因导致的,建议可以补充更多具体一点的参数和实际输出内容

init_device("Android")和connect_device("android:///")都可以正确连接到手机并运行后面的测试代码

如果这样写能够连上,可以再观察下命令行里在执行指令时自动生成了什么语句,对比一下你用connect_devce时的语句里的参数?

AxelHu commented 4 years ago

@yimelia 嗯,我一会新开一个issue吧,具体原因我在上面那条回复里讲了。使用adb -s选项输入ip是正常运行的,这个也是文档里讲的前两种连接方式使用的指令,第三种使用了adb -H -P选项,这个测试过会卡住。 我是直接用命令行测试的,所以其实不是airtest的问题,是adb的问题,所以我给谷歌提了那条adb的issue。

yimelia commented 4 years ago

按照你的描述,connect_device("android:///")也不应该能连上设备才对,能贴出具体的log对比一下吗?

AxelHu commented 4 years ago

我新开issue讲吧,在编辑中,稍等