折腾:
【未解决】给安卓手机小米9中欢乐大作战的游戏实现自动挂机
期间,为了方便后续调试,还是去安装那个weditor吧:
1 | pip install --upgrade weditor |
1 | pip install --pre weditor |
去试试
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | ➜ autoTestAndroidGameHappyBigBattle pipenv install - U weditor Courtesy Notice: Pipenv found itself running within a virtual environment, so it will automatically use that environment, instead of creating its own for any project. You can set PIPENV_IGNORE_VIRTUALENVS = 1 to force pipenv to ignore that environment and create its own instead. You can set PIPENV_VERBOSITY = - 1 to suppress this warning. Installing - U… WARNING: Invalid requirement, parse error at "'-U'" ✘ Installation Failed ➜ autoTestAndroidGameHappyBigBattle pipenv install - - upgrade weditor Courtesy Notice: Pipenv found itself running within a virtual environment, so it will automatically use that environment, instead of creating its own for any project. You can set PIPENV_IGNORE_VIRTUALENVS = 1 to force pipenv to ignore that environment and create its own instead. You can set PIPENV_VERBOSITY = - 1 to suppress this warning. Installing - - upgrade… WARNING: Invalid requirement, parse error at "'--upgrad'" ✘ Installation Failed ➜ autoTestAndroidGameHappyBigBattle pipenv install weditor Installing weditor… Adding weditor to Pipfile's [packages]…
Pipfile.lock (ae4f88) out of date, updating to ( 78903d )… Locking [dev - packages] dependencies… Locking [packages] dependencies…
Updated Pipfile.lock (ae4f88)! Installing dependencies from Pipfile.lock (ae4f88)…
25 / 25 — 00 : 00 : 05 |
安装后,去看看:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | ➜ autoTestAndroidGameHappyBigBattle pipenv graph weditor==0.3.1 - facebook-wda [required: >=0.3, installed: 0.4.1] - Pillow [required: Any, installed: 6.2.1] - requests [required: >=2.9.1, installed: 2.22.0] - certifi [required: >=2017.4.17, installed: 2019.9.11] - chardet [required: >=3.0.2,<3.1.0, installed: 3.0.4] - idna [required: >=2.5,<2.9, installed: 2.8] - urllib3 [required: >=1.21.1,<1.26,!=1.25.1,!=1.25.0, installed: 1.25.7] - retry [required: Any, installed: 0.9.2] - decorator [required: >=3.4.2, installed: 4.4.1] - py [required: >=1.4.26,<2.0.0, installed: 1.8.0] - six [required: Any, installed: 1.13.0] - logzero [required: Any, installed: 1.5.0] - pillow [required: Any, installed: 6.2.1] - six [required: Any, installed: 1.13.0] - tornado [required: >=4.3, installed: 6.0.3] - uiautomator2 [required: >=1.0, installed: 2.0.0] - adbutils [required: >=0.5.2,<1.0, installed: 0.6.2] - deprecation [required: >=2.0.6,<3.0, installed: 2.0.7] - packaging [required: Any, installed: 19.2] - pyparsing [required: >=2.0.2, installed: 2.4.5] - six [required: Any, installed: 1.13.0] - requests [required: Any, installed: 2.22.0] - certifi [required: >=2017.4.17, installed: 2019.9.11] - chardet [required: >=3.0.2,<3.1.0, installed: 3.0.4] - idna [required: >=2.5,<2.9, installed: 2.8] - urllib3 [required: >=1.21.1,<1.26,!=1.25.1,!=1.25.0, installed: 1.25.7] - retry [required: >=0.9, installed: 0.9.2] - decorator [required: >=3.4.2, installed: 4.4.1] - py [required: >=1.4.26,<2.0.0, installed: 1.8.0] - six [required: Any, installed: 1.13.0] - whichcraft [required: Any, installed: 0.6.1] - Deprecated [required: ~=1.2.6, installed: 1.2.7] - wrapt [required: >=1.10,<2, installed: 1.11.2] - humanize [required: Any, installed: 0.5.1] - logzero [required: ~=1.5, installed: 1.5.0] - lxml [required: >=4.3, installed: 4.4.1] - Pillow [required: Any, installed: 6.2.1] - progress [required: ~=1.3, installed: 1.5] - requests [required: Any, installed: 2.22.0] - certifi [required: >=2017.4.17, installed: 2019.9.11] - chardet [required: >=3.0.2,<3.1.0, installed: 3.0.4] - idna [required: >=2.5,<2.9, installed: 2.8] - urllib3 [required: >=1.21.1,<1.26,!=1.25.1,!=1.25.0, installed: 1.25.7] - retry [required: ~=0.9, installed: 0.9.2] - decorator [required: >=3.4.2, installed: 4.4.1] - py [required: >=1.4.26,<2.0.0, installed: 1.8.0] - six [required: Any, installed: 1.13.0] - whichcraft [required: Any, installed: 0.6.1] |
然后去启动:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | ➜ autoTestAndroidGameHappyBigBattle python - m weditor listening on http: / / 192.168 . 31.12 : 17310 [I 191122 20 : 38 : 19 web: 2246 ] 200 GET / (:: 1 ) 18.05ms [I 191122 20 : 38 : 19 web: 2246 ] 200 GET / static / libs / css / buttons.css (:: 1 ) 18.39ms [I 191122 20 : 38 : 19 web: 2246 ] 200 GET / static / libs / fontawesome / css / font - awesome. min .css (:: 1 ) 5.45ms [I 191122 20 : 38 : 19 web: 2246 ] 200 GET / static / loading.svg (:: 1 ) 243.51ms [I 191122 20 : 38 : 19 web: 2246 ] 200 GET / static / running.svg (:: 1 ) 257.34ms [I 191122 20 : 38 : 19 web: 2246 ] 200 GET / static / style.css?v = 4000e274c1eeda53ea9ec4e51f124faa (:: 1 ) 262.57ms [I 191122 20 : 38 : 20 web: 2246 ] 200 GET / static / ace / ace.js (:: 1 ) 22.74ms [I 191122 20 : 38 : 20 web: 2246 ] 200 GET / static / ace / mode - python.js (:: 1 ) 24.57ms [I 191122 20 : 38 : 20 web: 2246 ] 200 GET / static / libs / vue - 2.5 . 16 / vue.js?v = cbe2b9b2fb6955decf033515d079e44b (:: 1 ) 14.18ms [I 191122 20 : 38 : 20 web: 2246 ] 200 GET / static / js / common.js?v = f1c2d6b24d012c4fc2e22595bd549793 (:: 1 ) 11.82ms [I 191122 20 : 38 : 20 web: 2246 ] 200 GET / static / js / index.js?v = 66bde55ac3879acf69a8ef548473df6b (:: 1 ) 4.07ms [I 191122 20 : 38 : 20 web: 2246 ] 200 GET / cdn.jsdelivr.net / bootstrap.select / 1.12 . 2 / js / bootstrap - select. min .js (:: 1 ) 646.20ms [I 191122 20 : 38 : 20 web: 2246 ] 200 GET / cdn.jsdelivr.net / bootstrap / 3.3 . 7 / js / bootstrap. min .js (:: 1 ) 659.83ms [I 191122 20 : 38 : 20 web: 2246 ] 200 GET / cdn.jsdelivr.net / npm / jstree@ 3.3 . 8 / dist / jstree. min .js (:: 1 ) 316.84ms [I 191122 20 : 38 : 20 web: 2246 ] 200 GET / cdn.jsdelivr.net / npm / jquery@ 3.3 . 1 / dist / jquery. min .js (:: 1 ) 754.59ms [I 191122 20 : 38 : 21 web: 2246 ] 200 GET / static / libs / fontawesome / fonts / fontawesome - webfont.woff2?v = 4.7 . 0 (:: 1 ) 6.31ms [I 191122 20 : 38 : 22 web: 2246 ] 200 GET / api / v1 / version (:: 1 ) 1.13ms [I 191122 20 : 38 : 23 web: 2246 ] 200 GET / favicon.ico (:: 1 ) 1.55ms [I 191122 20 : 38 : 30 web: 2246 ] 200 GET / (:: 1 ) 5.30ms [I 191122 20 : 38 : 30 web: 2246 ] 200 GET / static / libs / css / buttons.css (:: 1 ) 2.49ms [I 191122 20 : 38 : 30 web: 2246 ] 200 GET / static / style.css?v = 4000e274c1eeda53ea9ec4e51f124faa (:: 1 ) 2.14ms [I 191122 20 : 38 : 30 web: 2246 ] 200 GET / static / libs / fontawesome / css / font - awesome. min .css (:: 1 ) 3.91ms [I 191122 20 : 38 : 30 web: 2246 ] 200 GET / cdn.jsdelivr.net / npm / jquery@ 3.3 . 1 / dist / jquery. min .js (:: 1 ) 1.87ms [I 191122 20 : 38 : 30 web: 2246 ] 200 GET / cdn.jsdelivr.net / bootstrap / 3.3 . 7 / js / bootstrap. min .js (:: 1 ) 1.34ms [I 191122 20 : 38 : 30 web: 2246 ] 200 GET / cdn.jsdelivr.net / bootstrap.select / 1.12 . 2 / js / bootstrap - select. min .js (:: 1 ) 1.45ms [I 191122 20 : 38 : 30 web: 2246 ] 200 GET / static / ace / ace.js (:: 1 ) 4.96ms [I 191122 20 : 38 : 30 web: 2246 ] 200 GET / static / ace / mode - python.js (:: 1 ) 1.89ms [I 191122 20 : 38 : 30 web: 2246 ] 200 GET / cdn.jsdelivr.net / npm / jstree@ 3.3 . 8 / dist / jstree. min .js (:: 1 ) 3.17ms [I 191122 20 : 38 : 30 web: 2246 ] 200 GET / static / libs / vue - 2.5 . 16 / vue.js?v = cbe2b9b2fb6955decf033515d079e44b (:: 1 ) 3.33ms [I 191122 20 : 38 : 30 web: 2246 ] 200 GET / static / js / common.js?v = f1c2d6b24d012c4fc2e22595bd549793 (:: 1 ) 1.48ms [I 191122 20 : 38 : 30 web: 2246 ] 200 GET / static / js / index.js?v = 66bde55ac3879acf69a8ef548473df6b (:: 1 ) 2.98ms [I 191122 20 : 38 : 30 web: 2246 ] 200 GET / static / loading.svg (:: 1 ) 1.35ms [I 191122 20 : 38 : 30 web: 2246 ] 200 GET / static / running.svg (:: 1 ) 1.32ms [I 191122 20 : 38 : 32 web: 2246 ] 200 GET / static / libs / fontawesome / fonts / fontawesome - webfont.woff2?v = 4.7 . 0 (:: 1 ) 4.30ms [I 191122 20 : 38 : 32 web: 2246 ] 200 GET / api / v1 / version (:: 1 ) 0.69ms [I 191122 20 : 38 : 34 web: 2246 ] 200 GET / favicon.ico (:: 1 ) 1.72ms ... |

