How to use the appium-support.util.compareVersions 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 / driver.js View on Github external
await this.setInitialOrientation(this.opts.orientation);
    this.logEvent('orientationSet');

    // real devices will be handled later, after the web context has been initialized
    if (this.isSafari() && !this.isRealDevice() && util.compareVersions(this.opts.platformVersion, '>=', '12.2')) {
      // on 12.2 the page is not opened in WDA
      await openUrl(this.opts.device.udid, this._currentUrl);
    }

    if (this.isSafari() || this.opts.autoWebview) {
      log.debug('Waiting for initial webview');
      await this.navToInitialWebview();
      this.logEvent('initialWebviewNavigated');
    }

    if (this.isSafari() && this.isRealDevice() && util.compareVersions(this.opts.platformVersion, '>=', '12.2')) {
      // on 12.2 the page is not opened in WDA
      await this.setUrl(this._currentUrl);
    }

    if (!this.isRealDevice()) {
      if (this.opts.calendarAccessAuthorized) {
        await this.opts.device.enableCalendarAccess(this.opts.bundleId);
      } else if (this.opts.calendarAccessAuthorized === false) {
        await this.opts.device.disableCalendarAccess(this.opts.bundleId);
      }
    }
  }
github appium / appium-xcuitest-driver / test / functional / desired.js View on Github external
let feature = parseInt(process.env[envArg], 10);
  if (isNaN(feature)) {
    feature = process.env[envArg];
  }
  return !!feature;
}

const PLATFORM_VERSION = process.env.PLATFORM_VERSION ? process.env.PLATFORM_VERSION : '11.3';
const LAUNCH_WITH_IDB = process.env.LAUNCH_WITH_IDB;

// If it's real device cloud, don't set a device name. Use dynamic device allocation.
const DEVICE_NAME = process.env.DEVICE_NAME
  ? process.env.DEVICE_NAME
  : process.env.SAUCE_RDC
    ? undefined
    : util.compareVersions(PLATFORM_VERSION, '>=', '13.0') ? 'iPhone 8' : 'iPhone 6';

const SHOW_XCODE_LOG = checkFeatureInEnv('SHOW_XCODE_LOG');
const REAL_DEVICE = checkFeatureInEnv('REAL_DEVICE');
let XCCONFIG_FILE = process.env.XCCONFIG_FILE;
if (REAL_DEVICE && !XCCONFIG_FILE) {
  // no xcconfig file specified, so try to find in the root directory of the package
  // this happens once, at the start of a test run, so using sync method is ok
  let cwd = path.resolve(__dirname, '..', '..', '..');
  let files = glob.sync('*.xcconfig', { cwd });
  if (files.length) {
    XCCONFIG_FILE = path.resolve(cwd, _.first(files));
  }
}

