這個章節介紹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
Appium is at its heart a webserver that exposes a REST API
It receives connections from a client, listens for commands, executes those commands on a mobile device
Appium responds with an HTTP response representing the result of the command execution
Session
Automation is always performed in the context of a session
Clients initiate a session with a server in ways specific to each library
Sessions all end up sending a
POST /session
request to the server, with a JSON object called the ‘desired capabilities’ object.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主要原理:
左邊的WebDriver scrip是我們的測試腳本
中間是Appium的服務, Appium在這裡起了一個Server (port 4723), 跟Selenium Webdriver測試框架類似
Appium支持標準的WebDriver JSONWireProtocol 在這裡提供了一套Web服務
Appium Server接收web driver標準請求, 解析請求內容 調用對應的框架影響操作Appium Server會把請求轉發給中間件Bootstrap.jar, 它是用Java寫的安裝在手機上
Bootstrap接收Appium的命令,最終通過調用UiAutomator的命令來實現最後執行的結果由Bootstrap返回給Appium Server
另外Appium 還用到了chromedriver來支持HTML5 (webview)的測試
在iOS端, Appium同樣使用WebDriver的一套協議 與Android端測試框架不同的是,
Appium iOS封裝了Apple的Instruments框架, 主要用了Instruments裡的UI Automation(Apple的自動化測試框架)
然後在設備中注入bootstrap.js進行監聽
iOS 主要原理:
左邊的WebDriver scrip是我們的測試腳本
中間是Appium的服務, Appium在這裡起了一個Server (port 4723), 跟Selenium Webdriver測試框架類似
Appium支持標準的WebDriver JSONWireProtocol 在這裡提供了一套Web服務
Appium Server接收web driver標準請求, 解析請求內容 調用對應的框架影響操作Appium server調用instruments.js啟動一個socket server, 同時分出一個child process運行instruments.app,
將bootstrap.js (一個UIAutomation腳本) 注入到device用於和外界進行互動對於HTML5的操作, 運用了iOS webkit debug proxy來實現
Appium Rules
You shouldn’t have to recompile your app or modify it in any way in order to automate it
You shouldn’t be locked into a specific language or framework to write and run your tests
A mobile automation framework shouldn’t reinvent the wheel when it comes to automation APIs
A mobile automation framework should be open source
Pros and Cons
Appium 的優點
Open-source and popular mobile automation tools with large community support
Cross platform, Support Native, Hybrid, Web app automation
No need to recompile or modify app in order to automate it, you are testing the same app you're shipping
Can’t be locked into a specific language or framewok
Can parallel execution with Selenium Grid
Appium 的缺點
A minimum 1 second delay between each actions
Debugging server side issues can be challenging sometimes
Documentation or examples can sometimes be hard to find in your specific language binding (except Java)
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
Eliminate step duplication
Put common steps in your test setup and tear down
Never ever write tests that rely on another test or tests to pass
Write enough steps to get from point A to point B the quickest way possible to validate your expectation
Elimate steps that have no relation to the final expected result
參考資料:
Slide: Appium Mobile Test Automation like WebDriver
https://www.slideshare.net/AndrewDzynia/appiumSlide: Continuous Integration of Mobile Apps with Docker and Appium
https://www.slideshare.net/emergya/continuous-integration-of-mobile-apps-with-docker-and-appiumSlide: [Srijan Wednesday Webinar] Mastering Mobile Test Automation with Appium
https://www.slideshare.net/SrijanOne/srijan-wednesday-webinar-mastering-mobile-test-automation-with-appium/6Slide: Android & iOS Automation Using Appium
https://www.slideshare.net/MindfireSolutions/android-ios-automation-using-appiumAppium official site introduction
http://appium.io/introduction.htmlAppium 從入門到原理
https://bestswifter.com/appium/Appium 架構原理
http://www.voidcn.com/blog/hqzxsc2006/article/p-5786773.htmlAppium简介及工作原理
http://blog.sina.com.cn/s/blog_c2c7d41b0102xd47.htmlHow Appium Works?
http://executeautomation.com/blog/how-appium-works/用实例告诉你,如何利用Appium实现移动终端UI自动化测试
http://rdc.hundsun.com/portal/article/584.mhtml