AppCrawler自動遍歷工具

前言

AppCrawler是一個基于自動遍歷的app爬蟲工具. 支持android和iOS, 支持真機和模擬器. 最大的特點是靈活性. 可通過配置來設定遍歷的規(guī)則似踱。
AppCrawler地址

環(huán)境準備

快速遍歷

安裝好環(huán)境后趋艘,可以執(zhí)行以下命令, 命令參數(shù)介紹

# 查看幫助文檔
java -jar appcrawler.jar
# 運行測試
java -jar appcrawler.jar -a xueqiu.apk

通過配置文件執(zhí)行

配置文件可以幫助我們自定義遍歷規(guī)則砾脑,和自定義測試用例。

  1. 生成配置文件
# 生成配置文件
java -jar appcrawler.jar --demo
  1. 配置文件內容
---
# 插件列表
pluginList: [] 
# 是否截圖                                   
saveScreen: true  
# 報告的標題              
reportTitle: ""    
# 結果目錄             
resultDir: "20190907185946"  
# 在執(zhí)行操作后等待多少毫秒進行刷新     
waitLoading: 500               
waitLaunch: 6000
# 顯示取消
showCancel: true
# 最大運行時間
maxTime: 10800
# 默認的最大深度                      
maxDepth: 10
# appium的capability通用配置
capability:
  noReset: "true"
  fullReset: "false"
  appium: "http://127.0.0.1:4723/wd/hub"
# 測試用例
testcase:
  name: "TesterHome AppCrawler"
  steps:
  - given: []
    when: null
    then: []
    xpath: "/*"
    action: "Thread.sleep(5000)"
    actions: []
    times: 0
# 默認遍歷列表
selectedList:
- given: []
  when: null
  then: []
  xpath: "http://*[contains(name(), 'Button')]"
  action: null
  actions: []
  times: 0
- given: []
  when: null
  then: []
  xpath: "http://*[contains(name(), 'Text') and @clickable='true' and string-length(@text)<10]"
  action: null
  actions: []
  times: 0
- given: []
  when: null
  then: []
  xpath: "http://*[@clickable='true']/*[contains(name(), 'Text') and string-length(@text)<10]"
  action: null
  actions: []
  times: 0
- given: []
  when: null
  then: []
  xpath: "http://*[contains(name(), 'Image') and @clickable='true']"
  action: null
  actions: []
  times: 0
- given: []
  when: null
  then: []
  xpath: "http://*[@clickable='true']/*[contains(name(), 'Image')]"
  action: null
  actions: []
  times: 0
- given: []
  when: null
  then: []
  xpath: "http://*[contains(name(), 'Image') and @name!='']"
  action: null
  actions: []
  times: 0
- given: []
  when: null
  then: []
  xpath: "http://*[contains(name(), 'Text') and @name!='' and string-length(@label)<10]"
  action: null
  actions: []
  times: 0
# 優(yōu)先遍歷元素
firstList: []
# 最后遍歷列表
lastList:
- given: []
  when: null
  then: []
  xpath: "http://*[@selected='true']/..//*"
  action: null
  actions: []
  times: 0
- given: []
  when: null
  then: []
  xpath: "http://*[@selected='true']/../..//*"
  action: null
  actions: []
  times: 0
# 當所有元素都被點擊后默認后退控件定位
backButton:
- given: []
  when: null
  then: []
  xpath: "Navigate up"
  action: null
  actions: []
  times: 0
# 特定條件觸發(fā)執(zhí)?動作的設置,通常?于處理彈框
triggerActions:
- given: []
  when: null
  then: []
  xpath: "share_comment_guide_btn"
  action: null
  actions: []
  times: 0
# 自動生成的xpath表達式里可以包含的匹配屬性
xpathAttributes:
- "name"
- "label"
- "value"
- "resource-id"
- "content-desc"
- "instance"
- "text"
# 先按照深度depth排序,再按照list排序,最后按照selected排序尔艇。后排序是優(yōu)先級別最高的
sortByAttribute:
- "depth"
- "list"
- "selected"
# 可選 default|android|id|xpath,默認狀態(tài)會自動判斷是否使用android定位或者ios定位
findBy: "default"
# 用來確定url的元素定位xpath 他的text會被取出當作url因素
defineUrl: []
# 設置一個起始url和maxDepth, 用來在遍歷時候指定初始狀態(tài)和遍歷深度
baseUrl: []
# app白名單
appWhiteList: []
# url黑名單咆疗,用于排除某些頁面 
urlBlackList: []
# url白名單
urlWhiteList: []
# 黑名單列表 匹配風格, 默認排除內容是2個數(shù)字以上的控件
blackList:
- given: []
  when: null
  then: []
  xpath: ".*[0-9]{2}.*"
  action: null
  actions: []
  times: 0
# 在重啟session之前做的事情
beforeRestart: []
# 在執(zhí)行action之前和之后默認執(zhí)行的動作漓帚,比如等待
beforeElement:
- given: []
  when: null
  then: []
  xpath: "/*"
  action: "Thread.sleep(500)"
  actions: []
  times: 0
