Giter VIP home page Giter VIP logo

atx's Introduction

ATX(AutomatorX) (中文版)

Build Status Documentation Status PyPI PyPI Gitter

重要说明 !!!

ATX目前已经分成了两个项目

旧项目不再维护。欢迎入群讨论 QQ: 499563266

Introduction (简介)

ATX(AutomatorX) 是一款开源的自动化测试工具,支持测试iOS平台和Android平台的原生应用、游戏、Web应用。 使用Python来编写测试用例,混合使用图像识别,控件定位技术来完成游戏的自动化。附加专用的IDE来完成脚本的快速编写。

Hope (愿景)

希望该项目可以让手机应用测试自动化起来,让测试人员摆脱那些枯燥的重复性工作。

重要说明

新版本以采用新的uiautomator2替换到原来的atx-uiautomator. 历史版本可以通过Tag查看tag:1.1.3 测试安卓应用前,需要先进行init操作

python -muiautomator2 init

用于安卓和iOS原生应用测试的库已经分离出来,可以单独使用(强烈推荐单独使用,一来依赖少、稳定性高,二来写代码的时候还能自动补全)

  1. 对于Android应用的测试,如果不需要用到图像识别,推荐使用这个项目uiautomator2
  2. 对于iOS应用的测试,如果不需要用到图像识别,推荐使用这个项目facebook-wda

BTW: atx-webide已经不在维护

Features

  • 支持iOS, Android 双平台的原生应用,Web应用和游戏
  • 支持通过图像识别来定位元素的位置
  • 内置自动生成测试报告的功能
  • 网页版的脚本编辑器,来帮助快速的写代码

Discuss (讨论群)

面向游戏行业测试人员,当然也开放给国际友人(PS:中文不知道他们看得懂不)

  • QQ: 499563266 PS: 因为群人数即将到达上限,所以目前进群有收取少量的群费,来募集扩大群规模的费用。
  • 网易内部用户加Popo群 1347390 群主 hzsunshx
  • Testerhome社区
  • Gitter Chat Room

Limitation (限制)

  • Python 2.7 or 3.6
  • Android 4.4+
  • iOS 9.0+ with Mac
  • adb >= 1.0.36

Installation (安装)

准备Python虚拟环境 Virtualenv

pip install virtualenv
virtualenv venv

# Linux or Mac
. venv/bin/activate

# Windows
venv\Scripts\activate.bat 

安装相关的python库

# install the lastest version of atx
# If feed too slow use douban pypi mirror:  -i https://pypi.doubanio.com/simple/
pip install --upgrade --pre atx

# install opencv dependencies
pip install opencv_contrib_python

Android测试依赖

  • ADB

  • ATX手机助手.apk

    该App为自动化提供了输入法的功能,屏幕常量等功能 命令行安装 python -m atx install atx-assistant

iOS测试依赖

  • WebDriverAgent

    由于WebDriverAgent更新过快,atx的一个依赖库facebook-wda还跟不上他更新的速度,下载完WDA后,请切换到这个版本

     git reset --hard a8def24ca67f8a74dd709b899c8ea539c9c488ea
    

    你的iPhone手机需要连接到Mac上,然后Mac安装WebDriverAgent,通常对Xcode部署的人搭WDA的人会遇到不少问题,搞不定继续参考这里 https://testerhome.com/topics/7220

    WDA成功启动后,会生成一个用于ATX连接的http地址,比如http://localhost:8100

检查安装是否成功

# 查看atx版本号
python -m atx version
# 检查环境配置是否正常
python -m atx doctor

脚本编辑器(可选)

为了方便快速的写出脚本,提供了三个Web编辑器。

  • 自带GUI

    自带的使用Tkinter写的编辑器,只提供截图功能,但是比较稳定,启动方法 python -m atx gui -s ${SERIAL or WDA_URL} 使用 python -m atx gui -h 可以查看更多的选项

  • weditor beta 针对Android和iOS原生应用快速定位元素,自动生成代码

Getting Started (必看)

