這個章節介紹Appium, 開始了解系統架構、特性及優缺點

介紹的項目包含:

  • What is Appium ?
  • Types of Mobile App
  • Appium Architecture
  • Appium Concepts
  • Appium rules
  • Pros and Cons
  • Writing a good test
Let's go through each of them

What is Appium ?

  • Appium is an open source test automation framework for use with native, hybrid and mobile web apps on iOS, Android and Windows Platforms.
  • Appium is “cross-platform”: it allows you to write tests against multiple platforms (iOS, Android, Windows), using the same API.
  • It drives iOS, Android, and Windows apps using the WebDriver protocol

Types of Mobile App

Mobile App 可以分成 Native, Hybrid和Web 三種不同的型態, 下面這張圖用來說明彼此之間的差異

Appium Concepts

  • Client / Server Architecture
    1. Appium is at its heart a webserver that exposes a REST API

    2. It receives connections from a client, listens for commands, executes those commands on a mobile device

    3. Appium responds with an HTTP response representing the result of the command execution

  • Session
    1. Automation is always performed in the context of a session

    2. Clients initiate a session with a server in ways specific to each library

    3. Sessions all end up sending aPOST /sessionrequest to the server, with a JSON object called the ‘desired capabilities’ object.

    4. At this point the server will start up the automation session and respond with a session ID which is used for sending further commands.

  • Desired Capabilities
    • Desired capabilities are a set of keys and values (i.e., a map or hash) sent to the Appium server to tell the server what kind of automation session we’re interested in starting up.
  • Appium Server
    • Appium is a server written in Node.js.
  • Appium Clients
    • There are client libraries (in Java, Ruby, Python, PHP, JavaScript, and C#) which support Appium’s extensions to the WebDriver protocol.

Appium Architecture

  • Client Server Architecture

  • Based on WebDriver JSON Wire Protocol

  • Native Test libraries of respective platform is the backbone of the backend

詳細的 request and reponse flow diagram

Appium 在iOS和Android端的工作模式

在Android端, appium基於WebDriver, 並利用Bootstrap.js, 最後調用Uiautomator的命令來實現App的自動化測試 另外由於
UiAutomator對於HTML5的支持有限, appium引入了chromedriver來實現基於HTML5的自動化
Android主要原理:
  1. 左邊的WebDriver scrip是我們的測試腳本

  2. 中間是Appium的服務, Appium在這裡起了一個Server (port 4723), 跟Selenium Webdriver測試框架類似
    Appium支持標準的WebDriver JSONWireProtocol 在這裡提供了一套Web服務
    Appium Server接收web driver標準請求, 解析請求內容 調用對應的框架影響操作

  3. Appium Server會把請求轉發給中間件Bootstrap.jar, 它是用Java寫的安裝在手機上
    Bootstrap接收Appium的命令,最終通過調用UiAutomator的命令來實現

  4. 最後執行的結果由Bootstrap返回給Appium Server

  5. 另外Appium 還用到了chromedriver來支持HTML5 (webview)的測試

在iOS端, Appium同樣使用WebDriver的一套協議 與Android端測試框架不同的是,
Appium iOS封裝了Apple的Instruments框架, 主要用了Instruments裡的UI Automation(Apple的自動化測試框架)
然後在設備中注入bootstrap.js進行監聽
iOS 主要原理:
  1. 左邊的WebDriver scrip是我們的測試腳本

  2. 中間是Appium的服務, Appium在這裡起了一個Server (port 4723), 跟Selenium Webdriver測試框架類似
    Appium支持標準的WebDriver JSONWireProtocol 在這裡提供了一套Web服務
    Appium Server接收web driver標準請求, 解析請求內容 調用對應的框架影響操作

  3. Appium server調用instruments.js啟動一個socket server, 同時分出一個child process運行instruments.app,
    將bootstrap.js (一個UIAutomation腳本) 注入到device用於和外界進行互動

  4. 對於HTML5的操作, 運用了iOS webkit debug proxy來實現

Appium Rules

  1. You shouldn’t have to recompile your app or modify it in any way in order to automate it
  2. You shouldn’t be locked into a specific language or framework to write and run your tests
  3. A mobile automation framework shouldn’t reinvent the wheel when it comes to automation APIs
  4. A mobile automation framework should be open source

Pros and Cons

Appium 的優點

  1. Cross platform, Support Native, Hybrid, Web app automation
  2. No need to recompile or modify app in order to automate it, you are testing the same app you're shipping
  3. Can’t be locked into a specific language or framewok
  4. Can parallel execution with Selenium Grid

Appium 的缺點

  1. A minimum 1 second delay between each actions
  2. Debugging server side issues can be challenging sometimes
  3. Documentation or examples can sometimes be hard to find in your specific language binding (except Java)
  4. There can be delay getting new updates when changes occur to the underlining platform framework
    or operating system (ex. iOS or MacOS upgrade)

Writing a good test

在開發Automation testing時, 盡量遵守下面的原則能夠為我們帶來有效率和好維護的test csae

  1. Eliminate step duplication
  2. Put common steps in your test setup and tear down
  3. Never ever write tests that rely on another test or tests to pass
  4. Write enough steps to get from point A to point B the quickest way possible to validate your expectation
  5. Elimate steps that have no relation to the final expected result

參考資料:

results matching ""

    No results matching ""