diff --git a/.gitignore b/.gitignore index df54b8cc..58af42b4 100644 --- a/.gitignore +++ b/.gitignore @@ -113,5 +113,4 @@ vendor/ docs/*.rst .DS_Store -apk_version.txt *.lock diff --git a/Makefile b/Makefile index ddb95ef9..596ae4a4 100644 --- a/Makefile +++ b/Makefile @@ -4,10 +4,10 @@ format: poetry run isort . -m HANGING_INDENT -l 120 test: - poetry run pytest -v tests + poetry run pytest -v mobile_tests/ cov: - poetry run pytest -v tests/unittests \ + poetry run pytest -v tests/ \ --cov-config=.coveragerc \ --cov uiautomator2 \ --cov-report xml \ diff --git a/docs/2to3.md b/docs/2to3.md index 4a8a4603..36f3d70f 100644 --- a/docs/2to3.md +++ b/docs/2to3.md @@ -5,15 +5,9 @@ - 版本管理从pbr改为poetry,同时降低依赖库的数量 - Python依赖调整为最低3.8 - 增加更多的单测 +- 日志使用标准库logging, 默认不输出任何内容,除非手动开启 - minicap,minitouch不再默认安装 - -# 增加 -开启库的详细日志的方法 - -```python -from uiautomator2 import enable_pretty_logging -enable_pretty_logging() -``` +- atx-agent[armeabi]直接打包到lib里面去,避免外网下载依赖 ## 移除的功能 - current_app函数移除 @@ -30,4 +24,17 @@ enable_pretty_logging() - 移除 module uiautomator2.ext.xpath - 移除 connect_usb函数中的init参数移除,这个参数目前没什么用了 -TODO: atx-agent不在依赖外网下载,直接打包到内部 +# 手动开启日志方法 +开启Lib库日志的方法 + +```python +from uiautomator2 import enable_pretty_logging +enable_pretty_logging() +``` + +或者 + +``` +logger = logging.getLogger("uiautomator2") +# 修改logger +``` diff --git a/tests/real_device/conftest.py b/mobile_tests/conftest.py similarity index 100% rename from tests/real_device/conftest.py rename to mobile_tests/conftest.py diff --git a/tests/real_device/runtest.sh b/mobile_tests/runtest.sh similarity index 100% rename from tests/real_device/runtest.sh rename to mobile_tests/runtest.sh diff --git a/tests/real_device/skip_test_image.py b/mobile_tests/skip_test_image.py similarity index 100% rename from tests/real_device/skip_test_image.py rename to mobile_tests/skip_test_image.py diff --git a/tests/real_device/test_push_pull.py b/mobile_tests/test_push_pull.py similarity index 100% rename from tests/real_device/test_push_pull.py rename to mobile_tests/test_push_pull.py diff --git a/tests/real_device/test_screenrecord.py b/mobile_tests/test_screenrecord.py similarity index 100% rename from tests/real_device/test_screenrecord.py rename to mobile_tests/test_screenrecord.py diff --git a/tests/real_device/test_session.py b/mobile_tests/test_session.py similarity index 100% rename from tests/real_device/test_session.py rename to mobile_tests/test_session.py diff --git a/tests/real_device/test_settings.py b/mobile_tests/test_settings.py similarity index 100% rename from tests/real_device/test_settings.py rename to mobile_tests/test_settings.py diff --git a/tests/real_device/test_simple.py b/mobile_tests/test_simple.py similarity index 100% rename from tests/real_device/test_simple.py rename to mobile_tests/test_simple.py diff --git a/tests/real_device/test_swipe.py b/mobile_tests/test_swipe.py similarity index 100% rename from tests/real_device/test_swipe.py rename to mobile_tests/test_swipe.py diff --git a/tests/real_device/test_utils.py b/mobile_tests/test_utils.py similarity index 100% rename from tests/real_device/test_utils.py rename to mobile_tests/test_utils.py diff --git a/tests/real_device/test_watcher.py b/mobile_tests/test_watcher.py similarity index 100% rename from tests/real_device/test_watcher.py rename to mobile_tests/test_watcher.py diff --git a/tests/real_device/test_xpath.py b/mobile_tests/test_xpath.py similarity index 100% rename from tests/real_device/test_xpath.py rename to mobile_tests/test_xpath.py diff --git a/tests/real_device/testdata/AE86.jpg b/mobile_tests/testdata/AE86.jpg similarity index 100% rename from tests/real_device/testdata/AE86.jpg rename to mobile_tests/testdata/AE86.jpg diff --git a/pyproject.toml b/pyproject.toml index 7ebe1fbc..b7793aff 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ homepage = "https://github.com/openatx/uiautomator2" authors = ["codeskyblue "] license = "MIT" readme = "README.md" -include = ["*/assets/*.apk"] +include = ["*/assets/*"] [tool.poetry.dependencies] python = "^3.8" diff --git a/tests/unittests/test_import.py b/tests/test_import.py similarity index 100% rename from tests/unittests/test_import.py rename to tests/test_import.py diff --git a/tests/unittests/test_logger.py b/tests/test_logger.py similarity index 100% rename from tests/unittests/test_logger.py rename to tests/test_logger.py diff --git a/tests/unittests/test_xpath.py b/tests/test_xpath.py similarity index 100% rename from tests/unittests/test_xpath.py rename to tests/test_xpath.py diff --git a/uiautomator2/__main__.py b/uiautomator2/__main__.py index 76a267a0..b46d9540 100644 --- a/uiautomator2/__main__.py +++ b/uiautomator2/__main__.py @@ -11,8 +11,9 @@ import uiautomator2 as u2 -from .init import Initer -from .version import __version__ +from uiautomator2.init import Initer +from uiautomator2.version import __version__ +from uiautomator2 import enable_pretty_logging logger = logging.getLogger(__name__) @@ -138,6 +139,7 @@ def cmd_version(args): def cmd_console(args): import code import platform + enable_pretty_logging() d = u2.connect(args.serial) model = d.shell("getprop ro.product.model").output.strip() diff --git a/uiautomator2/assets/.gitignore b/uiautomator2/assets/.gitignore new file mode 100644 index 00000000..cc51612c --- /dev/null +++ b/uiautomator2/assets/.gitignore @@ -0,0 +1,3 @@ +*.apk +atx-agent +version.txt \ No newline at end of file diff --git a/uiautomator2/assets/sync.sh b/uiautomator2/assets/sync.sh index 028917f4..07cb4c88 100755 --- a/uiautomator2/assets/sync.sh +++ b/uiautomator2/assets/sync.sh @@ -4,25 +4,37 @@ set -e APK_VERSION="2.3.3" +AGENT_VERSION="0.10.1" +echo "Created at $(date +"%Y-%m-%d %H:%M:%S %Z")" > version.txt cd "$(dirname $0)" -#if test -f apk_version.txt -a "$APK_VERSION" = "$(cat apk_version.txt)" -#then -# echo "apk version $APK_VERSION, already downloaded, exit" -# exit -#fi +function download_atx_agent() { + VERSION=$1 + NAME="tmp-atx-agent.tar.gz" + URL="https://github.com/openatx/atx-agent/releases/download/$VERSION/atx-agent_${VERSION}_linux_armv6.tar.gz" + echo "$URL" + curl -L "$URL" --output "$NAME" + tar -xzvf "$NAME" atx-agent + rm -f "$NAME" +} -function download(){ +function download_apk(){ VERSION=$1 NAME=$2 URL="https://github.com/openatx/android-uiautomator-server/releases/download/$VERSION/$NAME" echo "$URL" curl -L "$URL" --output "$NAME" + unzip -tq "$NAME" } -download "$APK_VERSION" "app-uiautomator.apk" -download "$APK_VERSION" "app-uiautomator-test.apk" +download_atx_agent "$AGENT_VERSION" +echo "atx_agent_version: $AGENT_VERSION" >> version.txt + +download_apk "$APK_VERSION" "app-uiautomator.apk" +download_apk "$APK_VERSION" "app-uiautomator-test.apk" + +echo "apk_version: $APK_VERSION" >> version.txt + -unzip -tq app-uiautomator.apk && echo "$APK_VERSION" > apk_version.txt diff --git a/uiautomator2/init.py b/uiautomator2/init.py index d541a387..a0cf78b2 100644 --- a/uiautomator2/init.py +++ b/uiautomator2/init.py @@ -5,6 +5,7 @@ import hashlib import logging import os +from pathlib import Path import shutil import tarfile @@ -22,6 +23,7 @@ logger = logging.getLogger(__name__) +assets_dir = Path(__file__).absolute().parent.joinpath("assets") class DownloadBar(progress.bar.PixelBar): message = "Downloading" @@ -333,14 +335,20 @@ def _install_jars(self): def _install_atx_agent(self): logger.info("Install atx-agent %s", __atx_agent_version__) + if 'armeabi' in self.abis: + local_atx_agent_path = assets_dir.joinpath("atx-agent") + if local_atx_agent_path.exists(): + logger.info("Use local atx-agent[armeabi]: %s", local_atx_agent_path) + dest = '/data/local/tmp/atx-agent' + self._device.sync.push(local_atx_agent_path, dest, mode=0o755) + return self.push_url(self.atx_agent_url, tgz=True, extract_name="atx-agent") def setup_atx_agent(self): # stop atx-agent first self.shell(self.atx_agent_path, "server", "--stop") if self.is_atx_agent_outdated(): - logger.info("Install atx-agent %s", __atx_agent_version__) - self.push_url(self.atx_agent_url, tgz=True, extract_name="atx-agent") + self._install_atx_agent() self.shell(self.atx_agent_path, 'server', '--nouia', '-d', "--addr", self.__atx_listen_addr) logger.info("Check atx-agent version") diff --git a/uiautomator2/version.py b/uiautomator2/version.py index 8d534586..10b1167a 100644 --- a/uiautomator2/version.py +++ b/uiautomator2/version.py @@ -39,7 +39,8 @@ __jar_version__ = 'v0.1.6' # no useless for now. # v0.1.6 first release version -__atx_agent_version__ = '0.10.0' +__atx_agent_version__ = '0.10.1' # sync.sh verison should also be updated +# 0.10.1 update androidbinary version, https://github.com/openatx/atx-agent/issues/115 # 0.10.0 remove tunnel code, use androidx.test.runner # 0.9.6 fix security reason for remote control device # 0.9.5 log support rotate, prevent log too large