内置的测试报告暂时有点问题,最近没时间去修复了。因为ATX底层使用的uiautomator2,测试报告可以用底层库自带的 SimpleHTMLReport

APIs (接口文档)

Other (其他)

Known Issues (常见问题)

If you are having some issues please checkout wiki first.

为了避免潜在的Python编码问题,代码文件都应该用UTF-8编码格式保存。

  • 测试中出现的弹窗如何处理?

    《iOS弹窗如何自动处理》,仅供参考 https://testerhome.com/topics/9540

  • 对于python2.7 字符串前应该加上u开头,例如u'你好'

    文件的开头可以加上下面这段代码,强制使用python3的编码体系(默认全部都是unicode)

     from __future__ import unicode_literals
  • 对于python3的非windows系统

    检查一下sys.stdout.encoding的编码是否是UTF-8,不然中文字符的输出通常会有问题 解决办法通常就是在bashrc文件中加入一行

     export PYTHONIOENCODING=UTF-8

ATX Extentions (扩展功能)

  • WebView

    目前仅限安卓, 具体参考 https://testerhome.com/topics/7232

    例子代码

     # coding: utf-8
     import atx
     from atx.ext.chromedriver import ChromeDriver
    
     d = atx.connect()
     driver = ChromeDriver(d).driver() # return selenium.driver instance
     elem = driver.find_element_by_link_text(u"登录")
     elem.click()
     driver.quit()

    PS: 实现这个扩展并不复杂,简单的封装了一下selenium就搞定了

  • Performance record (For Android)

    性能测试直接使用了腾讯开源的GT

    PS: 刚写好没多久,你只能在最新的开发版中看到。有可能以后还会修改。

    使用方法

    1. 首先需要去腾讯GT的主页上,将GT安装到手机上

      http://gt.qq.com

    2. 代码中引入GT扩展

      import atx
      from atx.ext.gt import GT
      
      
      d = atx.connect()
      
      gt = GT(d)
      gt.start_test('com.netease.my') # start test
      # ... do click touch test ...
      gt.stop_and_save()
    3. 运行完测试后,代码会保存到/sdcard/GT/GW/+包名(com.netease.my)目录下,直接使用adb pull下载下来并解析

      $ adb pull /sdcard/GT/GW/com.netease.my/
      

    该部分代码位于 atx/ext/gt.py, 这部分代码目前在我看来,易用性一般般,希望使用者能根据具体情况,进行修改,如果是修改具有通用性,欢迎提交PR,我们会负责Review代码。

代码导读

connect 函数负责根据平台返回相应的类(atx.drivers.android.AndroidDevice or atx.drivers.ios_webdriveragent.IOSDevice)

图像识别依赖于另一个库 aircv, 虽然这个库还不怎么稳定,也还凑合能用吧

每个平台相关的库都放到了 目录 atx/device下,公用的方法在atx/device/device_mixin.py里实现。第三方扩展位于atx/ext目录下。

Related projects (相关的项目)

  1. 基于opencv的图像识别库 https://github.com/netease/aircv

  2. 感谢作者 https://github.com/xiaocong 提供的uiautomator的python封装,相关项目已经fork到了

  3. Android input method https://github.com/macacajs/android-unicode

  4. SikuliX http://sikulix-2014.readthedocs.org/en/latest/index.html

  5. Blockly https://github.com/codeskyblue/blockly

Contribution (参与贡献)

如何才能让软件变的更好,这其中也一定需要你的参与才行,发现问题去在github提个issue, 一定会有相应的开发人员看到并处理的。文档有错误的话,直接提Issue,或者提PR都可以。 由于我平常使用该项目的概率并不怎么高,所有不少问题即使存在我也不会发现,请养成看到问题提Issue的习惯,所有的Issue我都会去处理的,即使当时处理不了,等技术成熟了,我还是会处理。但是如果不提交Issue,说不定我真的会忘掉。

BTW: 有开发能力的也可以先跟开发者讨论下想贡献的内容,并提相应的PR由开发人员审核。

License (协议)

This project is under the Apache 2.0 License. See the LICENSE file for the full license text.

