コード例 #1
0
ファイル: execute.js プロジェクト: bigfei/appium-ios-driver
commands.receiveAsyncResponse = async function (status, value) {
  logger.debug(`Received async response: ${JSON.stringify(value)}`);
  if (!_.isNull(this.asyncPromise) && !_.isUndefined(this.asyncPromise)) {
    if (status !== 0) {
      this.asyncPromise.reject(errorFromCode(status, value.message));
    } else {
      this.asyncPromise.resolve(value);
    }
  } else {
    logger.warn(`Received async response when we were not expecting one! ` +
                `Response was: ${JSON.stringify(value)}`);
  }
};
コード例 #2
0
helpers.proxyCommand = async function (endpoint, method, body) {
  if (!endpoint) {
    throw new errors.BadParametersError('Proxying requires an endpoint');
  } else if (method !== 'POST' && method !== 'GET') {
    throw new errors.BadParametersError('Proxying only works for GET or POST requests');
  }

  let res = await this.wda.jwproxy.command(endpoint, method, body);

  // temporarily handle errors that can be returned
  if (res && res.status && parseInt(res.status, 10) !== 0) {
    throw errorFromCode(res.status, res.value);
  }

  return res;
};
コード例 #3
0
helpers.proxyCommand = async function (endpoint, method, body, isSessionCommand = true) {
  if (this.shutdownUnexpectedly) {
    return;
  }

  if (!endpoint) {
    log.errorAndThrow('Proxying requires an endpoint');
  } else if (SUPPORTED_METHODS.indexOf(method) === -1) {
    log.errorAndThrow(`Proxying only works for the following requests: ${SUPPORTED_METHODS.join(', ')}`);
  }

  if (!this.wda) {
    throw new Error("Can't call proxyCommand without WDA driver active");
  }
  const proxy = isSessionCommand ? this.wda.jwproxy : this.wda.noSessionProxy;
  if (!proxy) {
    throw new Error("Can't call proxyCommand without WDA proxy active");
  }

  const cmdName = routeToCommandName(endpoint, method);
  const timeout = this._getCommandTimeout(cmdName);
  let res = null;
  if (timeout) {
    log.debug(`Setting custom timeout to ${timeout} ms for "${cmdName}" command`);
    let isCommandExpired = false;
    res = await B.Promise.resolve(proxy.command(endpoint, method, body))
                  .timeout(timeout)
                  .catch(B.Promise.TimeoutError, () => {
                    isCommandExpired = true;
                  });
    if (isCommandExpired) {
      proxy.cancelActiveRequests();
      const errMsg = `Appium did not get any response from "${cmdName}" command in ${timeout} ms`;
      await this.startUnexpectedShutdown(new errors.TimeoutError(errMsg));
      log.errorAndThrow(errMsg);
    }
  } else {
    res = await proxy.command(endpoint, method, body);
  }

  // temporarily handle errors that can be returned
  if (res && res.status && parseInt(res.status, 10) !== 0) {
    throw errorFromCode(res.status, res.value);
  }

  return res;
};