app穩定性、遍歷工具——appcrawler(一)——相關介紹

AppCrawler

對app進行快速遍歷,底層引擎基於appium,支持Android和iOS。適合做隨機遍歷 或者 定製業務流遍歷。
https://github.com/seveniruby/AppCrawler   (由於github只能上傳100M以內,所以版本不是最新的)

 騰訊也有使用:https://security.tencent.com/index.php/blog/msg/105

1.appcrawler介紹

功能:

  • 自動化探索測試, 遍歷基本的界面, 瞭解主要界面的可用性. 比如兼容性, 基本功能
  • 利用遍歷獲取app的加載時間和性能數據,(需要藉助其他的性能數據抓取工具,比如OneApm, NewRelic、GT),提供前端性能基線
  • 利用遍歷驗證app的crash問題(appcrawler已支持),驗證app的內存泄漏以及穩定性等功能(需要藉助LeakCanary和MLeaksFinder)
  • 增加代碼覆蓋率
  • 自動化迴歸測試. UI diff 驗證新老版本的功能差異. 並識別細節的問題
  • 抓取接口請求 輔助驗證一些模塊基本接口, 並輔助分析接口調用流程. 爲接口測試做準備

2.安裝教程+問題解決:(目前最新版本2.4.0,對應appium版本1.12.0)

https://testerhome.com/wiki/appcrawler

https://seveniruby.gitbooks.io/appcrawler/content/

https://github.com/seveniruby/AppCrawler/tree/master/doc

參考appetizers的相關配置,可以瞭解到appcrawler的使用需要以下參數:

 

給的示例配置文件:

---
#插件列表
#pluginList:
#- "com.testerhome.appcrawler.plugin.FlowDiff"
#- "com.testerhome.appcrawler.plugin.ProxyPlugin"
#- "com.testerhome.appcrawler.plugin.TagLimitPlugin"
#- "com.testerhome.appcrawler.plugin.ReportPlugin"
reportTitle: AppCrawler-acp4.7
currentDriver: "android"
# 結果目錄
resultDir: ""
# 最大運行時間
maxTime: 10800
logLevel: "TRACE"
#結果報告是否展示沒有遍歷被取消的控件
showCancel: true
#特定元素的tag佈局層級完全一樣時的遍歷最大值
tagLimitMax: 4
tagLimit:
- xpath: //*[../*[@selected='true']]
  count: 12
#是否截圖
saveScreen: true
screenshotTimeout: 20

# appium的capability通用配置
capability:
  newCommandTimeout: 120
  launchTimeout: 120000
  platformVersion: ""
  platformName: ""Android""
# Appium是否需要自動安裝和啓動應用。默認值true  
  autoLaunch: "true"
# 直接轉換到 WebView 上下文。 默認值 false    
  autoWebview: "false"
# 不要在會話前重置應用狀態。默認值false。  
  noReset: "false"
  androidInstallTimeout: 180000

# android專屬配置 最後會和capability合併
androidCapability:
  deviceName: "192.168.58.101:5555"
  appPackage: "com.sinacp.ggaicai"
  appActivity: "com.aicai.pluginhost.activity.MainActivity"
  app: "/home/cmd/appcrawler/acp4.7p.apk"
  # 你想使用的自動化測試引擎 可以是 uiautomator2  macaca 等 默認appium
  automationName: appium/uiautomator2/macaca
  appium: "http://127.0.0.1:4730/wd/hub"
  macaca: "http://127.0.0.1:3456/wd/hub"
  fullReset: false
  noReset: true
  reuse: 3
  #以下爲重置手機輸入法爲appium輸入法
  unicodeKeyboard: true
  resetKeyboard: true


iosCapability:
  deviceName: "iPhone 6 Plus"
  bundleId: "com.sinacp.ggaicai"
  screenshotWaitTimeout: "10"
  platformVersion: "9.3"
  autoAcceptAlerts: "true"
  app: "/home/cmd/appcrawler/acp4.7p.apk"
  appium: "http://127.0.0.1:4730/wd/hub"

#appWhiteList:
#- android
#- com.shafa.market

# 用來確定url的元素定位xpath 他的text會被取出當作url因素
#defineUrl:
- //*[@selected='true' and contains(name(), 'TextView')]/@text

