How to use the appium-support.fs.exists 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 / webdriveragent.js View on Github external
async launch (sessionId) {
    if (this.webDriverAgentUrl) {
      log.info(`Using provided WebdriverAgent at '${this.webDriverAgentUrl}'`);
      this.url = this.webDriverAgentUrl;
      this.setupProxies(sessionId);
      return this.webDriverAgentUrl;
    }

    log.info('Launching WebDriverAgent on the device');

    this.setupProxies(sessionId);

    if (!await fs.exists(this.agentPath)) {
      throw new Error(`Trying to use WebDriverAgent project at '${this.agentPath}' but the ` +
                      'file does not exist');
    }

    // make sure that the WDA dependencies have been built
    await checkForDependencies(this.bootstrapPath, this.useCarthageSsl);

    // if necessary, update the bundleId to user's specification
    if (this.realDevice && this.updatedWDABundleId) {
      await updateProjectFile(this.agentPath, this.updatedWDABundleId);
    }

    //kill all hanging processes
    await this.killHangingProcesses();

    if (this.xcodeVersion.major === 7 || (this.xcodeVersion.major === 8 && this.xcodeVersion.minor === 0)) {
github appium / appium-ios-simulator / lib / certificate.js View on Github external
async getDB () {
    if (this.db) {
      return this.db;
    }

    // If the sim doesn't have a keychains directory, create one
    let keychainsPath = path.resolve(this.sharedResourceDir, 'Library', 'Keychains');
    if (!(await fs.exists(keychainsPath))) {
      await mkdirp(keychainsPath);
    }

    // Open sqlite database
    this.db = path.resolve(keychainsPath, 'TrustStore.sqlite3');

    // If it doesn't have a tsettings table, create one
    await execSQLiteQuery(this.db, `CREATE TABLE IF NOT EXISTS tsettings (sha1 BLOB NOT NULL DEFAULT '', subj BLOB NOT NULL DEFAULT '', tset BLOB, data BLOB, PRIMARY KEY(sha1));`);
    try {
      await execSQLiteQuery(this.db, 'CREATE INDEX isubj ON tsettings(subj);');
    } catch (e) { }


    return this.db;
  }
github appium / appium-xcuitest-driver / lib / commands / file-movement.js View on Github external
async function deleteFromSimulator (device, remotePath) {
  let pathOnServer;
  if (CONTAINER_PATH_PATTERN.test(remotePath)) {
    const {bundleId, pathInContainer: dstPath} = await parseContainerPath(remotePath,
      async (appBundle, containerType) => await getAppContainer(device.udid, appBundle, null, containerType));
    log.info(`Parsed bundle identifier '${bundleId}' from '${remotePath}'. ` +
      `'${dstPath}' will be deleted`);
    pathOnServer = dstPath;
  } else {
    const simRoot = device.getDir();
    pathOnServer = path.posix.join(simRoot, remotePath);
    verifyIsSubPath(pathOnServer, simRoot);
    log.info(`Got the full path: ${pathOnServer}`);
  }
  if (!await fs.exists(pathOnServer)) {
    log.errorAndThrow(`The remote path at '${pathOnServer}' does not exist`);
  }
  await fs.rimraf(pathOnServer);
}
github appium / appium-adb / lib / helpers.js View on Github external
const getSdkToolsVersion = _.memoize(async function getSdkToolsVersion () {
  const androidHome = process.env.ANDROID_HOME;
  if (!androidHome) {
    throw new Error('ANDROID_HOME environment variable is expected to be set');
  }
  const propertiesPath = path.resolve(androidHome, 'tools', 'source.properties');
  if (!await fs.exists(propertiesPath)) {
    log.warn(`Cannot find ${propertiesPath} file to read SDK version from`);
    return;
  }
  const propertiesContent = await fs.readFile(propertiesPath, 'utf8');
  const versionMatcher = new RegExp(/Pkg\.Revision=(\d+)\.?(\d+)?\.?(\d+)?/);
  const match = versionMatcher.exec(propertiesContent);
  if (match) {
    return {
      major: parseInt(match[1], 10),
      minor: match[2] ? parseInt(match[2], 10) : 0,
      build: match[3] ? parseInt(match[3], 10) : 0
    };
  }
  log.warn(`Cannot parse "Pkg.Revision" value from ${propertiesPath}`);
});
github appium / appium-android-driver / lib / driver.js View on Github external
return false;
    }
    let remotePath = `/data/data/${this.opts.appPackage}/shared_prefs`;
    let remoteFile = `${remotePath}/${name}.xml`;
    let localPath = `/tmp/${name}.xml`;
    let builder = this.getPrefsBuilder();
    builder.build(sharedPrefs.prefs);
    log.info(`Creating temporary shared preferences: ${localPath}`);
    builder.toFile(localPath);
    log.info(`Creating shared_prefs remote folder: ${remotePath}`);
    await this.adb.shell(['mkdir', '-p', remotePath]);
    log.info(`Pushing shared_prefs to ${remoteFile}`);
    await this.adb.push(localPath, remoteFile);
    try {
      log.info(`Trying to remove shared preferences temporary file`);
      if (await fs.exists(localPath)) {
        await fs.unlink(localPath);
      }
    } catch (e) {
      log.warn(`Error trying to remove temporary file ${localPath}`);
    }
    return true;
  }
