Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poetry #945

Merged
merged 6 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[run]
branch = True

[report]
; Regexes for lines to exclude from consideration
exclude_also =
; Don't complain about missing debug-only code:
def __repr__
if self\.debug

; Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError

; Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:

; Don't complain about abstract methods, they aren't run:
@(abc\.)?abstractmethod

ignore_errors = True

omit =
"tests/*"
"docs/*"
55 changes: 55 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Python application

on: [push]

jobs:
build-and-publish:
name: ${{ matrix.os }} / ${{ matrix.python-version }}
runs-on: ${{ matrix.image }}
strategy:
matrix:
os: [Ubuntu, macOS, Windows]
python-version: ["3.8", "3.11"]
include:
- os: Ubuntu
image: ubuntu-latest
- os: Windows
image: windows-2022
- os: macOS
image: macos-12
fail-fast: false
steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Get full Python version
id: full-python-version
run: echo version=$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))") >> $GITHUB_OUTPUT

- name: Update PATH
if: ${{ matrix.os != 'Windows' }}
run: echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Update Path for Windows
if: ${{ matrix.os == 'Windows' }}
run: echo "$APPDATA\Python\Scripts" >> $GITHUB_PATH

- name: Enable long paths for git on Windows
if: ${{ matrix.os == 'Windows' }}
# Enable handling long path names (+260 char) on the Windows platform
# https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#maximum-path-length-limitation
run: git config --system core.longpaths true

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install

- name: Run tests with coverage
run: |
make cov
38 changes: 0 additions & 38 deletions .github/workflows/pythonapp.yml

This file was deleted.

33 changes: 33 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Release

on:
push:
tags:
- *.*.*

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.8

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry

- name: Build
run: |
make build

- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
password: ${{ secrets.PYPI_API_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,4 @@ docs/*.rst

.DS_Store
apk_version.txt
*.lock
22 changes: 6 additions & 16 deletions DEVELOP.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,17 @@

```
git clone https://github.com/openatx/uiautomator2
pip3 install -e uiautomator2
```

`-e`这个选项可以将该目录以软连接的形式添加到Python `site-packages`

## 生成CHANGELOG
See changelog from git history
cd uiautomator2

```
git log --graph --date-order -C -M --pretty=format:"<%h> %ad [%an] %Cgreen%d%Creset %s" --all --date=short
pip install poetry
poetry install
```

## 使用Sphinx生成文档
```bash
pip3 install -e .
cd docs
make publish
```
项目使用poetry做包管理和打包发布功能


## ViewConfiguration
一些默认的配置,从 `/android/view/ViewConfiguration.java`中可以查到
一些默认的配置,从 [/android/view/ViewConfiguration.java](https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/view/ViewConfiguration.java)中可以查到

> 单位: 毫秒

Expand Down
10 changes: 0 additions & 10 deletions MANIFEST.in

This file was deleted.

20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.PHONY: build

format:
poetry run isort . -m HANGING_INDENT -l 120

test:
poetry run pytest -v tests

cov:
poetry run pytest -v tests/unittests --cov=. --cov-report xml --cov-report term

build:
rm -fr dist
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
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import uiautomator2


# -- Project information -----------------------------------------------------

master_doc = 'index'
Expand Down
1 change: 1 addition & 0 deletions examples/apk_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# OPPO need password

import time

import uiautomator2 as u2


Expand Down
1 change: 0 additions & 1 deletion examples/batteryweb/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import flask
import requests


app = flask.Flask(__name__)


Expand Down
1 change: 0 additions & 1 deletion examples/com.codeskyblue.remotecamera/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import uiautomator2 as u2


pkg_name = 'com.codeskyblue.remotecamera'
d = u2.connect()

Expand Down
1 change: 1 addition & 0 deletions examples/com.netease.cloudmusic/xpath_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#

import unittest

from logzero import logger

import uiautomator2 as u2
Expand Down
4 changes: 3 additions & 1 deletion examples/minitouch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
#
# 半成品
import json
from . import Device

from websocket import create_connection

from . import Device


class Minitouch:
# TODO: need test
Expand Down
6 changes: 4 additions & 2 deletions examples/multi-thread-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
# But is seems fine, because these operation have so many socket IO
# So it seems no need to use multiprocess
#
import uiautomator2 as u2
import adbutils
import threading

import adbutils
from logzero import logger

import uiautomator2 as u2


def worker(d: u2.Device):
d.app_start("io.appium.android.apis", stop=True)
Expand Down
8 changes: 4 additions & 4 deletions examples/runyaml/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
# coding: utf-8
#

import re
import argparse
import os
import re
import time
import argparse

import yaml
import bunch
import uiautomator2 as u2
import yaml
from logzero import logger

import uiautomator2 as u2

CLICK = "click"
# swipe
Expand Down
3 changes: 3 additions & 0 deletions poetry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[virtualenvs]
create = true
in-project = true
Loading