# 是否需要刷新或者滑動
afterElement: []
afterPage: []
# afterPage執(zhí)行多少次后才不執(zhí)行母债,比如連續(xù)滑動2次都沒新元素即取消
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
# 只需要寫given與then即可
assertGlobal: []

配置文件介紹

配置文件的參數(shù)說明

如上的配置文件是完整形態(tài)午磁,還支持簡寫形態(tài),拿testcase舉例
1. testcase

  • testcase的完整形態(tài)
    • given:所有的先決條件(先決條件通過xpath的方式進行匹配)
    • when:先決條件成?后的?為
    • then:斷言集合
  • testcase的簡寫形態(tài)
    • xpath:對應when?的xpath
    • action:對應when的action

實例

testcase:
  name: "點擊行情"  # 測試用例名稱
  steps:
  - xpath: //*[contains(@resource-id, "tab_name") and @text="行情"]    #定位模式
    action: click  # 動作
    then:
    - //*[contains(@text,'雪球熱股')]  # 斷言

2. 定位模式 xpath
定位模式支持xpath定位毡们、正則迅皇、迷糊匹配(注意:配置文件中的xpath定位模式別和appium的xpath搞混了,配置文件中的xpath只是一個參數(shù)衙熔,它支持appium的xpath的定位方法登颓,并且還支持正則和模糊匹配)

  • xpath

    • //*[@resource-id=‘xxxx’]
    • //*[contains(@text, ‘密碼’)]
  • 正則

    • ^確定$
    • ^.*輸入密碼
  • 包含

    • 密碼
    • 輸入

實例

blackList:
- xpath: ".*[0-9]{2}.*"
- xpath: "^雪球$"
- xpath: //*[@resource-id="com.xueqiu.android:id/action_search"]
- xpath: 雪

3. 動作支持 action

  • " " 只是截圖記錄
  • back 后退
  • backApp 回退到當前的app 默認等價于back?為 可定制
  • monkey 隨機事件
  • xxx() 執(zhí)?代碼
    • Thread.sleep(3000)
    • driver.swipe(0.9, 0.5, 0.1, 0.5)
  • click
  • longTap
  • 非以上所有行為是輸入 123 abcd

4. 動作次數(shù) times

# 點擊凈買入10次
triggerActions:
- xpath: 凈買入
   times: 10

實例自動遍歷雪球app行情頁面下的所有二級頁面

  1. 安裝模擬器,如mumu
  2. 安裝雪球app
  3. 啟動appium server
appium --session-override
  1. 生成配置文件
java -jar appcrawler-2.4.0-jar-with-dependencies.jar --demo
  1. 修改配置文件红氯,另存為xueqiu.yml.(注意框咙,保存為utf8編碼)
---
pluginList: []
saveScreen: true
reportTitle: "遍歷雪球行情頁的所有二級頁面"
resultDir: "20190907221950"
waitLoading: 500
waitLaunch: 6000
showCancel: true
maxTime: 10800
maxDepth: 1
capability:
  noReset: "true"
  fullReset: "false"
  appium: "http://127.0.0.1:4723/wd/hub"
  appPackage: com.xueqiu.android
  appActivity: .view.WelcomeActivityAlias
testcase:
  name: "點擊行情"
  steps:
  - xpath: //*[contains(@resource-id, "tab_name") and @text="行情"]
    action: click
    then:
    - //*[contains(@text,'雪球熱股')]
# 遍歷雪球行情頁
selectedList:
- xpath: "http://*[contains(name(), 'Button')]"
- xpath: "http://*[contains(name(), 'Text') and @clickable='true' and string-length(@text)<10]"
- xpath: "http://*[@clickable='true']/*[contains(name(), 'Text') and string-length(@text)<10]"
- xpath: "http://*[contains(name(), 'Image') and @clickable='true']"
- xpath: "http://*[@clickable='true']/*[contains(name(), 'Image')]"
- xpath: "http://*[contains(name(), 'Image') and @name!='']"
- xpath: "http://*[contains(name(), 'Text') and @name!='' and string-length(@label)<10]"
firstList: []
lastList:
- xpath: "http://*[@selected='true']/..//*"
- xpath: "http://*[@selected='true']/../..//*"
backButton:
- xpath: "Navigate up"
triggerActions:
- xpath: "share_comment_guide_btn"
xpathAttributes:
- "name"
- "label"
- "value"
- "resource-id"
- "content-desc"
- "instance"
- "text"
sortByAttribute:
- "depth"
- "list"
- "selected"
findBy: "default"
defineUrl: []
baseUrl: []
appWhiteList: []
urlBlackList: []
urlWhiteList: []
# 添加黑名單元素,避免點擊到其他地方
blackList:
- xpath: ".*[0-9]{2}.*"
- xpath: //*[contains(@resource-id, "tab_name") and @text="雪球"]
- xpath: //*[contains(@resource-id, "tab_name") and @text="自選"]
- xpath: //*[contains(@resource-id, "tab_name") and @text="關注"]
- xpath: //*[contains(@resource-id, "tab_name") and @text="交易"]
- xpath: //*[@resource-id="com.xueqiu.android:id/action_search"]
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: []

  1. 連接模擬器
