app自动化测试平台实战 1

app自动化测试平台实战 1

android 源码 :https://android.googlesource.com/platform/system/core/+/refs/tags/android-6.0.0_r5/adb/

Monkey

https://developer.android.com/studio/test/monkey

基本语法:

$ adb shell monkey [options] <event-count>

monkey命令:

usage: monkey [-p ALLOWED_PACKAGE [-p ALLOWED_PACKAGE] ...]
              [-c MAIN_CATEGORY [-c MAIN_CATEGORY] ...]
              [--ignore-crashes] [--ignore-timeouts]
              [--ignore-security-exceptions]
              [--monitor-native-crashes] [--ignore-native-crashes]
              [--kill-process-after-error] [--hprof]
              [--pct-touch PERCENT] [--pct-motion PERCENT]
              [--pct-trackball PERCENT] [--pct-syskeys PERCENT]
              [--pct-nav PERCENT] [--pct-majornav PERCENT]
              [--pct-appswitch PERCENT] [--pct-flip PERCENT]
              [--pct-anyevent PERCENT] [--pct-pinchzoom PERCENT]
              [--pct-permission PERCENT]
              [--pkg-blacklist-file PACKAGE_BLACKLIST_FILE]
              [--pkg-whitelist-file PACKAGE_WHITELIST_FILE]
              [--wait-dbg] [--dbg-no-events]
              [--setup scriptfile] [-f scriptfile [-f scriptfile] ...]
              [--port port]
              [-s SEED] [-v [-v] ...]
              [--throttle MILLISEC] [--randomize-throttle]
              [--profile-wait MILLISEC]
              [--device-sleep-time MILLISEC]
              [--randomize-script]
              [--script-log]
              [--bugreport]
              [--periodic-bugreport]
              [--permission-target-system]
              COUNT

调用关系:

 Script to start "monkey" on the device, which has a very rudimentary
# shell.
#
base=/system
export CLASSPATH=$base/framework/monkey.jar
trap "" HUP
exec app_process $base/bin com.android.commands.monkey.Monkey $*

命令:

adb shell monkey  -p com.xueqiu.android  --throttle 500 -s 100  100
adb shell monkey  -p com.xueqiu.android  --throttle 500 --pct-touch 10 --pct-syskeys 90  100

Maxim

工具下载:

git clone git@github.com:zhangzhao4444/Maxim.git

下载完成后,将两个jar推到手机:

adb push framework.jar /sdcard
adb push monkey.jar /sdcard

执行命令:

adb shell CLASSPATH=/sdcard/monkey.jar:/sdcard/framework.jar exec app_process /system/bin tv.panda.test.monkey.Monkey -p com.panda.videoliveplatform --uiautomatormix --running-minutes 60 -v -v

appcrawler

https://github.com/seveniruby/AppCrawler

生成配置文件

java  -jar  appcrawler-2.4.0-jar-with-dependencies.jar --demo

样例1:

  • 点击我的,进行滑动,点击设置
  • 在设置页面完成自动化遍历
capability:
  noReset: "true"
  fullReset: "false"
  appium: "http://127.0.0.1:4723/wd/hub"
  appPackage: "com.xueqiu.android"
  appActivity: ".view.WelcomeActivityAlias"
testcase:
  name: "TesterHome AppCrawler"
  steps:
    - xpath: "我的"
      action: click
    - xpath: //*
      action: driver.swipe(0.5,0.9,0.5,0.1)
    - xpath: "设置"
      action: click

triggeraction去掉广告,处理弹窗:


triggerActions:
   - xpath: "//*[@resource-id='com.xueqiu.android:id/iv_close']"
     action: click

selectedList完成先后遍历:

capability:
  noReset: "true"
  fullReset: "false"
  appium: "http://127.0.0.1:4723/wd/hub"
  appPackage: "com.xueqiu.android"
  appActivity: ".view.WelcomeActivityAlias"
testcase:
  name: "TesterHome AppCrawler"
  steps:
    - xpath: "//*[@resource-id='com.xueqiu.android:id/tv_search']"
      action: click
    - xpath: "//*[@resource-id='com.xueqiu.android:id/search_input_text']"
      action: "alibaba"
    - xpath: "//*[@text='阿里巴巴-SW']"
      action: click
    - xpath: "//*[@text='09988' and @resource-id='com.xueqiu.android:id/stockCode']"
      action: click
  
selectedList:
  - xpath: "//*[@resource-id='com.xueqiu.android:id/small_period_container']//android.widget.TextView"
  - xpath: "//*[@resource-id='com.xueqiu.android:id/tab_indicator_view']//android.widget.TextView"
firstList:
  - xpath: "//*[@resource-id='com.xueqiu.android:id/tab_indicator_view']//android.widget.TextView"

作业

点击搜索 alibaba ,点击后进行 selectedList完成先后遍历

老师,appcrawler启动报错(appium启动了,jdk1.8装了,mumu模拟器连接了。。。)

value 为空

执行命令报错:
java -jar appcrawler-2.4.0-jar-with-dependencies.jar --capability “appPackage=com.xueqiu.android,appActivity=.view.WelcomeActivityAlias”


点击搜索 alibaba ,点击后进行 selectedList完成先后遍历

---
pluginList: []
saveScreen: true
reportTitle: ""
resultDir: "20200420213353"
waitLoading: 500
waitLaunch: 6000
showCancel: true
maxTime: 10800
maxDepth: 10
capability:
  noReset: "true"
  fullReset: "false"
  appium: "http://127.0.0.1:4723/wd/hub"
  appPackage: "com.xueqiu.android"
  appActivity: ".view.WelcomeActivityAlias"
testcase:
  name: "TesterHome AppCrawler"
  steps:
    - xpath: "//*[@resource-id='com.xueqiu.android:id/tv_search']"
      action: click
    - xpath: "//*[@resource-id='com.xueqiu.android:id/search_input_text']"
      action: "alibaba"
    - xpath: "//*[@text='阿里巴巴-SW']"
      action: click
    - xpath: "//*[@text='09988' and @resource-id='com.xueqiu.android:id/stockCode']"
      action: click
#    - xpath: "//*[@text='行情']"
#      action: click
#    - xpath: //*
#      action: driver.swipe(0.5,0.9,0.5,0.1)
#    - xpath: "设置"
#      action: click
selectedList:
#  - xpath: "//*[contains(@resource-id, 'stock_index_quote_view_layout')]//*[@clickable='true']"
  - xpath: "//*[@resource-id='com.xueqiu.android:id/small_period_container']//android.widget.TextView"
  - xpath: "//*[@resource-id='com.xueqiu.android:id/tab_indicator_view']//android.widget.TextView"
firstList:
  - xpath: "//*[@resource-id='com.xueqiu.android:id/tab_indicator_view']//android.widget.TextView"
lastList:
  - given: []
    when: null
    then: []
    xpath: "//*[@selected='true']/..//*"
    action: null
    actions: []
    times: 0
  - given: []
    when: null
    then: []
    xpath: "//*[@selected='true']/../..//*"
    action: null
    actions: []
    times: 0
backButton:
  - given: []
    when: null
    then: []
    xpath: "Navigate up"
    action: null
    actions: []
    times: 0
triggerActions:
  - xpath: "//*[@resource-id='com.xueqiu.android:id/iv_close']"
    action: click
xpathAttributes:
  - "name"
  - "label"
  - "value"
  - "resource-id"
  - "content-desc"
  - "instance"
  - "text"
sortByAttribute:
  - "depth"
  - "list"
  - "selected"
findBy: "default"
defineUrl: []
baseUrl: []
appWhiteList: []
urlBlackList: []
urlWhiteList: []
blackList:
  - given: []
    when: null
    then: []
    xpath: ".*[0-9]{2}.*"
    action: null
    actions: []
    times: 0
beforeRestart: []
beforeElement:
  - given: []
    when: null
    then: []
    xpath: "/*"
    action: "Thread.sleep(500)"
    actions: []
    times: 0
afterElement: []
afterPage: []
afterPageMax: 2
tagLimitMax: 2
tagLimit:
  - given: []
    when: null
    then: []
    xpath: "ȷ��"
    action: null
    actions: []
    times: 1000
  - given: []
    when: null
    then: []
    xpath: "ȡ��"
    action: null
    actions: []
    times: 1000
  - given: []
    when: null
    then: []
    xpath: "share_comment_guide_btn_name"
    action: null
    actions: []
    times: 1000
assertGlobal: []

https://github.com/Ashley-luo66/hogwarts_lagou_homework/blob/master/appCrawler_homework/demo_xueqiu.yml

https://github.com/ZHHAYO/TestingDemo/blob/master/test_appcrawler/demo3.yml

capability:
  noReset: "true"
  fullReset: "false"
  appium: "http://127.0.0.1:4723/wd/hub"
  appPackage: "com.xueqiu.android"
  appActivity: ".view.WelcomeActivityAlias"
testcase: #进行随机事件前要执行的步骤
  name: "TesterHome AppCrawler"
  steps:
    - xpath: "//*[@resource-id='com.xueqiu.android:id/tv_search']"
      action: click
    - xpath: "//*[@resource-id='com.xueqiu.android:id/search_input_text']"
      action: "alibaba"
    - xpath: "//*[@text='阿里巴巴-SW']"
      action: click
    - xpath: "//*[@text='09988' and @resource-id='com.xueqiu.android:id/stockCode']"
      action: click
  
selectedList:  #限定要遍历的控件
  - xpath: "//*[@resource-id='com.xueqiu.android:id/small_period_container']//android.widget.TextView"
  - xpath: "//*[@resource-id='com.xueqiu.android:id/tab_indicator_view']//android.widget.TextView"
firstList: #首先进行的遍历的控件
  - xpath: "//*[@resource-id='com.xueqiu.android:id/tab_indicator_view']//android.widget.TextView"

https://github.com/GongBin-0923/selenium/blob/master/appcrawler/demo1.yml