atx's People

Contributors

bigwavelet avatar codeskyblue avatar jinpf avatar johannesbuchner avatar lucyking avatar riccoyu avatar wuxc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

atx's Issues

Sometime, It stopped in loop. I don't know why?

thread = threading.Thread(target=self.run_test,
args=(self.event, db, self.app_status_queue,))
thread.daemon = True
self.status_run_app = True
self.event.set()
thread.start()

func loop:

def run_test()
   while true:
     u = atx.connect()
    #action test ...
     kill adb

My log.txt
log.txt
log-2.txt

集成所有常用功能的APK

  • Utf7IME输入法
  • 屏幕常亮 Keep Screen WakeUP
  • 自动安装软件,自动确认权限 Auto confirm installation, permissions

Please update document. File not Found

pip install http://goandroid.qiniucdn.com/opencv_python-2.4.12-cp27-none-win_amd64.whl
File not Found. I suggest you should change language to english

About click() and quit()

When I use quit() after click() ,in most cases (not always) quit immediate ,not after click()

w.on('enter-game.png').click().quit()

About atx.Pattern

unable to use like this

on(atx.Pattern("xx.png",offset=(xx,xx))).click() 

python -m atx install 出错

What steps will reproduce the problem?

What is the expected output?

What do you see instead?

Do you have any log or screenshots?

提示 adb.build_cmd 不存在

文件名增加使用百分比的偏移

DESIGN

点击坐标的偏移百分比

规则

<name>.<T|B><number><L|R><number>.png

T代表Top,B代表Bottom,L代表Left,R代表Right

filename: button.T50R150.png

代表向上偏移50%,向右偏移150%

报告优化

  • 每个步骤前面写出序号。
  • 在uiautomator点击操作时,把uiautomator的语句添加到步骤里,例如d(text="abc").click()。如果可以,希望可以翻译成“点击文字abc”。
  • 在uiautomator的exist判断时,希望把uiautomator的语句添加到步骤里,例如d(text="abc").exist。如果可以,希望可以翻译成“文字adb存在”或者“文字abc不存在”。(但是我这边的用法是加上assert exist==True。看看怎么表达比较好?

atx每次仅能完成一次操作,第二次操作会一直处于无响应状态

What steps will reproduce the problem?

win 10 32位PC,atx安装成功后,每次只能完成一次操作
按以下执行,第二次click()操作一直不返回结果

Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:19:22) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import atx
>>> d=atx.connect()
>>> d.click(300,600)
True
>>> d.click(300,600)

不仅仅是click(),包括screenshot()都存在类似问题

python -m atx minicap 安装失败,必须指定端口到15073才能成功

What steps will reproduce the problem?

win 10 32位PC,atx安装完毕后,按照指示完成设备的连接(atx.connect()),未报错
命令行运行python -m atx minicap

What do you see instead?

报错信息如下:

D:\duping\atx>python -m atx minicap
2016-07-29 10:58:29.029 INFO  [minicap:  55] Minicap install started!
2016-07-29 10:58:29.029 INFO  [minicap:  60] Make temp dir ...
2016-07-29 10:58:29.029 INFO  [minicap:  64] Retrive device information ...
2016-07-29 10:58:29.060 ERROR [minicap: 100] run cmd: adb -H 127.0.0.1 -P 5037 shell getprop ro.product.cpu.abi failed. Command 'adb -H 127.0.0.1 -P 5037 shell getprop ro.product.cpu.abi' returned non-zero exit status 1
2016-07-29 10:58:29.060 INFO  [minicap: 103] Cleaning temp dir

在命令中指定端口到15073后问题解决
Python -m atx -H 127.0.0.1 -P 15037 minicap

另,以下测试设备均有问题
小米5 6.0.1
三星note4 4.4.4
三星s3 4.3

在中文路径下运行 python -matx gui会出现编码问题