# 連接模擬器
adb connect 127.0.0.1:7555
# 查看是否連接成功
adb devices
  1. 執(zhí)行測試
java -jar appcrawler-2.4.0-jar-with-dependencies.jar -c xueqiu.yml
  1. 測試報告


    測試報告
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
禁止轉載痢甘,如需轉載請通過簡信或評論聯(lián)系作者喇嘱。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市塞栅,隨后出現(xiàn)的幾起案子者铜,更是在濱河造成了極大的恐慌,老刑警劉巖放椰,帶你破解...
    沈念sama閱讀 218,755評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件作烟,死亡現(xiàn)場離奇詭異,居然都是意外死亡砾医,警方通過查閱死者的電腦和手機拿撩,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,305評論 3 395
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來如蚜,“玉大人压恒,你說我怎么就攤上這事头滔。” “怎么了涎显?”我有些...
    開封第一講書人閱讀 165,138評論 0 355
  • 文/不壞的土叔 我叫張陵坤检,是天一觀的道長。 經(jīng)常有香客問我期吓,道長早歇,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,791評論 1 295
  • 正文 為了忘掉前任讨勤,我火速辦了婚禮箭跳,結果婚禮上,老公的妹妹穿的比我還像新娘潭千。我一直安慰自己谱姓,他們只是感情好,可當我...
    茶點故事閱讀 67,794評論 6 392
  • 文/花漫 我一把揭開白布刨晴。 她就那樣靜靜地躺著屉来,像睡著了一般。 火紅的嫁衣襯著肌膚如雪狈癞。 梳的紋絲不亂的頭發(fā)上茄靠,一...
    開封第一講書人閱讀 51,631評論 1 305
  • 那天,我揣著相機與錄音蝶桶,去河邊找鬼慨绳。 笑死,一個胖子當著我的面吹牛真竖,可吹牛的內容都是我干的脐雪。 我是一名探鬼主播,決...
    沈念sama閱讀 40,362評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼恢共,長吁一口氣:“原來是場噩夢啊……” “哼战秋!你這毒婦竟也來了?” 一聲冷哼從身側響起旁振,我...
    開封第一講書人閱讀 39,264評論 0 276
  • 序言:老撾萬榮一對情侶失蹤获询,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后拐袜,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體吉嚣,經(jīng)...
    沈念sama閱讀 45,724評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,900評論 3 336
  • 正文 我和宋清朗相戀三年蹬铺,在試婚紗的時候發(fā)現(xiàn)自己被綠了尝哆。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,040評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡甜攀,死狀恐怖秋泄,靈堂內的尸體忽然破棺而出琐馆,到底是詐尸還是另有隱情,我是刑警寧澤恒序,帶...
    沈念sama閱讀 35,742評論 5 346
  • 正文 年R本政府宣布瘦麸,位于F島的核電站,受9級特大地震影響歧胁,放射性物質發(fā)生泄漏滋饲。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,364評論 3 330
  • 文/蒙蒙 一喊巍、第九天 我趴在偏房一處隱蔽的房頂上張望屠缭。 院中可真熱鬧,春花似錦崭参、人聲如沸呵曹。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,944評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽奄喂。三九已至,卻和暖如春郭卫,著一層夾襖步出監(jiān)牢的瞬間砍聊,已是汗流浹背背稼。 一陣腳步聲響...
    開封第一講書人閱讀 33,060評論 1 270
  • 我被黑心中介騙來泰國打工贰军, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人蟹肘。 一個月前我還...
    沈念sama閱讀 48,247評論 3 371
  • 正文 我出身青樓词疼,卻偏偏與公主長得像,于是被迫代替她去往敵國和親帘腹。 傳聞我的和親對象是個殘疾皇子贰盗,可洞房花燭夜當晚...
    茶點故事閱讀 44,979評論 2 355

推薦閱讀更多精彩內容

  • ORA-00001: 違反唯一約束條件 (.) 錯誤說明:當在唯一索引所對應的列上鍵入重復值時,會觸發(fā)此異常阳欲。 O...
    我想起個好名字閱讀 5,320評論 0 9
  • 一 使用目的 該工具主要是基于appium,可以面向Android和Ios移動App,或H5或微信等應用的,基于元...
    AIHorse閱讀 8,667評論 9 1
  • Appium Desktop 原滋原味的官方文檔 Appium Desktop是一款用于Mac舵盈、Windows和L...
    Roshan_閱讀 3,421評論 4 10
  • 1、風華是一指流砂球化,蒼老是一段年華秽晚。 2、山河拱手筒愚,為君一笑赴蝇。 3、幾段唏噓幾世悲歡可笑我命由我不由天巢掺。 4句伶、經(jīng)流...
    瑩_9d22閱讀 166評論 0 0
  • 閉上眼 我看到了你 長發(fā)茜茜 身姿翩翩 行走在四月的晴天 這是一個浪漫的季節(jié) 楊柳深處飄著晶瑩的雪 像白色精靈 ...
    三月晨光閱讀 226評論 1 0