Files
appium/lib/protocol
Dan Graham 7ffda66813 Fixed W3C error messaging (#182)
* Do proxying for W3C responses
  * If a W3C Response is provided by a proxy, map to the correct error
  * Checks if `value` is an object and `value.error` and maps it based on that (`value.error` is the W3C error code)
  * Broke off `errorFromCode` into `errorFromMJSONWPStatusCode` and `errorFromW3CJsonCode`
* Rename '.error' property to correct W3C property
  * The error property in the ProtocolError objects should match up with https://www.w3.org/TR/webdriver/#handling-errors under the 'JSON Error Code' column
  * Added tests for all of these
* Make ProxyRequestError work for W3C
  * Added an arg called `.w3c` that passes in the proxied W3C error
  * Fixed the `getActualError` function that looks for the .w3c variable and parses error from the code
2018-02-05 11:55:56 -08:00
..
2018-02-05 11:55:56 -08:00
2018-02-05 11:55:56 -08:00
2018-02-05 11:55:56 -08:00
2018-01-30 07:22:20 -05:00

webdriver and mobile-json-wire protocols

An abstraction of the Mobile JSON Wire Protocol (spec) and the W3C Wire Protocol (spec with Appium extensions (as specified here).

Protocol Detection

In the event that a session is requested, and both MJSONWP and W3C capabilities are provided, like this

{
  "capabilities: {
    "alwaysMatch": {...}, 
    "firstMatch": [{...}, ...]
  },
  "desiredCapabilities": {...}
}

a W3C session will be served unless the W3C Capabilities are incomplete. So if the "desiredCapabilities" object has more keys then whatever the capabilities were matched for the W3C capabilities, then an MJSONWP session will be served instead

Endpoints in the protocol

The Mobile JSON Wire Protocol package gives access to a number of endpoints documented here.

The W3C WebDriver Protocol package gives access to a number of endpoints documented in the official documentation and the simplified spec

Protocol

The basic class, subclassed by drivers that will use the protocol.

routeConfiguringFunction (driver)

This function gives drivers access to the protocol routes. It returns a function that itself will take an Express application.

isSessionCommand (command)

Checks if the command needs to have a session associated with it.

ALL_COMMANDS

An array of all the commands that will be dispatched to by the Mobile JSON Wire Proxy endpoints.

NO_SESSION_ID_COMMANDS

An array of commands that do not need a session associated with them.

Errors

This package exports a number of classes and methods related to Selenium error handling. There are error classes for each Selenium error type (see JSONWP Errors, as well as the context errors in the mobile spec.

The list of errors, and their meanings, can be found here for JSONWP and here for W3C Errors)

There are, in addition, two helper methods for dealing with errors

isErrorType (err, type)

  • checks if the err object is a Mobile JSON Wire Protocol error of a particular type
  • arguments
    • err - the error object to test
    • type - the error class to test against
  • usage
    import { errors, isErrorType } from 'mobile-json-wire-protocol';
    
    try {
      // do some stuff...
    } catch (err) {
      if (isErrorType(err, errors.InvalidCookieDomainError)) {
        // process...
      }
    }
    

errorFromCode (code, message)

  • retrieve the appropriate error for an error code, with the supplied message.
  • arguments
    • code - the integer error code for a Mobile JSON Wire Protocol error
    • message - the message to be encapsulated in the error
  • usage
    import { errors, errorFromCode } from 'mobile-json-wire-protocol';
    
    let error = errorFromCode(6, 'an error has occurred');
    
    console.log(error instanceof errors.NoSuchDriverError);
    // => true
    
    console.log(error.message === 'an error has occurred');
    // => true