Appium翻譯篇【 appium/docs/en/about-appium/intro.md 】

2020-08-10 17:38:52

Introduction to Appium

Appium is an open-source tool for automating native, mobile web, and hybrid applications on iOS mobile, Android mobile, and Windows desktop platforms. Native apps are those written using the iOS, Android, or Windows SDKs. Mobile web apps are web apps accessed using a mobile browser (Appium supports Safari on iOS and Chrome or the built-in ‘Browser’ app on Android). Hybrid apps have a wrapper around a 「webview」 – a native control that enables interaction with web content. Projects like Apache Cordova or Phonegap make it easy to build apps using web technologies that are then bundled into a native wrapper, creating a hybrid app.

Importantly, Appium is 「cross-platform」: it allows you to write tests against multiple platforms (iOS, Android, Windows), using the same API. This enables code reuse between iOS, Android, and Windows testsuites.

For specific information about what it means for Appium to 「support」 its platforms, and automation modalities, please see the platform support doc.

Appium是一個開源工具,用於iOS移動平臺、Android移動平臺和Windows桌面平臺上的原生、移動web和混合應用程式的自動化。原生應用是指那些使用iOS、Android或Windows sdk編寫的應用。移動web應用程式是通過移動瀏覽器存取的web應用程式(Appium支援iOS上的Safari和Chrome或Android上內建的瀏覽器應用程式)。混合應用程式有一個webview包裝器——一個可以與web內容互動的原生控制元件。類似於Apache Cordova或Phonegap專案,可以很容易地使用web技術構建應用程式,然後將這些應用程式打包到一個原生包裝器中,建立一個混合應用程式。
重要的是,Appium是跨平臺的:它允許你用相同的API編寫針對多個平臺(iOS, Android, Windows)的測試。這使得iOS、Android和Windows測試套件之間的程式碼重用成爲可能。
有關Appium支援其平臺和自動化模式的具體資訊,請參閱platform support doc。

Appium Philosophy

Appium was designed to meet mobile automation needs according to a philosophy outlined by the following four tenets:

  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, in spirit and practice as well as in name!

Appium的設計是爲了滿足移動自動化的需要,如下四個原則:

  1. 不應該爲了自動化而重新編譯你的應用或者修改它。
  2. 不應該被限制在特定的語言或框架中來編寫和執行測試。
  3. 當涉及到自動化api時,一個移動自動化框架不應該重新造輪子。
  4. 當涉及到自動化api時,一個移動自動化框架不應該重新發明輪子。

Appium Design

So how does the structure of the Appium project live out this philosophy? We meet requirement #1 by using vendor-provided automation frameworks under the hood. That way, we don’t need to compile in any Appium-specific or third-party code or frameworks to your app. This means you’re testing the same app you’re shipping. The vendor-provided frameworks we use are:

  • iOS 9.3 and above: Apple’s XCUITest
  • iOS 9.3 and lower: Apple’s UIAutomation
  • Android 4.3+: Google’s UiAutomator/UiAutomator2
  • Windows: Microsoft’s WinAppDriver

那麼Appium專案的結構是如何實現這一理唸的呢?
爲了實現需求#1,使用供應商提供的自動化框架。這樣,就不需要把 Appium 特定的或者第三方的程式碼編譯進應用,這也意味着正在測試的應用和最終發佈的應用是一樣的。我們使用的供應商提供的框架是:

  • iOS 9.3 及以上: XCUITest
  • iOS 9.3 及以下: UIAutomation
  • Android 4.3+: UiAutomator/UiAutomator2
  • Windows: WinAppDriver

We meet requirement #2 by wrapping the vendor-provided frameworks in one API, the WebDriver API. WebDriver (aka 「Selenium WebDriver」) specifies a client-server protocol (known as the JSON Wire Protocol). Given this client-server architecture, a client written in any language can be used to send the appropriate HTTP requests to the server. There are already clients written in every popular programming language. This also means that you’re free to use whatever test runner and test framework you want; the client libraries are simply HTTP clients and can be mixed into your code any way you please. In other words, Appium & WebDriver clients are not technically 「test frameworks」 – they are 「automation libraries」. You can manage your test environment any way you like!

爲了實現需求#2,將供應商提供的框架包裝在一個API (WebDriver API)中。WebDriver(又名「Selenium WebDriver」)指定了一個用戶端-伺服器協定(稱爲JSON有線協定)。對於這種客戶機-伺服器體系結構,可以使用任何語言編寫的客戶機向伺服器發送適當的HTTP請求。現在已經有了用每種流行程式語言編寫的客戶機。這也意味着你可以自由地使用任何你想要的測試執行器和測試框架;用戶端庫只是簡單的HTTP用戶端,可以按照您的喜好將其混合到您的程式碼中。

We meet requirement #3 in the same way: WebDriver has become the de facto standard for automating web browsers, and is a W3C Working Draft. Why do something totally different for mobile? Instead we have extended the protocol with extra API methods useful for mobile automation.

