From efe540458bd569c0490796029745892b54cdb8dd Mon Sep 17 00:00:00 2001 From: codeskyblue Date: Wed, 20 Mar 2024 14:41:09 +0800 Subject: [PATCH] fix tests --- Makefile | 8 +++++++- README.md | 18 +++++++++++------- setup.cfg | 36 ------------------------------------ tests/conftest.py | 1 - tests/test_screenrecord.py | 4 ++-- tests/test_session.py | 5 ----- tests/test_simple.py | 5 +++-- tests/test_swipe.py | 1 - tests/test_xpath.py | 5 ----- 9 files changed, 23 insertions(+), 60 deletions(-) delete mode 100644 setup.cfg diff --git a/Makefile b/Makefile index bf0ab5e8..a57f620e 100644 --- a/Makefile +++ b/Makefile @@ -11,4 +11,10 @@ cov: build: rm -fr dist - poetry build \ No newline at end of file + poetry build + +init: + if [ ! -f "ApiDemos-debug.apk" ]; then \ + wget https://github.com/appium/appium/raw/master/packages/appium/sample-code/apps/ApiDemos-debug.apk; \ + fi + poetry run python -m adbutils -i ./ApiDemos-debug.apk \ No newline at end of file diff --git a/README.md b/README.md index a0c91681..c266b608 100644 --- a/README.md +++ b/README.md @@ -36,9 +36,7 @@ QQ交流群: 815453846 ## Requirements - Android版本 4.4+ -- Python 3.6+ (社区反馈3.8.0不支持, 但是3.8.2支持) - ->如果用python2的pip安装,会安装本库的老版本0.2.3;如果用python3.5的pip安装,会安装本库的老版本0.3.3;两者均已经不会再维护;PYPI上的最近版本是这个:https://pypi.org/project/uiautomator2/ +- Python 3.8+ ## QUICK START 先准备一台(不要两台)开启了`开发者选项`的安卓手机,连接上电脑,确保执行`adb devices`可以看到连接上的设备。 @@ -1468,8 +1466,8 @@ for elem in d.xpath("//android.widget.TextView").all(): 点击查看[其他XPath常见用法](XPATH.md) -### Screenrecord -视频录制 +### Screenrecord (Deprecated) +视频录制(废弃) 这里没有使用手机中自带的screenrecord命令,是通过获取手机图片合成视频的方法,所以需要安装一些其他的依赖,如imageio, imageio-ffmpeg, numpy等 因为有些依赖比较大,推荐使用镜像安装。直接运行下面的命令即可。 @@ -1491,7 +1489,7 @@ d.screenrecord.stop() # 停止录制后,output.mp4文件才能打开 录制的时候也可以指定fps(当前是20),这个值是率低于minicap输出图片的速度,感觉已经很好了,不建议你修改。 -### Image match +### Image match (3.x开始移除该功能) 图像匹配,在使用这个功能之前你需要先把依赖安装上 ```bash @@ -1564,6 +1562,12 @@ https://www.cnblogs.com/insist8089/p/6898181.html ## [CHANGELOG (generated by pbr)](CHANGELOG) 重大更新 +- 3.x + + 最低Python从3.5改为3.8 + 使用poetry代替pbr管理包依赖 + 移除图片匹配和视频录制功能 + - 1.0.0 移除 `d.watchers.watched` (会拖慢自动化的执行速度并且还会降低稳定性) @@ -1592,7 +1596,7 @@ https://www.cnblogs.com/insist8089/p/6898181.html Other [contributors](../../graphs/contributors) -## 其他优秀的项目 +## 其他优秀的项目 (好久没更新了,去谷歌吧) - [google/mobly](https://github.com/google/mobly) 谷歌内部的测试框架,虽然我不太懂,但是感觉很好用 - https://www.appetizer.io/ 包含一个很好用的IDE,快速编写脚本,也可以插桩采集性能。 - https://github.com/atinfo/awesome-test-automation 所有优秀测试框架的集合,包罗万象 diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index cf1f5cb9..00000000 --- a/setup.cfg +++ /dev/null @@ -1,36 +0,0 @@ -[metadata] -name = uiautomator2 -author = codeskyblue -author_email = codeskyblue@gmail.com -summary = Python Wrapper for Google Android UiAutomator2 test tool -license = MIT -description_file = ABOUT.rst -home_page = https://github.com/openatx/uiautomator2 -# all classifier can be found in https://pypi.python.org/pypi?%3Aaction=list_classifiers -classifier = - Development Status :: 4 - Beta - Environment :: Console - Intended Audience :: Developers - Operating System :: POSIX - Programming Language :: Python :: 3 - Topic :: Software Development :: Libraries :: Python Modules - Topic :: Software Development :: Testing - -[files] -packages = - uiautomator2 - -# support: pip3 install uiautomator2[image] -[extras] -image = - scikit-image - imutils - findit - imageio>=2.8.0,<3.0 - imageio-ffmpeg>=0.4.2,<1.0 - websocket_client>=0.57.0,<1.0 - -[entry_points] -# https://docs.openstack.org/pbr/3.1.1/#entry-points -console_scripts = - uiautomator2 = uiautomator2.__main__:main diff --git a/tests/conftest.py b/tests/conftest.py index a42336da..e16caba2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,7 +9,6 @@ @pytest.fixture(scope="module") def d(device): _d = device - #_d = u2.connect() _d.settings['operation_delay'] = (0.2, 0.2) _d.settings['operation_delay_methods'] = ['click', 'swipe'] return _d diff --git a/tests/test_screenrecord.py b/tests/test_screenrecord.py index b681c87d..7c9a2465 100644 --- a/tests/test_screenrecord.py +++ b/tests/test_screenrecord.py @@ -3,14 +3,14 @@ import time -import imageio import pytest import uiautomator2 as u2 -# @pytest.mark.skip("Too long") +@pytest.mark.skip("deprecated") def test_screenrecord(d: u2.Device): + import imageio with pytest.raises(RuntimeError): d.screenrecord.stop() diff --git a/tests/test_session.py b/tests/test_session.py index f839849c..68b00f43 100644 --- a/tests/test_session.py +++ b/tests/test_session.py @@ -1,20 +1,15 @@ # coding: utf-8 # -from collections import namedtuple - def test_session(sess): sess.wlan_ip - # sess.widget sess.watcher - sess.image sess.jsonrpc sess.open_identify sess.shell sess.set_new_command_timeout sess.settings - sess.taobao sess.xpath diff --git a/tests/test_simple.py b/tests/test_simple.py index a3e15e96..04f9b7fe 100644 --- a/tests/test_simple.py +++ b/tests/test_simple.py @@ -87,7 +87,7 @@ def test_get_text(sess): d = sess text = d(resourceId="android:id/list").child( className="android.widget.TextView", instance=2).get_text() - assert text == "App" + assert text == "Animation" def test_xpath(sess): @@ -96,7 +96,7 @@ def test_xpath(sess): assert len(d.xpath("//*[@text='Media']").all()) == 1 assert len(d.xpath("//*[@text='MediaNotExists']").all()) == 0 d.xpath("//*[@text='Media']").click() - assert d.xpath('//*[contains(@text, "Audio")]').wait(5) + assert d.xpath('//*[contains(@text, "VideoView")]').wait(5) @pytest.mark.skip("Need fix") @@ -141,6 +141,7 @@ def test_send_keys(sess): d.xpath("App").click() d.xpath("Search").click() d.xpath('//*[@text="Invoke Search"]').click() + d.xpath('@io.appium.android.apis:id/txt_query_prefill').click() d.send_keys("hello", clear=True) assert d.xpath('io.appium.android.apis:id/txt_query_prefill').info['text'] == 'hello' diff --git a/tests/test_swipe.py b/tests/test_swipe.py index b10c344e..bee1afff 100644 --- a/tests/test_swipe.py +++ b/tests/test_swipe.py @@ -9,7 +9,6 @@ def test_swipe_duration(d: u2.Device): w, h = d.window_size() start = time.time() - d.debug = True d.swipe(w//2, h//2, w-1, h//2, 2.0) duration = time.time() - start assert duration >= 1.5 # actually duration is about 7s in my TT diff --git a/tests/test_xpath.py b/tests/test_xpath.py index 6aa0e1bc..7f5a4bf1 100644 --- a/tests/test_xpath.py +++ b/tests/test_xpath.py @@ -40,11 +40,6 @@ def test_element_all(sess: u2.Session): assert len(app.all()) == 1 assert app.exists - elements = sess.xpath('//*[@resource-id="android:id/list"]/android.widget.TextView').all() - assert len(elements) == 11 - el = elements[0] - assert el.text == 'Accessibility' - def test_watcher(sess: u2.Session, request): sess.xpath.when("App").click()