之前的隨筆說過摆舟,最近入坑使用appium server v1.7.1挽拔,本著對(duì)appium負(fù)責(zé)任的態(tài)度---不拋棄矛纹、不放棄抵栈,繼續(xù)在新的app上用appium 折騰
前言
??學(xué)習(xí)一門開源框架之前溪掀,必須搞清楚各個(gè)模塊之間的關(guān)系事镣,比如舉例appium來說,得理清楚appium desktop揪胃、appium server 璃哟、appium client和使用語言(java、python)之間關(guān)系喊递,這里不一一敘述随闪。
-
本文使用的client版本
??Appium-Python-Client (0.26)
-
本文使用的driver
??appium-uiautomator2-driver
關(guān)于API 的碎碎言(后續(xù)會(huì)繼續(xù)碎碎)
-
獲取app的strings.xml的內(nèi)容(android)
原方法:app_strings(language=None, string_file=None)
使用場景舉例:
??app支持多語言,通過腳本的方式獲取各個(gè)語言下對(duì)應(yīng)的字符串骚勘,與定義文檔對(duì)比
-
獲取app的strings.xml的內(nèi)容(android)
??原理說明:
????實(shí)際是通過執(zhí)行aapt d --values resources <apk>
獲得铐伴,因此caps一定要包含apk的完整路徑
????app_strings()
支持獲取多個(gè)語言的strings.xml內(nèi)容,如果想要獲取默認(rèn)或者不同語言的strings怎么辦呢俏讹?通過反編譯apk可知当宴,res文件夾結(jié)構(gòu)如下
??結(jié)合反編譯后的結(jié)構(gòu)和傳遞的參數(shù)可以推測,如果想要獲取各種語言下的strings,只需要傳language
參數(shù)值,如獲取中文環(huán)境下的strings,language=zh
;然而想要獲取默認(rèn)的strings則沒那么順暢泽疆,如果你認(rèn)為不傳language參數(shù)就可以獲取得到户矢,那么我只能告訴你,想多了殉疼,不過記得舊版本可以哈梯浪,實(shí)際上不傳任何參數(shù)則默認(rèn)獲取language=en
對(duì)應(yīng)的strings捌年。想要獲取默認(rèn)的strings,換了一種巧妙的方式驱证,language隨便傳一個(gè)非語言代號(hào)延窜,例如這里我的language參數(shù)設(shè)置為default
- 關(guān)于app的啟動(dòng)
原方法
launch_app()
start_activity(app_package, app_activity, **opts)
background_app(seconds)
- launch_app()
啟動(dòng)app,相當(dāng)于先殺死app再重新啟動(dòng)抹锄,該方法實(shí)際執(zhí)行了這段adb命令adb shell am start -W -n com.yf.smart.coros.alpha/com.yf.smart.weloopx.app.entry.SplashScreenActivity -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000
逆瑞,對(duì)于依賴藍(lán)牙連接其他設(shè)備的app來說,'殺死'會(huì)導(dǎo)致藍(lán)牙斷開伙单,然后有時(shí)候并不是希望的結(jié)果 - start_activity(app_package, app_activity, **opts)
同樣可以作為啟動(dòng)app來使用获高,可定制適合自己的啟動(dòng)方式或者啟動(dòng)其他app,必須參數(shù)app的package和activity吻育,可選參數(shù)opts
opts詳細(xì):
- app_wait_package - Begin automation after this package starts (optional).
- app_wait_activity - Begin automation after this activity starts (optional). 啟動(dòng)一個(gè)activity時(shí)需要經(jīng)過中間某個(gè)activity時(shí)需要填寫
- intent_action - Intent to start (optional).
- intent_category - Intent category to start (optional).
- intent_flags - Flags to send to the intent (optional).
- optional_intent_arguments - Optional arguments to the intent (optional).
- dont_stop_app_on_reset - Should the app be stopped on reset (optional)? 表示要不要重置app念秧,簡單說,要不要?dú)⑺繿pp來啟動(dòng)
background_app(seconds)
設(shè)置app后臺(tái)多少秒后重啟布疼,app進(jìn)入后臺(tái)摊趾,其實(shí)是執(zhí)行home鍵操作,重啟則直接熱啟動(dòng)app游两,不會(huì)殺死app- 模擬返回與home操作
原方法
press_keycode( keycode, metastate=None)
keyevent( keycode, metastate=None)
- press_keycode()
發(fā)送按鍵碼砾层,常見:4表示back,3表示home
可參考:https://developer.android.com/reference/android/view/KeyEvent.html - keyevent( keycode, metastate=None)
執(zhí)行會(huì)報(bào)404贱案,估計(jì)被uiautomator2 driver棄用了肛炮,所以不推薦使用
結(jié)語
?? 一定要看API ,一定要看github宝踪!一定要看API 侨糟,一定要看github!一定要看API 瘩燥,一定要看github秕重!重要的話重復(fù)三遍