Traceback (most recent call last):
File "C:\Python27\lib\runpy.py", line 162, in run_module_as_main
"main", fname, loader, pkg_name)
File "C:\Python27\lib\runpy.py", line 72, in run_code
exec code in run_globals
File "C:\Python27\lib\site-packages\atx__main
.py", line 141, in
main()
File "C:\Python27\lib\site-packages\atx__main__.py", line 138, in main
args.func(args)
File "C:\Python27\lib\site-packages\atx__main__.py", line 46, in inner
return inject(mod.main, pargs)
File "C:\Python27\lib\site-packages\atx__main
_.py", line 37, in inject
return func(*args)
File "C:\Python27\lib\site-packages\atx\cmds\tkgui.py", line 363, in main
d.wakeup()
File "C:\Python27\lib\site-packages\uiautomator__init__.py", line 797, in wak
eup
self.server.jsonrpc.wakeUp()
File "C:\Python27\lib\site-packages\uiautomator__init__.py", line 430, in wra
pper
server.start(timeout=30)
File "C:\Python27\lib\site-packages\uiautomator__init__.py", line 468, in sta
rt
files = self.push()
File "C:\Python27\lib\site-packages\uiautomator__init__.py", line 404, in pus
h
self.adb.cmd("push", filename, "/data/local/tmp/").wait()
File "C:\Python27\lib\site-packages\uiautomator__init__.py", line 288, in cmd

return self.raw_cmd(*["-s", serial] + list(args))

File "C:\Python27\lib\site-packages\uiautomator__init__.py", line 297, in raw
_cmd
return subprocess.Popen(cmd_line, shell=True, stdout=subprocess.PIPE, stderr
=subprocess.PIPE)
File "C:\Python27\lib\subprocess.py", line 710, in init
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 913, in _execute_child
args = list2cmdline(args)
File "C:\Python27\lib\subprocess.py", line 644, in list2cmdline
return ''.join(result)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd1 in position 0: ordinal
not in range(128)

红米 note Android4.4.4 录屏提示minicap错误

What steps will reproduce the problem?

python -m atx screenrecord -o out.avi

What is the expected output?

正确录制视频

What do you see instead?

异常报错

Do you have any log or screenshots?

C:\Users\Administrator>python -m atx screenrecord -o out.avi
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\atx\adbkit\mixins.py", line 152, in _pull
assert p.poll() is None
AssertionError
Process died.
ERROR: invalid format for -P, need <w>x<h>@<w>x<h>/{0|90|180|270}

minicap died

报告总结果页面

如果执行多个脚本,希望有个总结果页面,可以把执行若干的atx的结果页面用一个总的页面链接起来

Serial Result Link
af1222 PASS http://....
bd323 FAIL http://....
yyeww OFFLINE http://....
yyeww SKIP http://....

使用 `python -matx minicap` 在 genymotion 模拟器上安装 minicap 报错

使用 python -matx minicap 在 genymotion 模拟器上安装 minicap 报错:

$ python -matx minicap
2016-05-30 12:51:19.568 INFO  [minicap:  55] Minicap install started!
2016-05-30 12:51:19.569 INFO  [minicap:  60] Make temp dir ...
2016-05-30 12:51:19.575 INFO  [minicap:  64] Retrive device information ...
2016-05-30 12:51:19.587 ERROR [minicap: 100] run cmd: adb -H 127.0.0.1 -P 5037 shell getprop ro.product.cpu.abi failed. [Errno 2] No such file or directory
2016-05-30 12:51:19.588 INFO  [minicap: 103] Cleaning temp dir

但单独运行出错的命令没有问题:

$ adb -H 127.0.0.1 -P 5037 shell getprop ro.product.cpu.abi
x86

Genymotion 版本:2.5.2, reversion: 20150717-d5a1e88
模拟器相关信息:Google Nexus 4 -5.0.0-API 21-768x1280

不知道是不支持还是别的原因?

PS:直接用 stf 试过,stf 中找不到这个模拟器设备。。。

issue RPC server not started

My scenario:

  • Quit device -> Start device -> workflow -> Quit device -> Start device -> workflow --> .... (loop it )

Error: After a period then workflow don't work. It's pause

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.