AppCrawler運用總結


一.環境

1.環境准備:安裝安卓SDK + 真機 + appcrawler-2.1.3.jar

在放 appcrawler-2.1.0.jar 的文件夾下執行以下命令:

1.生成yml的demo:java -jar appcrawler-2.1.3.jar –demo

2.更改並運行yml配置文件:java -jar appcrawler-2.1.3.jar  -c example. yml

3.Java -jar appcrawler-2.1.0.jar -a jingdata.apk -c config.yml --output wyy/

二.參數說明

1、java -jar appcrawler-2.1.0.jar –capability appPackage=xxxxxx,appActivity=xxxxxx 
2、命名啟動appium:appium –session-override

3、配置文件使用:true和false是開啟和關閉的意思 
logLevel:日志級別 
saveScreen:是否截圖 
reportTitle:報告名字 
screenshotTimeout:屏幕超時時間 
currentDriver:當前設備(Android/iOS) 
resultDir:結果文件夾名,給定后,將不動態命名 
tagLimitMax:ios的元素tag控制 
tagLimit:給tag 
maxTime:最大運行時間 
showCancel:應該是控制是否展示注釋 
capability:用於配置appium 
androidCapability:Android專屬配置,最后會和capability合並 
iosCapability:iOS專屬配置 
urlWhiteList/blackList:白名單/黑名單 
xpathAttributes:用來設定可以用那些種類型去定位控件 
defineUrl:用來確定url的元素定位xpath 他的text會被取出當作url因素(沒理解) 
baseUrl:設置一個起始url和maxDepth, 用來在遍歷時候指定初始狀態和遍歷深度 
maxDepth:默認的最大深度10, 結合baseUrl可很好的控制遍歷的范圍 
appWhiteList:app白名單,如果跳轉到其他app,需要設定規則,是否允許停留在次app中 
headFirst:是否是前向遍歷或者后向遍歷 
enterWebView:是否遍歷WebView控件 
urlBlackList:url黑名單.用於排除某些頁面 
urlWhiteList:url白名單, 第一次進入了白名單的范圍, 就始終在白名單中. 不然就算不在白名單中也得遍歷. 
上層是白名單, 當前不是白名單才需要返回 
defaultBackAction:默認的返回動作(沒看到例子,貌似不特指的話,是click) 
backButton:給一些返回控件,用於返回動作使用 
firstList:優先遍歷元素 
selectedList:默認遍歷列表,如果不是指定的類型,而是確定控件,會分別點擊控件 
lastList:最后遍歷的元素 
blackList:排除某些控件 
triggerActions:制定規則(action、xpath、times) 
autoCrawl:自動抓取,看源碼指定true后運行crawl(conf.maxDepth)命令 
(crawl——清空堆棧 開始重新計數)應該是appcrawler的主要方法 
asserts:斷言,用於是否失敗的判斷 
testcase:測試用例,看appcrawler日志,每次都是首先運行用例才會往下執行 
beforeElementAction:貌似沒什么人用,字面意思在元素動作之前 
afterElementAction:與beforeElementAction的待遇差不多 
afterUrlFinished:也是很冷門的待遇 
monkeyEvents:monkey的點擊數 
monkeyRunTimeSeconds:monkey運行時間 
given是條件 或輸入 when是觸發條件和動作 then是斷言 
4、一次ctrl+c生成報告,兩次ctrl+c是強行退出 
5、終端輸入Scala進入Scala解釋器,輸入:q或:quit退出解釋器 
6、遍歷的深度應該怎么設置好,總是跳到其它頁面,就回不到當前頁面繼續遍歷了,看文檔 通過黑白名單 
7、設置一個起始url和maxDepth, 用來在遍歷時候指定初始狀態和遍歷深度

  • WebDriver 
    1. 根據id class xpath進行定位
  • AppCrawler 
    1. 先getPageSoruce獲取所有的元素列表 
    2. 根據xpath直接選擇元素 
    3. 截圖時增加對選擇控件的高亮區分 
    4. 寬松策略的自動化機制

  • Page Source解讀 
    Android 
    1. tag class 
    2. resource-id 
    3. content-desc 
    4. text 
    iOS 
    1. tag 
    2. name 
    3. label 
    4. value

  • xpath的定位 
    絕對定位 /xxx/ddd/dddd 
    相對定位 //android.widget.Button 
    查找 
    1. //* 
    2. //*[contains(@resource-id,’login’)] 
    3. //*[@text=’登錄’] 
    4. //*[contains(@resource-id,’login’) and contains(@text,’登錄’)] 
    5. //[contains(@text,’看點’)]/ancestor:://*[contains(name(),’EditText’)] 
    6. //*[@clickable=”true”]//android.widget.TextView[string-length(@text)>0 and string-length(@text)<20]

  • 多種方式匹配 
    xpath 
    1. //*[@resource-id=’xxxx’] 
    2. //*[contains(@text,’密碼’)] 
    正則 
    1. ^確定¥ 
    2.^.輸入密碼 
    包含 
    1. 密碼 
    2. 輸入 
    3. 請

