Dev::Coder 在電梯裡遇見雙胞胎
首頁 | 關於我 | 筆記 // 當你開始尋找,你就已經在前往的路上...

由於 Appium 是走 JSON Wire Protocol,當然可以用 Selenium WebDriver 的 client libraries 的來操控。不過 Appium 1.0 實作了擴充版的 Mobile JSON Wire Protocol Specification,所以得用擴充版的 client library 來操控,才能支援 Appium 完整的功能。

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.

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.

從實作細節來看,Appium client library 確實是在 Selenium WebDriver client library 上直接擴充。以 Python 為例:

from selenium import webdriver
# ...

class WebDriver(webdriver.Remote): # 1
    # ...

    def find_elements_by_accessibility_id(self, id):
        """Finds elements by accessibility id.

        :Args:
         - id - a string corresponding to a recursive element search using the
         Id/Name that the native Accessibility options utilize

        :Usage:
            driver.find_elements_by_accessibility_id()
        """
        return self.find_elements(by=By.ACCESSIBILITY_ID, value=id)

    # ...

    # convenience method added to Appium (NOT Selenium 3) 2
    def scroll(self, origin_el, destination_el):
        """Scrolls from one element to another

        :Args:
         - originalEl - the element from which to being scrolling
         - destinationEl - the element to scroll to

        :Usage:
            driver.scroll(el1, el2)
        """
        action = TouchAction(self)
        action.press(origin_el).move_to(destination_el).release().perform()
        return self

    # ...
1 appium.webdriver.webdriver.WebDriver 直接繼承自 selenium.webdriver.Remote
2 Appium 特有的 methods 會被標上 "NOT Selenium 3",剩下的應該都是未來 Selenium 3 應該會有的標準吧?

Java client library 也是類似的狀況:

import org.openqa.selenium.*;
import org.openqa.selenium.remote.*;
// ...

public class AppiumDriver extends RemoteWebDriver implements MobileDriver, ContextAware,
        Rotatable, FindsByIosUIAutomation, FindsByAndroidUIAutomator, FindsByAccessibilityId {

    // ...

覺得這份文件有幫助?別忘了按個讚並分享給更多的人、留下你/您的意見...

comments powered by Disqus