0_uiautomator2与atx环境安装与初始化

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sileixinhua/article/details/80800608

uiautomator2


uiautomator2的介绍,包括环境的安装,设备初始化,定位元素,测试demo

github项目地址

https://github.com/openatx/uiautomator2

https://www.cnblogs.com/fnng/p/8486863.html

uiautomator2的缺点:

1、测试脚本只能使用Java语言。

2、测试脚本必须每次被上传到设备上运行。 我们希望测试能够用一个更脚本化的语言,例如Python编写,同时可以每次所见即所得地修改测试、运行测试。

安装:

首先需要安装abd,并加入到环境变量中。

https://blog.csdn.net/L_201607/article/details/78150107

推荐直接安装android stdio开发环境,自动安装adb等一系列安卓开发等相关测试工具。

然后安装uiautomator2

pip install --pre uiautomator2

pip install pillow

初始化,在手机上安装设备端程序

运行以下代码,则自动安装设备端程序

python -m uiautomator2 init

但是报如下错误

C:\Users\Administrator.PC-20170907TLUD>python -m uiautomator2 init
error: could not install *smartsocket* listener: cannot bind to 127.0.0.1:5037: 通常每个套接字地址(协议/网络地址/端口)只允许使用一次。 (10048)
could not read ok from ADB Server
* failed to start daemon *
error: cannot connect to daemon
Traceback (most recent call last):
  File "C:\Users\Administrator.PC-20170907TLUD\AppData\Local\Programs\Python\Python35\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\Administrator.PC-20170907TLUD\AppData\Local\Programs\Python\Python35\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\Administrator.PC-20170907TLUD\AppData\Local\Programs\Python\Python35\lib\site-packages\uiautomator2\__main__.py", line 356, in <module>
    main()
  File "C:\Users\Administrator.PC-20170907TLUD\AppData\Local\Programs\Python\Python35\lib\site-packages\uiautomator2\__main__.py", line 352, in main
    fire.Fire(MyFire)
  File "C:\Users\Administrator.PC-20170907TLUD\AppData\Local\Programs\Python\Python35\lib\site-packages\fire\core.py", line 127, in Fire
    component_trace = _Fire(component, args, context, name)
  File "C:\Users\Administrator.PC-20170907TLUD\AppData\Local\Programs\Python\Python35\lib\site-packages\fire\core.py", line 366, in _Fire
    component, remaining_args)
  File "C:\Users\Administrator.PC-20170907TLUD\AppData\Local\Programs\Python\Python35\lib\site-packages\fire\core.py", line 542, in _CallCallable
    result = fn(*varargs, **kwargs)
  File "C:\Users\Administrator.PC-20170907TLUD\AppData\Local\Programs\Python\Python35\lib\site-packages\uiautomator2\__main__.py", line 261, in init
    output = subprocess.check_output(['adb', 'devices'])
  File "C:\Users\Administrator.PC-20170907TLUD\AppData\Local\Programs\Python\Python35\lib\subprocess.py", line 316, in check_output
    **kwargs).stdout
  File "C:\Users\Administrator.PC-20170907TLUD\AppData\Local\Programs\Python\Python35\lib\subprocess.py", line 398, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['adb', 'devices']' returned non-zero exit status 1

以上错误是表明端口5037被占用,则查看5037端口有哪些应用占用

netstat  -ano | findstr "5037"

结果显示

C:\Users\Administrator.PC-20170907TLUD>netstat  -ano | findstr "5037"
  TCP    127.0.0.1:5037         0.0.0.0:0              LISTENING       23556
  TCP    127.0.0.1:5037         127.0.0.1:10735        TIME_WAIT       0
  TCP    127.0.0.1:5037         127.0.0.1:10736        TIME_WAIT       0
  TCP    127.0.0.1:5037         127.0.0.1:10737        TIME_WAIT       0
  TCP    127.0.0.1:5037         127.0.0.1:10738        TIME_WAIT       0
  TCP    127.0.0.1:5037         127.0.0.1:10740        TIME_WAIT       0
  TCP    127.0.0.1:5037         127.0.0.1:10746        TIME_WAIT       0
  TCP    127.0.0.1:5037         127.0.0.1:10747        TIME_WAIT       0
  TCP    127.0.0.1:5037         127.0.0.1:10750        TIME_WAIT       0
  TCP    127.0.0.1:5037         127.0.0.1:10751        TIME_WAIT       0
  TCP    127.0.0.1:5037         127.0.0.1:10752        TIME_WAIT       0
  TCP    127.0.0.1:5037         127.0.0.1:10753        TIME_WAIT       0
  TCP    127.0.0.1:5037         127.0.0.1:10754        TIME_WAIT       0
  TCP    127.0.0.1:5037         127.0.0.1:10755        TIME_WAIT       0
  TCP    127.0.0.1:5037         127.0.0.1:10756        TIME_WAIT       0
  TCP    127.0.0.1:5037         127.0.0.1:10757        TIME_WAIT       0
  TCP    127.0.0.1:5037         127.0.0.1:10762        TIME_WAIT       0
  TCP    127.0.0.1:5037         127.0.0.1:10769        TIME_WAIT       0
  TCP    127.0.0.1:5037         127.0.0.1:10808        TIME_WAIT       0
  TCP    127.0.0.1:5037         127.0.0.1:10809        TIME_WAIT       0
  TCP    127.0.0.1:5037         127.0.0.1:10810        TIME_WAIT       0
  TCP    127.0.0.1:5037         127.0.0.1:10811        TIME_WAIT       0
  TCP    127.0.0.1:5037         127.0.0.1:10814        TIME_WAIT       0
  TCP    127.0.0.1:5037         127.0.0.1:10815        TIME_WAIT       0
  TCP    127.0.0.1:5037         127.0.0.1:10822        TIME_WAIT       0
  TCP    127.0.0.1:5037         127.0.0.1:10823        TIME_WAIT       0