自動遍歷過程 
信息的獲取 
把當前app的界面dump為xml結構 
獲取待遍歷元素 
遍歷范圍selectedList 
過濾黑名單 小控制 不可見控件 blackList 
重新控件順利firstList lastList 
跳過已點擊 + 跳過限制點擊的控件tagLimit 
跟進匹配的規則執行action 
循環上面的步驟

問題記錄

  1. 設置登錄賬號、密碼
triggerActions:
- action: "click" xpath: "//*[@resource-id='com.xxx.myfinance:id/login_tv']" times: 1 - action: "153xxxxxxxx" xpath: "//*[@resource-id='com.xxx.myfinance:id/phone_edit']" times: 1 - action: "123456" xpath: "//*[@resource-id='com.xxx.myfinance:id/pwd_edit']" times: 1 - action: "click" xpath: "//*[@resource-id='com.xxx.myfinance:id/btn_submit']" times: 1
 2.  編輯EditText

方式一:

 triggerActions:
  - action: "10000" xpath: "//*[@class='android.widget.EditText']" times: 1 

備注:times只能寫1,否則EditText控件一直在那復制剪切 
不適用需要多次輸入的EditText

方式二:

testcase:
  name: "sui guan jia" steps: - when: xpath: //*[@resource-id='com.feidee.myfinance:id/cash_amount'] action: ${random.int[100,1000]} times: 0 then: []

備注:可點擊的EditText獲取不到

clickedIndex=-1 action=Ready
 xpath=//*[@resource-id=\"com.feidee.myfinance:id/action_bar_root\" and @index=\"0\"]/*[@resource-id=\"android:id/content\" and @index=\"0\"]/*[@index=\"0\"]/*[@resource-id=\"com.feidee.myfinance:id/common_toolbar\" and @index=\"0\"] !!! CANCELED !!!

 

3 appcrawler經常會出現一些錯誤: 
2018-05-12 10:53:27 ERROR [Crawler.crawl.203] crawl not finish, return with exception 
2018-05-12 10:53:27 ERROR [Crawler.crawl.204] Unable to launch the app: Error: Trying to start logcat capture but it’s already started! (WARNING: The server did not provide any stacktrace information) 
Command duration or timeout: 0 milliseconds 
不太清楚,為什么會報錯…… 總的感覺是getPageSoruce未獲去到元素 
所以瞎改了

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')] - //*[@clickable='true']//*[contains(name(), 'Layout')] - //*[@class='android.view.ViewGroup'] - //*[@class='android.widget.EditText']

 

4 testcase 與 triggerActions 
自己試了一下,發現是先查找testcase,再查找triggerActions 
但是還是感覺邏輯關系有點混亂,或者沒有辦法支持復雜的邏輯關系,讓自己的case更有邏輯順序。

綜合考慮:2 和 4糾結了好久,試了個遍,可能是appcrawler自己的缺陷,所以放棄了這個工具。

又看到了新的工具AIMonkey: https://testerhome.com/topics/11719 
后面准備研究下


免責聲明!

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



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