Android自动化测试工具uiautomator

时间:2022-09-05 20:02:24

http://automationtesting.sinaapp.com/blog/m_uiautomator


python模块介绍-uiautomator:Android自动化测试工具uiautomator

简介

  • uiautomator适用于native的Android应用,但是无法处理web。
  • 应用类型的基本概念参见: hybrid app
  • 模块: uiautomator
  • 目的: Python Wrapper for Android UiAutomator? test tool
  • 月下载量:4k左右
  • 地址:uiautomator

安装

  • 安装uiautomator:
    ]#pip install uiautomator 
    Downloading/unpacking uiautomator
    Downloading uiautomator-0.1.32.tar.gz (513kB): 513kB downloaded
    Running setup.py (path:/tmp/pip_build_root/uiautomator/setup.py) egg_info for package uiautomator

    Downloading/unpacking urllib3>=1.7.1 (from uiautomator)
    Downloading urllib3-1.9.tar.gz (91kB): 91kB downloaded
    Running setup.py (path:/tmp/pip_build_root/urllib3/setup.py) egg_info for package urllib3

    Installing collected packages: uiautomator, urllib3
    Running setup.py install for uiautomator

    Running setup.py install for urllib3

    Successfully installed uiautomator urllib3
    Cleaning up...
# adb push bundle.jar /data/local/tmp/
# adb push uiautomator-stub.jar /data/local/tmp/
# adb shell uiautomator runtest bundle.jar uiautomator-stub.jar -c com.github.uiautomatorstub.Stub # 此步骤注意手机要通过USB连接到电脑,并允许调试和连接。
# adb forward tcp:9008 tcp:9008
# curl -d '{"jsonrpc":"2.0","method":"deviceInfo","id":1}' localhost:9008/jsonrpc/0 # 检查结果
{"jsonrpc":"2.0","id":1,"result":{"currentPackageName":"android","displayHeight":1280,"displayRotation":0,"displaySizeDpX":0,"displaySizeDpY":0,"displayWidth":720,"productName":"falcon","sdkInt":17,"naturalOrientation":true}}

执行python脚本:

from uiautomator import device as d
d(text="Settings").click()

注意:ubuntu中如果报:libstdc++.so.6,adb命令无法执行,需要执行apt-get install lib32stdc++6 lib32z1 lib32z1-dev

本文地址

参考资料