Files
appium/lib/protocol
Jonathan Lipps ec72948de2 add -image locator strategy and related logic (#235)
* add -image locator strategy and related logic

* use appium-support jimp helper

* handle find multiple elements by image

* update staleness check variable name

* ensure that a settings object always exists so we can rely on global settings always existing too

* only fix template size if user requests it in settings

* add note about implicit wait error handling

* only automatically update image element position if user turns on an appropriate setting

* add setting to control whether we check for image element staleness

* add setting to determine the image element tap strategy (w3c or mjsonwp)

* prefer single quotes

* add setting to turn off screenshot resizing if not desired

* add docstrings (except for cache class which we may not keep)

* address additional review comments

* add better jsdoc arg info

* use lru-cache npm package instead of rolling our own

* use new versino of appium-support

* make sure the lru cache is checking element size correctly

* give better names and tighten up logic around image el tap strategies

* add some unit tests for image elements

* ensure DeviceSettings has a default no-op update method

* check that driver implements action strategies and fall back / throw as appropriate

* finish out image element unit tests

* have basedriver set noop onSettingsUpdate rather than doing it in DeviceSettings

* move route avoidance detection from protocol to driver

* handle proxying actions to downstream drivers during image tap

* tighten up logic for deciding whether to proxy based on presence of image element

* add find by image specs and fix issues that arose in the process

* clean up regexes

* don't try to be smart and proxy actions for drivers; let them set it up themselves to support image elements

* change default match threshold based on experimentation

* export which settings are handled by basedriver so downstream drivers can utilize this information

* make sure to include a duration for the initial pointerMove action

* add docstring to proxyRouteIsAvoided
2018-07-30 13:17:54 -07: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