測開面試 | 自動化測試之工具篇


一、Instrumentation(https://developer.android.com/reference/android/app/Instrumentation.html)
1、 Instrumentation 原理是什么?

  • 通過直接調用被測應用的類實現自動化測試
  • 和被測應用處於同一個進程內

2、 Instrumentation 測試什么?

  • 功能測試
  • Activity 生命周期的測試
  • 模擬數據庫操作的測試
  • 兼容性測試

3、 什么情況使用 Instrumentation?

  • 使用 Java Junit 框架
  • 需要進行白盒測試時
  • 需要使用 Mock 技術模擬系統對象時

二、UIAutomator(https://developer.android.com/training/testing/ui-automator)
1、 UIAutomator 原理是什么?

  • Android UI 自動化測試工具
  • 不需要源碼,基於 Java 開發語言
  • UiDevice, UiSelector, UiScrollable, UiObject, UiCollection

2、 UIAutomator 可以測試什么?

  • App UI 層的交互操作
  • 不需要源碼,可以模擬跨進程過程
  • 基於 Java JUnit 框架,黑盒 UI 自動化

3、 如何識別 App 視圖內的元素?

  • UiAutomatorViewer(<Android_SDK>/tools/bin/)
  • 可以識別元素的 id、classname、bounds 等

三、Selendroid&Robotium
1、 Selendroid 的原理?(http://selendroid.io/)
Selendroid 四大組件:

  • Selendroid Client: WebDriver + 移動特性的實現
  • Selendroid Server: 一個 Instrumentation APK
  • AndroidDriver-App: 一個 WebViewActivity,即瀏覽器
  • Selendroid-Standalone: 大總管,負責准備環境

2、 Robotium 的原理?(https://github.com/RobotiumTech/robotium)

  • 基於 Instrumentation 進行封裝,實現的 Android 測試框架
  • 封裝了 Solo 類庫,提供自動化測試 API
  • 由於是基於 Instrumentation,測試時需要源碼

四、Appium(http://appium.io/)
1、 什么是 Appium?

  • 一個開源的移動端 UI 自動化測試框架

2、 Appium 的理念?

  • 不需要 App 源碼
  • 不局限於語言或者框架
  • 接口統一,不需要重復開發
  • 必須是開源的

3、 Appium 相關的概念?

  • C/S 架構,Appium 核心是一個 Web 服務器
  • Session,客戶端初始化 Session 與服務端交互
  • Desired Capabilities,初始化時的鍵值對組合
  • Appium Server,操作與驅動手機
  • Appium Client,支持多語言調用

4、 Appium 環境包含哪些內容?

  • Android SDK、JDK、Appium
  • PyCharm、Python 環境
  • 庫:Selenium、Appium-Python-Client

5、 Appium 支持哪些開發語言?

  • Java、Javascript、PHP、Python、Ruby、Perl、C#、Object-C

6、 Appium 初始化時需要配置哪些內容?

  • platformName,目標設備平台(Android/iOS)
  • platformVersion,目標設備平台版本
  • deviceName,目標設備名稱
  • appPackage,應用包名(Android)
  • appActivity,應用活動名(Android)
  • automationName,自動化驅動類型(Selendroid/Appium)
  • unicodeKeyboard,是否使用 Appium 輸入法
  • resetKeyboard,是否恢復默認鍵盤

7、 Appium 測試 Native App 的原理?

8、 Appium 測試 Hybrid App 的原理?

9、 Appium 測試 iOS App 的原理?

五、如何自動化測試 Native App?
1、 元素的定位、識別工具?

  • 第一個選擇:UIAutomatorViewer
  • 第二個選擇:Appium 的 Inspector

2、 定位元素的 API 都有哪些?

  • find_element_by_accessibility_id
  • find_element_by_id
  • find_element_by_name
  • find_element_by_xpath
  • find_element_by_class_name
  • find_elements_by_accessibility_id
  • find_elements_by_id
  • find_elements_by_name
  • find_elements_by_xpath
  • find_elements_by_class_name

3、 腳本的編寫規則
LOVE 規則:

  • L:Locate 定位
  • O:Operate 操作
  • V:Verify 驗證
  • E:Exception 異常的處理

4、 初始化注意事項

  • 1、 不需要指定 App 的包路徑
  • 2、 默認使用 Appium 驅動
  • 3、 如果需要輸入中文,需要添加輸入法相關的配置

六、如何自動化測試 Hybrid App?
1、 元素的定位、識別工具?

  • 1、 Native 部分,UIAutomatorViewer 或者 Appium Inspector
  • 2、 WebView 部分,Chrome 瀏覽器的調試模式

2、 定位元素的 API 都有哪些?

  • find_element_by_id(HTML 頁面中的 ID)
  • find_element_by_name
  • find_element_by_xpath
  • find_element_by_link_text
  • find_element_by_tag_name
  • find_element_by_class_name
  • find_elements_by_id
  • find_elements_by_name
  • find_elements_by_xpath
  • find_elements_by_link_text
  • find_elements_by_tag_name
  • find_elements_by_class_name

3、 腳本的編寫規則
S-LOVE 規則

  • S:Switch 在 Native 和 WebView 之間切換
  • L:Locate 定位
  • O:Operate 操作
  • V:Verify 驗證
  • E:Exception 異常的處理

4、 初始化注意事項

  • 需要明確指定驅動名稱為:Selendroid
  • 需要明確指定 App 的路徑(重簽名用)

七、如何使用 Selenium 測試 WEB 頁面?(https://www.seleniumhq.org/)
1、 環境的准備

  • 工具:Pycharm、Chrome
  • 包:Selenium、Python
  • WebDriver:Chrome Driver/Firefox Driver/IE Driver 等

2、 元素識別工具是什么?

  • Firefox 或者 Chrome 的調試工具

3、 元素定位的方法?

  • find_element_by_id(HTML 頁面中的 ID)
  • find_element_by_name
  • find_element_by_xpath
  • find_element_by_link_text
  • find_element_by_tag_name
  • find_element_by_class_name
  • find_elements_by_id
  • find_elements_by_name
  • find_elements_by_xpath
  • find_elements_by_link_text
  • find_elements_by_tag_name
  • find_elements_by_class_name

八、如何使用 Appium 測試 WAP 頁面?
1、 環境的准備

  • IDE:PyCharm
  • 包:Python、Selenium、Appium-Python-Client
  • 工具:Appium、Chrome

2、 元素的識別

  • Chrome 瀏覽器調試 WAP 頁面

3、 腳本的編寫

  • 初始化時,指定 browsername 為:Browser
  • 自動化測試代碼和 Selenium 相同

歡迎關注微信公眾號"測試開發Stack"


免責聲明!

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



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