// Had to make these two optional dependencies so the tests
// can still run in linux
github appium / appium-xcuitest-driver / lib / driver.js View on Github external
this.xcodeVersion = await getAndCheckXcodeVersion();
    }
    this.logEvent('xcodeDetailsRetrieved');

    if (_.toLower(this.opts.browserName) === 'safari') {
      log.info('Safari test requested');
      this.safari = true;
      this.opts.app = undefined;
      this.opts.processArguments = this.opts.processArguments || {};
      this.opts.bundleId = SAFARI_BUNDLE_ID;
      this._currentUrl = this.opts.safariInitialUrl || (
        this.isRealDevice()
          ? 'http://appium.io'
          : `http://${this.opts.address}:${this.opts.port}/welcome`
      );
      if (util.compareVersions(this.opts.platformVersion, '<', '12.2')) {
        // this option does not work on 12.2 and above
        this.opts.processArguments.args = ['-u', this._currentUrl];
      }
    } else if (this.opts.app || this.opts.bundleId) {
      await this.configureApp();
    }
    this.logEvent('appConfigured');

    // fail very early if the app doesn't actually exist
    // or if bundle id doesn't point to an installed app
    if (this.opts.app) {
      await checkAppPresent(this.opts.app);

      if (!this.opts.bundleId) {
        this.opts.bundleId = await appUtils.extractBundleId(this.opts.app);
      }
github appium / appium-xcuitest-driver / lib / commands / certificate.js View on Github external
try {
          await this.proxyCommand('/url', 'POST', {url: certUrl});
        } catch (err) {
          if (this.isWebContext()) {
            // The command above does not always work on real devices
            await iosCommands.general.setUrl.call(this, certUrl);
          } else {
            throw err;
          }
        }
      } else {
        await openUrl(this.opts.udid || this.sim.udid, certUrl);
      }

      let isCertAlreadyInstalled = false;
      if (util.compareVersions(this.opts.platformVersion, '>=', '12.2')) {
        if (await installPost122Certificate(this, cn)) {
          await clickElement(this, Settings.Profile);
          await trustCertificateInPreferences(this, cn);
        } else {
          isCertAlreadyInstalled = true;
        }
      } else {
        if (await installPre122Certificate(this)) {
          await clickElement(this, Button.Return_to_Settings);
          await trustCertificateInPreferences(this, cn);
        } else {
          isCertAlreadyInstalled = true;
        }
      }
      if (isCertAlreadyInstalled) {
        log.info(`It looks like the '${cn}' certificate has been already added to the CA root`);
github appium / appium-xcuitest-driver / lib / driver.js View on Github external
this.opts.device = device;
    this.opts.udid = udid;
    this.opts.realDevice = realDevice;

    // at this point if there is no platformVersion, get it from the device
    if (!this.opts.platformVersion && this.opts.device) {
      this.opts.platformVersion = await this.opts.device.getPlatformVersion();
      log.info(`No platformVersion specified. Using device version: '${this.opts.platformVersion}'`);
    }

    const normalizedVersion = normalizePlatformVersion(this.opts.platformVersion);
    if (this.opts.platformVersion !== normalizedVersion) {
      log.info(`Normalized platformVersion capability value '${this.opts.platformVersion}' to '${normalizedVersion}'`);
      this.opts.platformVersion = normalizedVersion;
    }
    if (util.compareVersions(this.opts.platformVersion, '<', '9.3')) {
      throw new Error(`Platform version must be 9.3 or above. '${this.opts.platformVersion}' is not supported.`);
    }

    if (_.isEmpty(this.xcodeVersion) && (!this.opts.webDriverAgentUrl || !this.opts.realDevice)) {
      // no `webDriverAgentUrl`, or on a simulator, so we need an Xcode version
      this.xcodeVersion = await getAndCheckXcodeVersion();
    }
    this.logEvent('xcodeDetailsRetrieved');

    if (_.toLower(this.opts.browserName) === 'safari') {
      log.info('Safari test requested');
      this.safari = true;
      this.opts.app = undefined;
      this.opts.processArguments = this.opts.processArguments || {};
      this.opts.bundleId = SAFARI_BUNDLE_ID;
      this._currentUrl = this.opts.safariInitialUrl || (
github appium / appium-remote-debugger / lib / rpc-client.js View on Github external
function isTargetBased (isSafari, platformVersion) {
  // on iOS 12.2 the messages get sent through the Target domain
  const isHighVersion = util.compareVersions(platformVersion, '>=', MIN_PLATFORM_FOR_TARGET_BASED);
  log.debug(`Checking which communication style to use (${isSafari ? '' : 'non-'}Safari on platform version '${platformVersion}')`);
  log.debug(`Platform version equal or higher than '${MIN_PLATFORM_FOR_TARGET_BASED}': ${isHighVersion}`);
  return isSafari && isHighVersion;
}
github appium / appium-xcuitest-driver / lib / driver.js View on Github external
}
    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);
    }

    const wdaCaps = {
      bundleId: this.opts.autoLaunch === false ? undefined : bundleId,
      arguments: args,
      environment: env,