How to use the appium-support.util.hasValue function in appium-support

To help you get started, we’ve selected a few appium-support 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-xcuitest-driver / lib / commands / context.js View on Github external
// add if this is a new page
    if (!_.includes(this.contexts, contextId)) {
      newPages.push(id);
      this.contexts.push(contextId);
    }
  }

  if (!keyId) {
    // if there is no key id, pull the first id from the page array and use that
    // as a stand in
    log.debug('No key id found. Choosing first id from page array');
    keyId = newIds[0] || null;
  }

  if (!util.hasValue(this.curContext)) {
    log.debug('We do not appear to have window set yet, ignoring');
    return;
  }

  const [curAppIdKey, curPageIdKey] = this.curContext.split('.');

  if (curAppIdKey !== appIdKey) {
    log.debug('Page change not referring to currently selected app, ignoring.');
    return;
  }

  let newPage = null;
  if (newPages.length) {
    newPage = _.last(newPages);
    log.debug(`We have new pages, selecting page '${newPage}'`);
  } else if (!_.includes(newIds, curPageIdKey)) {
github appium / appium-xcuitest-driver / lib / device-log / safari-network-log.js View on Github external
for (const line of (initiator.stackTrace || [])) {
      const functionName = line.functionName || '(anonymous)';

      const url = (!line.url || line.url === '[native code]')
        ? ''
        : `@${_.last((URL.parse(line.url).pathname || '').split('/'))}:${line.lineNumber}`;
      this.log.debug(`    ${_.padEnd(_.truncate(functionName, {length: 20}), 21)} ${url}`);
    }
    // get `memory-cache` or `disk-cache`, etc., right
    const sizeStr = source.includes('cache') ? ` (from ${source.replace('-', ' ')})` : `${size}B`;
    this.log.debug(`  Size: ${sizeStr}`);
    this.log.debug(`  Time: ${Math.round(time)}ms`);
    if (errorText) {
      this.log.debug(`  Error: ${errorText}`);
    }
    if (util.hasValue(cancelled)) {
      this.log.debug(`  Cancelled: ${cancelled}`);
    }
  }
