Android自動化框架API,方案及分析

1. 根據ID查找,不區分layout

示例:
GetButtonById(“login”).click()
缺點:
a. 每次寫腳本,都要藉助Hierarchy Viewer,來獲取“login”。
b. ”login”這個字符串不能寫錯,所以每次都要去確認一下。
優點:
a. 簡潔

2. 按layout中xml文件樹型結構

示例:
Layout(Main2.class).relativeLayout_id1().relativeLayout_id2().relativeLayout_id3().login().click
Layout(Main2.class).relativeLayout_id1().relativeLayout_id2().search_box().setText(“123”)
Layout(Main2.class).relativeLayout_id4().hot_store.click
缺點:
a. 藉助Hierarchy Viewer,來熟悉UI。
b. 層級可能很多6個,代碼長;
c. 一旦路徑走錯了,下面就不知道是啥了;
d. 受開發調整結構的限制。
優點:
a. 每個relativeLayout下的控件不會很多;
b. 代碼智能感應,不會寫錯。

3. 按類型平鋪

示例:
Layout(Main2.class).Button().login().click()
Layout(Main2.class).TextView().hot_store().click()
Layout(Main2.class).EditText().search_box().setText(“123”)
缺點:
a. 藉助Hierarchy Viewer,來熟悉UI。
b. 看着像Button實際上是個TextView,這時候測試需要了解一些特殊TextView (像Button);
c. 分類下面的view平鋪,可能很多20個,不好找。
優點:
a. 代碼智能感應,不會寫錯;
b. 路徑短;
c. 可以增加過濾黑名單。
d. 靈活應對開發調整結構。

4. 使用Automan的PageModel思想

示例:
Layout(Main2.class).LoginArea().login().click()
Layout(Main2.class).StoreSubmodel().hot_store().click()
Layout(Main2.class).SearchSubmodel().SearchArea().search_box().setText(“123”)
缺點:
a. 編輯PageModel需要人肉參與,起中文名字方便做爲eclipse提示。
優點:
a. 代碼智能感應,不會寫錯;
b. 可以通過導入layout xml的方式,通過人工參與刪減,生成PageModel;
c. 在建PageModel時,需要藉助Hierarchy Viewer對UI有一定的瞭解。
d. 靈活應對開發調整結構。

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