How to use the appium-support.fs.rimraf 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 / certificate.js View on Github external
prefix: 'cert',
    suffix: '.cer'
  });
  try {
    await fs.writeFile(tempCert.path, certBuffer);
    const {stdout} = await exec('openssl', ['x509', '-noout', '-subject', '-in', tempCert.path]);
    const cnMatch = /\/CN=([^\/]+)/.exec(stdout); // eslint-disable-line no-useless-escape
    if (cnMatch) {
      return cnMatch[1].trim();
    }
    throw new Error(`There is no common name value in '${stdout}' output`);
  } catch (err) {
    throw new Error(`Cannot parse common name value from the certificate. Is it valid and base64-encoded? ` +
                    `Original error: ${err.message}`);
  } finally {
    await fs.rimraf(tempCert.path);
  }
}
github appium-boneyard / appium-instruments / lib / utils.js View on Github external
async function quickLaunch (udid, appPath = path.resolve(__dirname, '..', '..', 'assets', 'TestApp.app')) {
  let traceTemplatePath = await xcode.getAutomationTraceTemplatePath();
  let scriptPath = path.resolve(__dirname, '..', '..', 'assets', 'blank_instruments_test.js');
  let traceDocument = path.resolve('/', 'tmp', 'testTrace.trace');
  let resultsPath = path.resolve('/', 'tmp');

  // the trace document can be in a weird state
  // but we never do anything with it, so delete
  await fs.rimraf(traceDocument);

  let args = ['instruments',
              '-D', traceDocument,
               '-t', traceTemplatePath,
               '-w', udid,
               appPath,
               '-e', 'UIASCRIPT', scriptPath,
               '-e', 'UIARESULTSPATH', resultsPath];
  log.debug(`Running command: 'xcrun ${args.join(' ')}'`);
  await exec('xcrun', args);
}
github appium / appium-ios-driver / lib / instruments / utils.js View on Github external
async function quickLaunch (udid, appPath = path.resolve(__dirname, '..', '..', 'assets', 'TestApp.app')) {
  let traceTemplatePath = await xcode.getAutomationTraceTemplatePath();
  let scriptPath = path.resolve(__dirname, '..', '..', 'assets', 'blank_instruments_test.js');
  let traceDocument = path.resolve('/', 'tmp', 'testTrace.trace');
  let resultsPath = path.resolve('/', 'tmp');

  // the trace document can be in a weird state
  // but we never do anything with it, so delete
  await fs.rimraf(traceDocument);

  let args = [
    'instruments',
    '-D', traceDocument,
    '-t', traceTemplatePath,
    '-w', udid,
    appPath,
    '-e', 'UIASCRIPT', scriptPath,
    '-e', 'UIARESULTSPATH', resultsPath];
  log.debug(`Running command: 'xcrun ${args.join(' ')}'`);
  await exec('xcrun', args);
}
github appium / appium-xcuitest-driver / lib / commands / file-movement.js View on Github external
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-android-driver / test / functional / commands / file-movement-e2e-specs.js View on Github external
const remoteDir = getRandomDir();
    await driver.pushFile(`${remoteDir}/remote0.txt`, base64Data);
    await driver.pushFile(`${remoteDir}/remote1.txt`, base64Data);
    const data = await driver.pullFolder(remoteDir);

    const tmpRoot = await tempDir.openDir();
    try {
      const zipPath = path.resolve(tmpRoot, 'data.zip');
      await fs.writeFile(zipPath, Buffer.from(data, 'base64'));
      const extractedDataPath = path.resolve(tmpRoot, 'extracted_data');
      await fs.mkdir(extractedDataPath);
      await zip.extractAllTo(zipPath, extractedDataPath);
      const itemsCount = (await fs.readdir(extractedDataPath)).length;
      itemsCount.should.eql(2);
    } finally {
      await fs.rimraf(tmpRoot);
    }
  });
});
github appium / appium-xcuitest-driver / lib / commands / performance.js View on Github external
const zipPath = `${localPath}.zip`;
  const zipArgs = [
    '-9', '-r', zipPath,
    path.basename(localPath),
  ];
  log.info(`Found perf trace record '${localPath}'. Compressing it with 'zip ${zipArgs.join(' ')}'`);
  try {
    await exec('zip', zipArgs, {
      cwd: path.dirname(localPath),
    });
    return await uploadTrace(zipPath, remotePath, {user, pass, method});
  } finally {
    delete runningRecorders[this.opts.device.udid];
    if (await fs.exists(localPath)) {
      await fs.rimraf(localPath);
    }
  }
};
github appium / appium-ios-simulator / test / unit / certificate-specs.js View on Github external
afterEach(async function () {
    await fs.rimraf(tempDirectory);
  });
github appium / appium-xcuitest-driver / lib / commands / actions.js View on Github external
log.info(`Parsed bundle identifier '${bundleId}' from '${remotePath}'. ` +
             `Will put the data into '${dstPath}'`);
    if (!await fs.exists(path.dirname(dstPath))) {
      log.debug(`The destination folder '${path.dirname(dstPath)}' does not exist. Creating...`);
      await fs.mkdirp(path.dirname(dstPath));
    }
    await fs.writeFile(dstPath, new Buffer(base64Data, 'base64').toString('binary'), 'binary');
    return;
  }
  const dstFolder = await tempDir.tempDir();
  const dstPath = path.resolve(dstFolder, path.basename(remotePath));
  try {
    await fs.writeFile(dstPath, new Buffer(base64Data, 'base64').toString('binary'), 'binary');
    await addMedia(device.udid, dstPath);
  } finally {
    await fs.rimraf(dstFolder);
  }
}
github appium / appium-chromedriver / lib / storage-client.js View on Github external
async unzipDriver (src, dst) {
    const tmpRoot = await tempDir.openDir();
    try {
      await zip.extractAllTo(src, tmpRoot);
      const chromedriverPath = await fs.walkDir(tmpRoot, true, (itemPath, isDirectory) =>
        !isDirectory && _.toLower(path.parse(itemPath).name) === 'chromedriver');
      if (!chromedriverPath) {
        throw new Error('The archive was unzipped properly, but we could not find any chromedriver executable');
      }
      log.debug(`Moving the extracted '${path.basename(chromedriverPath)}' to '${dst}'`);
      await fs.mv(chromedriverPath, dst, {
        mkdirp: true
      });
    } finally {
      await fs.rimraf(tmpRoot);
    }
  }
github appium / appium-chromedriver / lib / storage-client.js View on Github external
const archivesRoot = await tempDir.openDir();
    try {
      for (const [idx, driverKey] of driversToSync.entries()) {
        promises.push((async () => {
          if (await this.retrieveDriver(idx, driverKey, archivesRoot, !_.isEmpty(opts))) {
            synchronizedDrivers.push(driverKey);
          }
        })());

        if (promises.length % MAX_PARALLEL_DOWNLOADS === 0) {
          await B.all(promises);
        }
      }
      await B.all(promises);
    } finally {
      await fs.rimraf(archivesRoot);
    }
    if (!_.isEmpty(synchronizedDrivers)) {
      log.info(`Successfully synchronized ${synchronizedDrivers.length} ` +
        `chromedriver${synchronizedDrivers.length === 1 ? '' : 's'}`);
    } else {
      log.info(`No chromedrivers were synchronized`);
    }
    return synchronizedDrivers;
  }
}