然后输入设备id
1 2 3 | ➜ autoTestAndroidGameHappyBigBattle adb devices List of devices attached 8c8a4d4d device |
8c8a4d4d

weditor的log中出现很多警告:
1 2 3 4 5 6 7 8 9 10 11 | [W 191122 20 : 39 : 45 connectionpool: 748 ] Retrying (Retry(total = 2 , connect = 3 , read = None , redirect = None , status = None )) after connection broken by 'ProtocolError(' Connection aborted. ', RemoteDisconnected(' Remote end closed connection without response '))' : / version [W 191122 20 : 39 : 46 connectionpool: 748 ] Retrying (Retry(total = 1 , connect = 3 , read = None , redirect = None , status = None )) after connection broken by 'ProtocolError(' Connection aborted. ', RemoteDisconnected(' Remote end closed connection without response '))' : / version [W 191122 20 : 39 : 48 connectionpool: 748 ] Retrying (Retry(total = 0 , connect = 3 , read = None , redirect = None , status = None )) after connection broken by 'ProtocolError(' Connection aborted. ', RemoteDisconnected(' Remote end closed connection without response '))' : / version [W 191122 20 : 39 : 49 connectionpool: 748 ] Retrying (Retry(total = 2 , connect = 3 , read = None , redirect = None , status = None )) after connection broken by 'ProtocolError(' Connection aborted. ', RemoteDisconnected(' Remote end closed connection without response '))' : / version [W 191122 20 : 39 : 50 connectionpool: 748 ] Retrying (Retry(total = 1 , connect = 3 , read = None , redirect = None , status = None )) after connection broken by 'ProtocolError(' Connection aborted. ', RemoteDisconnected(' Remote end closed connection without response '))' : / version [W 191122 20 : 39 : 52 connectionpool: 748 ] Retrying (Retry(total = 0 , connect = 3 , read = None , redirect = None , status = None )) after connection broken by 'ProtocolError(' Connection aborted. ', RemoteDisconnected(' Remote end closed connection without response '))' : / version / Users / crifan / .local / share / virtualenvs / autoTestAndroidGameHappyBigBattle - F2NzwZ7Z / lib / python3. 7 / site - packages / uiautomator2 / __init__.py: 177 : RuntimeWarning: start atx - agent ... warnings.warn( "start atx-agent ..." , RuntimeWarning) [W 191122 20 : 39 : 52 connectionpool: 748 ] Retrying (Retry(total = 2 , connect = 3 , read = None , redirect = None , status = None )) after connection broken by 'ProtocolError(' Connection aborted. ', RemoteDisconnected(' Remote end closed connection without response '))' : / version [W 191122 20 : 39 : 53 connectionpool: 748 ] Retrying (Retry(total = 1 , connect = 3 , read = None , redirect = None , status = None )) after connection broken by 'ProtocolError(' Connection aborted. ', RemoteDisconnected(' Remote end closed connection without response '))' : / version [I 191122 20 : 39 : 53 web: 2246 ] 200 POST / api / v1 / connect (:: 1 ) 7625.05ms |


点击 静态 实时 的按钮 多点击几次 就可以界面了。

点击 Dump Hierarchy可以看到节点:

此处感觉有bug,会闪烁:

重新点击了 connect后才正常
点开游戏,可以看到游戏界面了:

去调试看看,貌似页面内元素和按钮,都很难抓到啊

只有大区域的元素
刷新了下页面:

还是不行。