How to use the appium-base-driver.errors.NoSuchContextError function in appium-base-driver

To help you get started, we’ve selected a few appium-base-driver examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github appium / appium-android-driver / test / unit / driver-specs.js View on Github external
it('should respect timeout if autoWebview is requested', async function () {
      this.timeout(10000);
      driver.setContext.throws(new errors.NoSuchContextError());

      let begin = Date.now();

      driver.opts.autoWebview = true;
      driver.opts.autoWebviewTimeout = 5000;
      await driver.startAndroidSession().should.eventually.be.rejected;
      driver.defaultWebviewName.calledOnce.should.be.true;

      // we have a timeout of 5000ms, retrying on 500ms, so expect 10 times
      driver.setContext.callCount.should.equal(10);

      let end = Date.now();
      (end - begin).should.be.above(4500);
    });
    it('should not set the context if autoWebview is not requested', async function () {
github appium / appium-xcuitest-driver / lib / commands / context.js View on Github external
// switching into a webview context

  // if contexts have not already been retrieved, get them
  if (_.isUndefined(this.contexts)) {
    await this.getContexts();
  }

  let contextId = _.replace(name, WEBVIEW_BASE, '');
  if (contextId === '') {
    // allow user to pass in "WEBVIEW" without an index
    // the second context will be the first webview as
    // the first is always NATIVE_APP
    contextId = this.contexts[1];
  }
  if (!_.includes(this.contexts, contextId)) {
    throw new errors.NoSuchContextError();
  }

  const oldContext = this.curContext;
  this.curContext = this.curWindowHandle = contextId;

  // `contextId` will be in the form of `appId.pageId` in this case
  const [appIdKey, pageIdKey] = _.map(contextId.split('.'), (id) => parseInt(id, 10));
  try {
    this.selectingNewPage = true;
    await this.remote.selectPage(appIdKey, pageIdKey, skipReadyCheck);
  } catch (err) {
    this.curContext = this.curWindowHandle = oldContext;
    throw err;
  } finally {
    this.selectingNewPage = false;
  }
github appium / appium-ios-driver / lib / commands / context.js View on Github external
// switching into a webview context

    // if contexts have not already been retrieved, get them
    if (_.isUndefined(this.contexts)) {
      await this.getContexts();
    }

    let contextId = name.replace(WEBVIEW_BASE, '');
    if (contextId === '') {
      // allow user to pass in "WEBVIEW" without an index
      // the second context will be the first webview as
      // the first is always NATIVE_APP
      contextId = this.contexts[1];
    }
    if (!_.includes(this.contexts, contextId)) {
      throw new errors.NoSuchContextError();
    }

    if (this.isRealDevice()) {
      if (this.remote) {
        await this.remote.disconnect();
      }
      this.curContext = contextId;
      await this.remote.connect(contextId);
    } else {
      // `contextId` will be in the form of `appId.pageId` in this case
      let [appIdKey, pageIdKey] = _.map(contextId.split('.'), (id) => parseInt(id, 10));
      await this.remote.selectPage(appIdKey, pageIdKey, skipReadyCheck);
      this.curContext = contextId;
    }
  }
github appium / appium-android-driver / lib / commands / context.js View on Github external
commands.setContext = async function setContext (name) {
  if (!util.hasValue(name)) {
    name = this.defaultContextName();
  } else if (name === WEBVIEW_WIN) {
    // handle setContext "WEBVIEW"
    name = this.defaultWebviewName();
  }
  // if we're already in the context we want, do nothing
  if (name === this.curContext) {
    return;
  }

  let contexts = await this.getContexts();
  // if the context we want doesn't exist, fail
  if (!_.includes(contexts, name)) {
    throw new errors.NoSuchContextError();
  }

  await this.switchContext(name);
  this.curContext = name;
};