The Selenium JSON wire protocol
The JSON wire protocol (JSONWP) is a transport mechanism created by WebDriver developers. This wire protocol is a specific set of predefined, standardized endpoints exposed via a RESTful API. The purpose of WebDriver and JSONWP is the automated testing of websites via a browser such as Firefox driver, IE driver, and Chrome driver.
Appium implements the Mobile JSONWP, the extension to the Selenium JSONWP, and it controls the different mobile device behaviors, such as installing/uninstalling apps over the session.
Let's have a look at some of the endpoints from the API which are used to interact with mobile applications:
/session/:sessionId
/session/:sessionId/element
/session/:sessionId/elements
/session/:sessionId/element/:id/click
/session/:sessionId/source
/session/:sessionId/url
/session/:sessionId/timeouts/implicit_wait
Note
The complete list of endpoints is available at https://code.google.com/p/selenium/wiki/JsonWireProtocol and https://code.google.com/p/selenium/source/browse/spec-draft.md?repo=mobile.
Appium provides client libraries similar to WebDriver that act as an interface to the REST API. These libraries have functions similar to the following method:
AppiumDriver.getPageSource();
This method will issue an HTTP request to the JSONWP, and it gets the response from the applicable API endpoint. In this case, the API endpoint that handles the getPageSource
method is as follows:
/session/:sessionId/source
The driver will execute the test script that comes in the JSON format from the AppiumDriver server to get the source. It will return the page source in the string format. In case of non-HTML (native mobile apps) platforms, the Appium library will respond with an XML document representation of the UI hierarchy. The specific structure of the document may vary from platform to platform.