Set the context to be automated. Used when testing hybrid mobile apps using Appium.

More info here: https://appium.io/docs/en/commands/context/set-context/

Usage

                    .appium.setContext(context, [callback])
                

Example

module.exports = {
  'switch to webview context': async function (app) {
    app
      .waitUntil(async function() {
        // wait for webview context to be available
        // initially, this.getContexts() only returns ['NATIVE_APP']
        const contexts = await this.appium.getContexts();

        return contexts.length > 1;
      })
      .perform(async function() {
        // switch to webview context
        const contexts = await this.appium.getContexts();  // contexts: ['NATIVE_APP', 'WEBVIEW_<id>']
        await this.appium.setContext(contexts[1]);
      });
  },

  'switch to native context': function (app) {
    app.appium.setContext('NATIVE_APP');
  }
};

Parameters

Name Type description
context string

context name to switch to - a string representing an available context.

callback
Optional
function

Optional callback function to be called when the command finishes.

See also