github appium-boneyard / appium-instruments / lib / utils.js View on Github external
async function getIwdPath (xcodeMajorVersion) {
  let thirdpartyPath = path.resolve(rootDir, 'thirdparty');
  let iwdPath = path.resolve(thirdpartyPath, `iwd${xcodeMajorVersion}`);
  if (!await fs.exists(iwdPath)) {
    iwdPath = path.resolve(thirdpartyPath, 'iwd');
  }
  log.debug(`Found Insruments-Without-Delay: ${iwdPath}`);
  return iwdPath;
}
github appium / appium-ios-driver / lib / commands / file-movement.js View on Github external
commands.pushFile = async function pushFile (remotePath, base64Data) {
  logger.debug(`Pushing ${remotePath} to iOS simulator`);

  if (this.isRealDevice()) {
    logger.debug('Unsupported: cannot write files to physical device');
    throw new errors.NotYetImplementedError();
  }

  let fullPath = await this.getSimFileFullPath(remotePath);

  logger.debug(`Attempting to write ${fullPath}...`);
  if (await fs.exists(fullPath)) {
    logger.debug(`${fullPath} already exists, deleting...`);
    await fs.unlink(fullPath);
  }
  await mkdirp(path.dirname(fullPath));
  let content = Buffer.from(base64Data, 'base64');
  await fs.writeFile(fullPath, content);
  logger.debug(`Wrote ${content.length} bytes to ${fullPath}`);
};
github appium / appium-uiautomator2-driver / lib / installer.js View on Github external
async function serverExists () {
  try {
    return (await fs.exists(UI2_SERVER_APK_PATH) &&
    await fs.exists(UI2_TEST_APK_PATH));
  } catch (e) {
    if (e.code.indexOf("ENOENT") !== -1) {
      return false;
    }
    throw e;
  }
}
github appium / appium-ios-simulator / lib / simulator-xcode-6.js View on Github external
async clearKeychains () {
    const plistPath = path.resolve(await this.getLaunchDaemonsRoot(), 'com.apple.securityd.plist');
    if (!await fs.exists(plistPath)) {
      throw new Error(`Cannot clear keychains because '${plistPath}' does not exist`);
    }
    await simctl.spawn(this.udid, ['launchctl', 'unload', plistPath]);
    try {
      if (await fs.exists(this.keychainPath)) {
        await fs.rimraf(this.keychainPath);
        await mkdirp(this.keychainPath);
      }
    } finally {
      await simctl.spawn(this.udid, ['launchctl', 'load', plistPath]);
    }
  }