# 設置一個起始url和maxDepth, 用來在遍歷時候指定初始狀態和遍歷深度
#baseUrl:
- ".*MainActivity"
- ".*SNBHomeView.*"

# 默認的最大深度10, 結合baseUrl可很好的控制遍歷的範圍
maxDepth: 10

# 是否是前向遍歷或者後向遍歷
headFirst: true

# 是否遍歷WebView控件
enterWebView: true

# url黑名單.用於排除某些頁面
#urlBlackList:
- .*OutdoorSummaryMap.*
- .*PersonalPage.*
- .*Training.*
- .*FriendRank.*
- .*\\.base\\.Container.*
- ".*球友.*"
- ".*png.*"
- ".*Talk.*"
- ".*Chat.*"
- ".*Safari.*"
- "WriteStatus.*"
- "Browser.*"
- "MyselfUser"
- ".*MyselfUser.*"
- ".*股市直播.*"

#urlWhiteList:
#- ".*Main.*"

# 後退按鈕標記, 主要用於iOS, xpath
#backButton:
- //*[contains(@resource-id, "left_button")]
#defaultBackAction:
#- import sys.process._;
#- Thread.sleep(5000)
#- val name=Seq("adb", "shell", "dumpsys window windows | grep mCurrentFocus").!!.split(" ")(4).split("/")(0)
#- println(s"kill package ${name}")
#- Seq("adb", "shell", s"am force-stop ${name}").!!
#firstList:
#- //*[contains(@resource-id, "layout_picker_view_container"]

# 優先遍歷元素特徵列表
firstList:
#- "//*[contains(@resource-id,'com.acp.main:id/tvBottomTab4')]//android.widget.TextView"
- "//*[contains(@resource-id,'com.acp.main:id/tvBottomTab3')]//android.widget.TextView"
#- //*[contains(@resource-id, "layout_picker_view_container"]

# 默認遍歷元素特徵列表 需要注意的是firstList和lastList指定的元素必須包含在selectedList中
#selectedList:
#android非空標籤
- //*[@clickable='true']
- //*[@clickable='true']//*[contains(name(), 'Text') and string-length(@text)>0 and string-length(@text)<10 ]
#通用的button和image
- //*[@clickable='true']//*[contains(name(), 'Button')]
- //*[@clickable='true']//*[contains(name(), 'Image')]
#todo:如果多個規則都包含相同控件, 如何排序


# 最後遍歷元素特徵列表,處於選中狀態的同級控件最後點擊
#lastList:
- //*[../*[@selected='true']]
- //*[../../*/*[@selected='true']]
- //*[../../*/*[@selected='true'] and contains(@resource-id, 'tab_')]
- //*[contains(name(), "HorizontalScrollView")]
- //*[@resource-id='com.gotokeep.keep:id/layout_bottom']

# 黑名單列表 matches風格, 默認排除內容是2個數字以上的控件
blackList:
- ".*\\.[0-9].*"
- ".*[0-9][0-9].*"
- //*[contains(@resource-id, "wrapper_in_custom_title_bar")]//*[contains(@resource-id, "right_button")]
- //*[contains(@resource-id, "share")]
- //*[contains(@text, "開始第")]
- //*[contains(@resource-id, "lock")]
- //*[contains(@text, "舉報")]
- "//*[contains(@resource-id,'com.acp.main:id/tvBottomTab4')]//android.widget.TextView"
- //*[@resource-id='com.acp.main:id/module_tj1_name']    
- //*[@resource-id='com.acp.main:id/module_tj1_description']

# 引導規則. name, value, times三個元素組成
triggerActions:
- action: "yourname"
  xpath: "//*[@resource-id='com.sinacp.ggaicai:id/etUserName']"
  times: 1
- action: "yourpasswd"
  xpath: "//*[@resource-id='com.sinacp.ggaicai:id/etPwd']"
  times: 1
- xpath: //*[contains(@resource-id, "layout_picker_view_container")]//*[@text="確定"]
- xpath: //*[contains(@resource-id, "content-wrapper_dialog")]//*[@text="不發了"]
- xpath: //*[@text="拒絕"]
- xpath: //*[@text="結束訓練"]

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章