以同樣的方式實現需求#3:WebDriver 已經成爲 Web 瀏覽器自動化事實上的標準,並且是一個 W3C 工作草案。何必在行動端做完全不同的嘗試?相反,我們通過附加額外的 API 方法 擴充套件協定,這些方法對移動自動化非常有用。

It should be obvious that requirement #4 is a given – you’re reading this because Appium is open source.

顯然,需求#4是已知的——閱讀本文就是因爲Appium是開源的。

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, and responds with an HTTP response representing the result of the command execution. The fact that we have a client/server architecture opens up a lot of possibilities: we can write our test code in any language that has a http client API, but it is easier to use one of the Appium client libraries. We can put the server on a different machine than our tests are running on. We can write test code and rely on a cloud service like Sauce Labs to receive and interpret the commands.

Appium本質上是一個暴露REST API的網路伺服器,。它接收來自客戶機的連線,偵聽命令,在移動裝置上執行這些命令,並使用表示命令執行結果的HTTP響應進行響應。客戶機/伺服器架構提供了很多可能性:我們可以用任何具有http用戶端API的語言編寫測試程式碼,但是使用Appium用戶端庫更容易。我們可以將伺服器放在其他機器上,而不是執行測試的機器。我們可以編寫測試程式碼並依賴於像Sauce Labs這樣的雲服務接受和解釋命令。

Session

Automation is always performed in the context of a session. Clients initiate a session with a server in ways specific to each library, but they 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.

自動化總是在對談的上下文中執行,用戶端庫以特定於每個庫的方式與伺服器發起對談,但它們最終都向伺服器發送了一個POST /session請求,以及一個名爲「所需功能」物件的JSON物件。此時,伺服器將啓動自動化對談並使用一個用於發送進一步命令的對談ID進行響應。

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. There are also various capabilities which can modify the behavior of the server during automation. For example, we might set the platformName capability to iOS to tell Appium that we want an iOS session, rather than an Android or Windows one. Or we might set the safariAllowPopups capability to true in order to ensure that, during a Safari automation session, we’re allowed to use JavaScript to open up new windows. See the capabilities doc for the complete list of capabilities available for Appium.

所需功能是一組發送到Appium伺服器的鍵和值(map或hash),以告訴伺服器我們想要啓動哪種自動化對談。還有各種各樣的功能可以在自動化過程中修改伺服器的行爲。例如,我們可以設定iOS的platformName功能來告訴Appium我們想要一個iOS對談,而不是一個Android或Windows對談。或者我們可以將safariAllowPopups功能設定爲true,以確保在Safari自動化對談期間,我們可以使用JavaScript開啓新的視窗。有關Appium可用功能的完整列表,請參閱 capabilities doc。

Appium Server

Appium is a server written in Node.js. It can be built and installed from source or installed directly from NPM:

Appium 是一個用 Node.js 寫的伺服器。可以從原始碼構建安裝或者從 NPM 直接安裝:

$ npm install -g appium
$ appium

The beta of Appium is available via NPM with npm install -g appium@beta. It is the development version so it might have breaking changes. Please uninstall appium@beta (npm uninstall -g appium@beta) before installing new versions in order to have a clean set of dependencies.

Appium 的 beta 版本可以通過 NPM 使用 npm install -g appium@beta 指令進行安裝。它是開發版本,所以可能存在破壞性的變更。在安裝新版本前,請解除安裝 appium@beta (npm uninstall -g appium@beta)以獲得一組乾淨的依賴。

Appium Clients

There are client libraries (in Java, Ruby, Python, PHP, JavaScript, and C#) which support Appium’s extensions to the WebDriver protocol. When using Appium, you want to use these client libraries instead of your regular WebDriver client. You can view the full list of libraries here.

有一些用戶端庫(Java、Ruby、Python、PHP、JavaScript和c#)支援Appium對WebDriver協定的擴充套件。在使用Appium時,您希望使用這些用戶端庫而不是常規的WebDriver用戶端。您可以在here檢視庫的完整列表。

Appium Desktop

There is a GUI wrapper around the Appium server that can be downloaded for any platform. It comes bundled with everything required to run the Appium server, so you don’t need to worry about Node. It also comes with an Inspector, which enables you to check out the hierarchy of your app. This can come in handy when writing tests.

這有一個 Appium 伺服器的圖形介面可以下載,它適用於任何平臺。它打包了 Appium 伺服器執行需要的所有東西,所以你不需要爲 Node 而煩惱。它們還提供一個 Inspector 使你可以檢視應用程式的層級結構。這在寫測試時可以派上用場。

Getting Started

Congratulations! You are now armed with enough knowledge to begin using Appium. Why not head to the getting started doc for more detailed requirements and instructions?

恭喜你!現在已經掌握了足夠的知識,可以開始使用Appium了。爲什麼不去getting started doc獲取更詳細的要求和說明呢?