则继续查看2356是什么程序

tasklist    | findstr "23556"

结果显示

360MobileLoader.exe          23556 Console                    1     23,416 K

然后去任务管理器结束360MobileLoader.exe

再次运行初始化代码

python -m uiautomator2 init

显示结果为如下所示

C:\Users\Administrator.PC-20170907TLUD>tasklist    | findstr "23556"
360MobileLoader.exe          23556 Console                    1     23,416 K

C:\Users\Administrator.PC-20170907TLUD>python -m uiautomator2 init
2018-06-13 23:21:22,059 - __main__.py:269 - INFO - Detect pluged devices: ['CB5A2631U9']
2018-06-13 23:21:22,059 - __main__.py:286 - INFO - Device(CB5A2631U9) initialing ...
minicap.so |################################| 21.8K / 21.8K
[?25h2018-06-13 23:21:23,699 - __main__.py:113 - INFO - install minicap
minicap |################################| 566.5K / 566.5K
[?25h2018-06-13 23:21:25,233 - __main__.py:120 - INFO - install minitouch
minitouch |################################| 33.8K / 33.8K
[?25h2018-06-13 23:21:26,881 - __main__.py:143 - INFO - app-uiautomator.apk(1.1.0) installing ...
app-uiautomator.apk |################################| 1.7M / 1.7M.7M
[?25h2018-06-13 23:21:38,488 - __main__.py:148 - INFO - app-uiautomator-test.apk installing ...
app-uiautomator-test.apk |################################| 964.2K / 964.2K
[?25h2018-06-13 23:21:48,813 - __main__.py:189 - INFO - atx-agent(0.3.3) is installing, please be patient
atx-agent_0.3.3_linux_armv7.tar.gz |################################| 3.3M / 3.3M.3M
[?25h2018-06-13 23:21:57,529 - __main__.py:212 - INFO - launch atx-agent daemon
2018-06-13 23:21:59,499 - __main__.py:228 - INFO - atx-agent output: server started, listening on 192.168.3.13:7912
2018-06-13 23:22:00,415 - __main__.py:232 - INFO - success

uiautomator2与atx的关系简介

https://testerhome.com/topics/10881


移动端设备也可以用WIFI网络链接电脑

import uiautomator2 as u2

d = u2.connect('192.168.31.234')
print(d.info)

但是必要要在同一WIFI环境下才可以,上面代码是验证是否WIFI连接上的代码,IP地址为192.168.31.234


atx

作者自述
https://testerhome.com/topics/11546

github项目地址

https://github.com/openatx/atx-agent

运行再Android手机上的http服务器,旨在希望通过Wifi控制手机,完成手机的自动化功能。

安装atx

前提要安装好GO环境

运行如下代码安装atx

go get -v github.com/openatx/atx-server

结果如下所示

github.com/openatx/atx-server (download)
github.com/codeskyblue/heartbeat (download)
github.com/codeskyblue/realip (download)
github.com/mattn/go-isatty (download)
github.com/openatx/androidutils (download)
github.com/openatx/atx-server/vendor/github.com/alecthomas/template/parse
github.com/codeskyblue/heartbeat/vendor/github.com/pkg/errors
github.com/openatx/atx-server/vendor/github.com/codeskyblue/realip
github.com/openatx/atx-server/vendor/github.com/codeskyblue/dingrobot
github.com/openatx/atx-server/vendor/golang.org/x/sys/windows
github.com/openatx/atx-server/vendor/github.com/gorilla/mux
github.com/openatx/atx-server/vendor/github.com/alecthomas/units
github.com/codeskyblue/realip
github.com/openatx/atx-server/vendor/github.com/gorilla/websocket
github.com/openatx/atx-server/vendor/github.com/mash/go-accesslog
github.com/mattn/go-isatty
github.com/codeskyblue/heartbeat
github.com/openatx/androidutils/vendor/github.com/kballard/go-shellquote
github.com/openatx/atx-server/vendor/golang.org/x/net/context
github.com/openatx/atx-server/vendor/github.com/hailocab/go-hostpool
github.com/openatx/androidutils
github.com/openatx/atx-server/vendor/github.com/alecthomas/template
github.com/openatx/atx-server/vendor/github.com/opentracing/opentracing-go/log
github.com/openatx/atx-server/vendor/golang.org/x/crypto/pbkdf2
github.com/openatx/atx-server/vendor/github.com/cenkalti/backoff
github.com/openatx/atx-server/vendor/github.com/opentracing/opentracing-go
github.com/openatx/atx-server/vendor/gopkg.in/fatih/pool.v2
github.com/openatx/atx-server/vendor/gopkg.in/gorethink/gorethink.v4/encoding
github.com/openatx/atx-server/vendor/github.com/koding/websocketproxy
github.com/openatx/atx-server/vendor/github.com/golang/protobuf/proto
github.com/openatx/atx-server/proto
github.com/openatx/atx-server/vendor/gopkg.in/gorethink/gorethink.v4/types
github.com/openatx/atx-server/vendor/github.com/opentracing/opentracing-go/ext
github.com/openatx/atx-server/vendor/github.com/alecthomas/kingpin
github.com/openatx/atx-server/vendor/golang.org/x/crypto/ssh/terminal
github.com/openatx/atx-server/vendor/gopkg.in/gorethink/gorethink.v4/ql2
github.com/openatx/atx-server/vendor/github.com/sirupsen/logrus
github.com/openatx/atx-server/vendor/github.com/codeskyblue/inforus
github.com/openatx/atx-server/vendor/gopkg.in/gorethink/gorethink.v4
github.com/openatx/atx-server

build atx-server 和 启动atx-server

只下载好了atx还不能运行,需要用go build的以下才可以使用

打开本地go文件夹,找到atx-server

我的如下所示

C:\Users\Administrator.PC-20170907TLUD\go\pkg\windows_amd64\github.com\openatx\atx-server

如果go build提示错误如下所示

C:\Users\Administrator.PC-20170907TLUD\go\pkg\windows_amd64\github.com\openatx\atx-server>go build
can't load package: package .: no Go files in C:\Users\Administrator.PC-20170907TLUD\go\pkg\windows_amd64\github.com\openatx\atx-server

则去以下github站点

https://github.com/golang/crypto

https://github.com/golang/sys

https://github.com/golang/net

下载文件夹,放入到

C:\Users\Administrator.PC-20170907TLUD\go\src\github.com\openatx\atx-server

再次go build即可。

运行如图下代码,启动atx-server

atx-server --port 8000

打开网页

http://localhost:8000/

下载rethinkdb并设置环境变量

运行如下代码

C:\Users\Administrator.PC-20170907TLUD>rethinkdb --http-port 8090

结果如下所示

C:\Users\Administrator.PC-20170907TLUD>rethinkdb --http-port 8090
In recursion: removing file 'C:\Users\Administrator.PC-20170907TLUD\rethinkdb_data\tmp'
warn: Trying to delete non-existent file 'C:\Users\Administrator.PC-20170907TLUD\rethinkdb_data\tmp'
Initializing directory C:\Users\Administrator.PC-20170907TLUD\rethinkdb_data
Running rethinkdb 2.3.6-windows (MSC 190024215)...
Running on 6.2.9200 (Windows 8, Server 2012)
Loading data from directory C:\Users\Administrator.PC-20170907TLUD\rethinkdb_data
Listening for intracluster connections on port 29015
Listening for client driver connections on port 28015
Listening for administrative HTTP connections on port 8090
Listening on cluster address: 127.0.0.1
Listening on driver address: 127.0.0.1
Listening on http address: 127.0.0.1
To fully expose RethinkDB on the network, bind to all addresses by running rethinkdb with the `--bind all` command line option.
Server ready, "PC_20170907TLUD_nmd" c68107b4-0cdd-43fc-bb98-84c25935af87

错误:atx-agent页面显示出来,但是没有手机显示

环境正确安装,手机也装了u2,atx-agent也开启了,页面也显示正常,就是没有手机显示出来。

最后找了一圈,发现问题是出现在

python -m uiautomator2 init 192.168.3.4:8000

上面的ip地址为PC机在WLAN中的IP地址,此处不可以填为手机的地址

猜你喜欢

转载自blog.csdn.net/sileixinhua/article/details/80800608