自動遍歷測試


前沿:

1、版本迭代過程中,為了保證新功能之外 還要保證原有老功能不受影響且運行正常, 而老功能回歸遍歷的工作量太大,優先級又相對較低;不適合投入較大工作量;

2、使用UI自動化測試做回歸遍歷又有一些弊端, case過於繁瑣,case量大,且運行case后的斷言不易包含過多驗證點; 因此使用UI自動化偏向於維護主流核心業務,且穩定性較高,鏈路不要太復雜為宜;

3、現有的monkey可控性差,穩定性差,不支持定制;

4、自動化遍歷工具還適用於做健壯性測試;性能測試;專項測試等;

因此急需引入新的開源自動化遍歷工具appcrawler, 解決以上痛點.

項目地址: https://github.com/seveniruby/AppCrawler

 

執行方法:

1、下載完成后, 啟動Appium(該開源項目是基於Appium開發的);

2、在項目路徑下 運行  生成配置文

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

  

3、自定義配置文件  vim demo.yml

  設置運行配置  appium配置

  編寫testcase  運行前的自動化程序 比如進入某個模塊

  編寫selectedList  編寫該模塊內遍歷的內容項

  編寫遍歷的順序  first  last

  設置遍歷深度  maxDepth 可以先查看存在幾層 urlStack=Activity (每個activity代表一層)

pluginList: []

saveScreen: true     #是否截圖

reportTitle: ""    #測試報告名字

resultDir: "20190826111341"

waitLoading: 500           #操作后的等待頁面加載時間

waitLaunch: 6000         #加載app等待時間 ,一般會有加載廣告

showCancel: true         #遍歷頁面時 頁面中沒有遍歷到的內容是否展示

maxTime: 10800       #最多執行時間

maxDepth: 10        #遍歷深度

capability:         #capability 是appium相關配置 除了appium(配置服務地址),其余項與appium配置一致

  noReset: "true"

  fullReset: "false"

  appium: "http://127.0.0.1:4723/wd/hub"

testcase:          #testcase用例配置  啟動app后基礎測試用例  自動化用例 比如想遍歷某個模塊,就配置進入該模塊的步驟

  name: "TesterHome AppCrawler"

  steps:

  - given: []   #先決條件

    when: null  #條件成立后的執行行為

    then: []    #斷言

    xpath: "/*" #when行為中的元素定位

    action: "Thread.sleep(5000)" #when行為元素的操作

    actions: []

    times: 0

 

 - when:   #簡寫形態,可以直接寫when 尋找定位元素后 對其進行操作

    xpath: "/*" #when行為中的元素定位  元素定位可以使用xpath  正則  包含關系

       action: "Thread.sleep(5000)" #when行為元素的操作  默認是點擊行為  可以改成函數driver.swipe(,,,) monkey隨機事件,長按longTap,后退backApp(可以定制),

 - xpath:我的

   action:點擊

  then:

 

selectedList:      #selectedList 被選擇控件清單列表,列表中沒有 遍歷過程中將不會被選中  可以在這個地方設置用例的遍歷模塊范圍

- given: []

  when: null

  then: []

  xpath: "//*[contains(name(), 'Button')]"   #遍歷頁面所有button

  action: null

  actions: []

  times: 0

- given: []

  when: null

  then: []                     #遍歷所有文本 且文本可被點擊 長度小於10

  xpath: "//*[contains(name(), 'Text') and @clickable='true' and string-length(@text)<10]"

  action: null

  actions: []

  times: 0

- given: []

  when: null

  then: []

  xpath: "//*[@clickable='true']/*[contains(name(), 'Text') and string-length(@text)<10]"

  action: null

  actions: []

  times: 0

- given: []

  when: null

  then: []

  xpath: "//*[contains(name(), 'Image') and @clickable='true']"

  action: null

  actions: []

  times: 0

- given: []

  when: null

  then: []

  xpath: "//*[@clickable='true']/*[contains(name(), 'Image')]"

  action: null

  actions: []

  times: 0

- given: []

  when: null

  then: []

  xpath: "//*[contains(name(), 'Image') and @name!='']"

  action: null

  actions: []

  times: 0

- given: []

  when: null

  then: []

  xpath: "//*[contains(name(), 'Text') and @name!='' and string-length(@label)<10]"

  action: null

  actions: []

  times: 0

firstList: []  #優先遍歷

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:      #遇到特點事件時觸發動作, 一般處理彈窗

- given: []

  when: null

  then: []

  xpath: "share_comment_guide_btn"

  action: null

  actions: []

  times: 0

xpathAttributes:  #默認帶哪些屬性

- "name"

- "label"

- "value"

- "resource-id"

- "content-desc"

- "instance"  #動態變化的元素 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: []  #遍歷過程中的全局斷言 

- xpath: //*

  then:

  - //*[@package='com.xueqiu.android']  #可以斷言操作過程中應用是否推出

4、執行 java -jar <appcrawler Path> -c demo.yml -capability "appPackage=,appActivity=" -o /path/report


pluginList: []
saveScreen: false
reportTitle: "演練"
resultDir: ""
waitLoading: 1000
waitLaunch: 6000
showCancel: true
maxTime: 10800
maxDepth: 10
capability:
appPackage: com.xueqiu.android
appActivity: .view.WelcomeActivityAlias
noReset: "true"
fullReset: "false"
unicodeKeyboard: true
resetKeyboard: true
appium: "http://127.0.0.1:4723/wd/hub"

testcase:
name: "TesterHome AppCrawler"
steps:
- xpath: //*[@text='行情']/../android.widget.ImageView              #點擊行情
- xpath: //*[contains(@resource-id, 'buttons_container')]//*[@text='私募']  #點擊私募
- { xpath: 私募排行,action: back }                      #點擊返回

selectedList:  #遍歷模塊范圍
- xpath: //*[contains(@resource-id, 'buttons_container')]//android.widget.TextView
- xpath: //*[contains(@resource-id, 'ti_tab_indicator')]//android.widget.TextView
- xpath: //*[contains(@resource-id, 'll_stock_item_container')]//android.widget.TextView

firstList:
- xpath: 基金
lastList:
- xpath: 極速開戶
backButton:
- xpath: 轉到上一層級
triggerActions:   #遇到特定事件執行特定操作;遍歷之前執行操作,進入固定頁面  (也可以用於執行固定操作,如去彈框)
- xpath: //*[contains(@resource-id, 'home_search')]//*[contains(@resource-id, 'tv_search')]
times: 1
- xpath: //android.widget.EditText  #定位輸入框
action: alibaba  #執行輸入操作
times: 1
xpathAttributes:
- "name"
- "label"
- "value"
- "resource-id"
- "content-desc"
#- "instance"
- "text"
sortByAttribute:
- "depth"
- "list"
- "selected"
findBy: "xpath"
defineUrl: []
baseUrl: []
appWhiteList: []
urlBlackList: []
urlWhiteList: []
blackList:
- given: []
when: null
then: []
xpath: ".*[0-9]{2}.*"
action: ""
actions: []
times: 0
beforeRestart: []
beforeElement:
- given: []
when: null
then: []
xpath: "/*"
action: "Thread.sleep(500)"
actions: []
times: 0
afterElement: []
afterPage: []
afterPageMax: 2
tagLimitMax: 5   #同級別   同輩份的元素最多被遍歷5次
tagLimit:    #特定內容 最多被遍歷10次
- xpath: //*[contains(@resource-id, 'ti_tab_indicator')]//android.widget.TextView
times: 10
assertGlobal: []

 

 

 Xpath定位:

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM