Appium學習筆記||7、用UIAutomator API定位

1、建議添加下邊內容到desitred_caps

  'automationName' = 'UiAutomator2'java

 

appium跨平臺,可是uiautomator只針對安卓android

 

2、UI Automator  (https://developer.android.google.cn/training/testing/ui-automator)

  1. 安卓要求4.3以上git

  2. 測試框架:正則表達式

    A. UIAutomatorViewer:檢查佈局層次結構的查看器的工具,以前介紹過。app

   

 

    B. UIDevice類,能夠訪問設備屬性,執行系統操做,用於檢索狀態信息並在目標設備上執行操做的API框架

  

    C. UIAutomatorAPI,支持跨應用程序UI測試的API工具

   

 

3、 經過class name和text屬性查找(使用java代碼實現)

  • 代碼:

  code = 'new UiSelector().className("android.widget.TextView").text("口碑最佳")’佈局

  ele = driver.find_element_by_android_uiautomator(code)測試

  • 在Appium中驗證:

  

 

4、經過resorce id屬性查找

  • 代碼:

  code = 'new UiSelector().resourceId("com.ibox.calculators:id/digit3")'ui

  ele = driver.find_element_by_android_uiautomator(code)

  • appium中驗證:

  

 

 

5、經過child Selector和instance方法

  • 代碼:

  code = ‘new UiSelector().resourceId("io.manong.developerdaily:id/tab_bar").childSelector(new UiSelector().className("android.widget.TextView").instance(3))’

  • appium中驗證:

  

 

 

6、三種text方法

  1. textContains:文本包含

  2. textStartsWith:文本以什麼開頭

  3. textMatches:文本匹配什麼正則表達式

相關文章
相關標籤/搜索