github地址点此进入

AndroidViewClient was originally conceived as an extension to monkeyrunner but lately evolved as a pure python tool that automates or simplifies test script creation.
It is a test framework for Android applications that:

  • Automates driving Android applications
  • Generates re-usable scripts
  • Provides view-based device independent UI interaction
  • Uses ‘logical’ screen comparison (UI Automator Hierarchy based) over image comparison (Avoiding extraneous detail issues, such as time or data changes)
  • Supports running on multiple devices
  • Provides simple control for high level operations like language change and activity start
  • Supports all Android APIs
  • Is written in python

AndroidViewClient主要工作方式是通过 adb shell uiautomator dump通过Android ViewSever将当前屏幕的内容保存成XML并保存到AndroidViewClient的数据结构中,而后通过ViewClient提供的method进行元素定位并进行相应操作。

AndroidViewClient可以跨应用进行操作,通过模拟用户操作(adb shell input),验证页面信息等方式达到自动化测试的目的。

每次页面的改动都需要进行一次dump进行同步手机显示信息,也正因如此,每次页面改动进行的dump操作都会带来一定的等待时间,等待时间太短容易页面未刷新完成导致dump失败,等待时间太长导致整体测试的效率变低,SO,如何聪明地去处理这个时间很重要。

anyway,一点点时间的浪费带来测试结果可信度的提高也是非常的值得。

定位页面元素(ViewClient)
findViewById
findViewByIdOrRaise
findViewByTag
findViewByTagOrRaise
findViewWithAttribute
findViewsWithAttribute
findViewWithAttributeOrRaise
findViewWithAttributeThatMatches
findViewWithText
findViewWithTextOrRaise
findViewWithContentDescription
findViewWithContentDescriptionOrRaise
findViewsContainingPoint

模拟用户操作(ViewClient)
click
longTouch
touch
swipe
pressKeyCode

页面元素信息获取(View)

getClass
getId
getContentDescription
getTag
getParent
getChildren
getText
getHeight
getWidth
getUniqueId
getVisibility
getX
getY
getXY
getCoords
getPositionAndSize
getBounds
getCenter
touch
escapeSelectorChars
obtainSelectorForView
longTouch
allPossibleNamesWithColon
intersection
containsPoint
add
isClickable
isFocused
variableNameFromId
setTarget
isTarget
writeImageToFile