github appium / appium-ios-driver / lib / commands / context.js View on Github external
}

    logger.debug('New page listing is same as old, doing nothing');
  }

  // make sure that the page listing isn't indicating a redirect
  if (util.hasValue(this.curContext)) {
    let currentPageId = parseInt(_.last(this.curContext.split('.')), 10);
    let page = _.find(pageArray, (p) => parseInt(p.id, 10) === currentPageId);
    if (page && page.url !== this.getCurrentUrl()) {
      logger.debug(`Redirected from '${this.getCurrentUrl()}' to '${page.url}'`);
      this.setCurrentUrl(page.url);
    }
  }

  if (util.hasValue(newPage)) {
    this.selectingNewPage = true;
    await this.remote.selectPage(appIdKey, parseInt(newPage, 10));
    this.selectingNewPage = false;
    this.curContext = `${appIdKey}.${newPage}`;
  }
  this.windowHandleCache = pageArray;
};
github appium / appium-ios-driver / lib / commands / gesture.js View on Github external
helpers.mobileScroll = async function mobileScroll (opts = {}) {
  let direction = opts.direction;
  let el = opts.element;
  el = unwrapEl(el);
  if (this.isWebContext()) {
    // not implemented yet in web
    throw new errors.NotYetImplementedError();
  } else {
    if (util.hasValue(el) && !util.hasValue(direction)) {
      await this.scrollToElement(el);
      return;
    }
    direction = _.capitalize(direction);
    let command;
    if (_.isNull(el) || _.isUndefined(el)) {
      // By default, scroll the first scrollview.
      command = `au.scrollFirstView('${direction}')`;
    } else {
      // if element is defined, call scrollLeft, scrollRight, scrollUp, and scrollDown on the element.
      command = `au.getElement('${el}').scroll${direction}()`;
    }
    try {
      await this.uiAutoClient.sendCommand(command);
    } catch (err) {
      if (!_.includes(err.message, 'kAXErrorFailure')) throw err; // eslint-disable-line curly
github appium / appium-xcuitest-driver / lib / driver.js View on Github external
async startWdaSession (bundleId, processArguments) {
    let args = processArguments ? (processArguments.args || []) : [];
    if (!_.isArray(args)) {
      throw new Error(`processArguments.args capability is expected to be an array. ` +
                      `${JSON.stringify(args)} is given instead`);
    }
    let env = processArguments ? (processArguments.env || {}) : {};
    if (!_.isPlainObject(env)) {
      throw new Error(`processArguments.env capability is expected to be a dictionary. ` +
                      `${JSON.stringify(env)} is given instead`);
    }

    let shouldWaitForQuiescence = util.hasValue(this.opts.waitForQuiescence) ? this.opts.waitForQuiescence : true;
    let maxTypingFrequency = util.hasValue(this.opts.maxTypingFrequency) ? this.opts.maxTypingFrequency : 60;
    let shouldUseSingletonTestManager = util.hasValue(this.opts.shouldUseSingletonTestManager) ? this.opts.shouldUseSingletonTestManager : true;
    let shouldUseTestManagerForVisibilityDetection = false;
    let eventloopIdleDelaySec = this.opts.wdaEventloopIdleDelay || 0;
    if (util.hasValue(this.opts.simpleIsVisibleCheck)) {
      shouldUseTestManagerForVisibilityDetection = this.opts.simpleIsVisibleCheck;
    }
    if (util.compareVersions(this.opts.platformVersion, '==', '9.3')) {
      log.info(`Forcing shouldUseSingletonTestManager capability value to true, because of known XCTest issues under 9.3 platform version`);
      shouldUseTestManagerForVisibilityDetection = true;
    }
    if (util.hasValue(this.opts.language)) {
      args.push('-AppleLanguages', `(${this.opts.language})`);
      args.push('-NSLanguages', `(${this.opts.language})`);
    }

    if (util.hasValue(this.opts.locale)) {
      args.push('-AppleLocale', this.opts.locale);
github appium / appium-xcuitest-driver / lib / driver.js View on Github external
if (util.hasValue(this.opts.locale)) {
      args.push('-AppleLocale', this.opts.locale);
    }

    const wdaCaps = {
      bundleId: this.opts.autoLaunch === false ? undefined : bundleId,
      arguments: args,
      environment: env,
      eventloopIdleDelaySec,
      shouldWaitForQuiescence,
      shouldUseTestManagerForVisibilityDetection,
      maxTypingFrequency,
      shouldUseSingletonTestManager,
    };
    if (util.hasValue(this.opts.shouldUseCompactResponses)) {
      wdaCaps.shouldUseCompactResponses = this.opts.shouldUseCompactResponses;
    }
    if (util.hasValue(this.opts.elementResponseFields)) {
      wdaCaps.elementResponseFields = this.opts.elementResponseFields;
    }
    if (this.opts.autoAcceptAlerts) {
      wdaCaps.defaultAlertAction = 'accept';
    } else if (this.opts.autoDismissAlerts) {
      wdaCaps.defaultAlertAction = 'dismiss';
    }

    await this.proxyCommand('/session', 'POST', {
      capabilities: {
        firstMatch: [wdaCaps],
        alwaysMatch: {},
      }
github appium / appium-android-driver / lib / commands / actions.js View on Github external
commands.doDrag = async function doDrag (dragOpts) {
  if (util.hasValue(dragOpts.elementId)) {
    return await this.bootstrap.sendAction('element:drag', dragOpts);
  } else {
    return await this.bootstrap.sendAction('drag', dragOpts);
  }
};
github appium / appium-android-driver / lib / commands / recordscreen.js View on Github external
async function scheduleScreenRecord (adb, recordingProperties) {
  if (recordingProperties.stopped) {
    return;
  }

  const {
    timer,
    videoSize,
    bitRate,
    timeLimit,
    bugReport,
  } = recordingProperties;

  let currentTimeLimit = MAX_RECORDING_TIME_SEC;
  if (util.hasValue(recordingProperties.currentTimeLimit)) {
    const currentTimeLimitInt = parseInt(recordingProperties.currentTimeLimit, 10);
    if (!isNaN(currentTimeLimitInt) && currentTimeLimitInt < MAX_RECORDING_TIME_SEC) {
      currentTimeLimit = currentTimeLimitInt;
    }
  }
  const pathOnDevice = `/sdcard/${Math.floor(new Date())}${DEFAULT_EXT}`;
  const recordingProc = adb.screenrecord(pathOnDevice, {
    videoSize,
    bitRate,
    timeLimit: currentTimeLimit,
    bugReport,
  });

  recordingProc.on('end', () => {
    if (recordingProperties.stopped || !util.hasValue(timeLimit)) {
      return;
github appium / appium-adb / lib / tools / adb-commands.js View on Github external
methods.screenrecord = function screenrecord (destination, options = {}) {
  const cmd = ['screenrecord'];
  const {
    videoSize,
    bitRate,
    timeLimit,
    bugReport,
  } = options;
  if (util.hasValue(videoSize)) {
    cmd.push('--size', videoSize);
  }
  if (util.hasValue(timeLimit)) {
    cmd.push('--time-limit', timeLimit);
  }
  if (util.hasValue(bitRate)) {
    cmd.push('--bit-rate', bitRate);
  }
  if (bugReport) {
    cmd.push('--bugreport');
  }
  cmd.push(destination);

  const fullCmd = [
    ...this.executable.defaultArgs,
    'shell',
    ...cmd
  ];
  log.debug(`Building screenrecord process with the command line: adb ${quote(fullCmd)}`);
github appium / appium-android-driver / lib / commands / app-management.js View on Github external
commands.terminateApp = async function terminateApp (appId, options = {}) {
  log.info(`Terminating '${appId}'`);
  if (!(await this.adb.processExists(appId))) {
    log.info(`The app '${appId}' is not running`);
    return false;
  }
  await this.adb.forceStop(appId);
  const timeout = util.hasValue(options.timeout) && !isNaN(options.timeout) ? parseInt(options.timeout, 10) : 500;
  try {
    await waitForCondition(async () => await this.queryAppState(appId) <= APP_STATE_NOT_RUNNING,
                           {waitMs: timeout, intervalMs: 100});
  } catch (e) {
    log.errorAndThrow(`'${appId}' is still running after ${timeout}ms timeout`);
  }
  log.info(`'${appId}' has been successfully terminated`);
  return true;
};