Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Mar 20, 2024
1 parent 7498bba commit efe5404
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 60 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ cov:

build:
rm -fr dist
poetry build
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
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`可以看到连接上的设备。
Expand Down Expand Up @@ -1468,8 +1466,8 @@ for elem in d.xpath("//android.widget.TextView").all():
点击查看[其他XPath常见用法](XPATH.md)
### Screenrecord
视频录制
### Screenrecord (Deprecated)
视频录制(废弃)
这里没有使用手机中自带的screenrecord命令,是通过获取手机图片合成视频的方法,所以需要安装一些其他的依赖,如imageio, imageio-ffmpeg, numpy等
因为有些依赖比较大,推荐使用镜像安装。直接运行下面的命令即可。
Expand All @@ -1491,7 +1489,7 @@ d.screenrecord.stop() # 停止录制后,output.mp4文件才能打开
录制的时候也可以指定fps(当前是20),这个值是率低于minicap输出图片的速度,感觉已经很好了,不建议你修改。
### Image match
### Image match (3.x开始移除该功能)
图像匹配,在使用这个功能之前你需要先把依赖安装上
```bash
Expand Down Expand Up @@ -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` (会拖慢自动化的执行速度并且还会降低稳定性)
Expand Down Expand Up @@ -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 所有优秀测试框架的集合,包罗万象
Expand Down
36 changes: 0 additions & 36 deletions setup.cfg

This file was deleted.

1 change: 0 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/test_screenrecord.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
5 changes: 0 additions & 5 deletions tests/test_session.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
5 changes: 3 additions & 2 deletions tests/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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")
Expand Down Expand Up @@ -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'

Expand Down
1 change: 0 additions & 1 deletion tests/test_swipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 0 additions & 5 deletions tests/test_xpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit efe5404

Please sign in to comment.