How to use the appium-support.fs.readFile 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-ios-driver / test / e2e / driver / uiauto / dynamic-bootstrap-specs.js View on Github external
it('should generate dynamic bootstrap', async () => {
    process.env.APPIUM_BOOTSTRAP_DIR = path.resolve('/', 'tmp', 'appium-uiauto', 'test', 'unit', 'bootstrap');
    if (await fs.exists(process.env.APPIUM_BOOTSTRAP_DIR)) {
      await fs.rimraf(process.env.APPIUM_BOOTSTRAP_DIR);
    }

      // first call: should create new bootstrap file
    let bootstrapFile = await uiauto.prepareBootstrap();
    bootstrapFile.should.match(/\/tmp\/appium-uiauto\/test\/unit\/bootstrap\/bootstrap\-.*\.js/);
    let code = await fs.readFile(bootstrapFile, 'utf8');
    await checkCode(code);
    log.debug.calledWithMatch(/Creating or overwriting dynamic bootstrap/).should.be.true;
    log.debug.resetHistory();

    // second call: should reuse bootstrap file
    bootstrapFile = await uiauto.prepareBootstrap();
    bootstrapFile.should.match(/\/tmp\/appium-uiauto\/test\/unit\/bootstrap\/bootstrap\-.*\.js/);
    code = await fs.readFile(bootstrapFile, 'utf8');
    await checkCode(code);
    log.debug.calledWithMatch(/Reusing dynamic bootstrap/).should.be.true;
    log.debug.resetHistory();

    // third call using custom socket path: should create different bootstrap file
    bootstrapFile = await uiauto.prepareBootstrap({sock: '/tmp/abcd/sock'});
    bootstrapFile.should.match(/\/tmp\/appium-uiauto\/test\/unit\/bootstrap\/bootstrap\-.*\.js/);
    code = await fs.readFile(bootstrapFile, 'utf8');
github appium / appium-ios-driver / test / unit / file-movement-specs.js View on Github external
it('should pull a folder from filesystem as a base64 zip, extract the zip and have same contents as in filesystem', async function () {
      // Create a temporary directory with one file in it
      const tempPath = await tempDir.openDir();
      await fs.writeFile(path.resolve(tempPath, 'a.txt'), 'Hello World!');

      const getSimPathStub = sinon.stub(driver, 'getSimFileFullPath').returns(tempPath);

      // Zip the directory to base64 and write it to 'zip.zip'
      const zippedData = await driver.pullFolder('/does/not/matter');
      const zippedFilepath = path.resolve(tempPath, 'zip.zip');
      await fs.writeFile(zippedFilepath, zippedData, {encoding: 'base64'});

      // Unzip it and check it matches original file contents
      const unzippedDir = path.resolve(tempPath, 'unzipped');
      await zip.extractAllTo(zippedFilepath, unzippedDir);
      await fs.readFile(path.resolve(unzippedDir, 'a.txt'), {encoding: 'utf8'}).should.eventually.equal('Hello World!');

      getSimPathStub.restore();
    });
  });
github appium / appium-chromedriver / lib / install.js View on Github external
log(`Extracting ${tempFile.path} to ${tempUnzipped}`);
  await mkdirp(tempUnzipped);
  await zip.extractAllTo(tempFile.path, tempUnzipped);
  let extractedBin = path.resolve(tempUnzipped, 'chromedriver');
  if (platform === 'win') {
    extractedBin += '.exe';
  }

  // make build dirs that will hold the chromedriver binary
  log(`Creating ${path.resolve(CD_BASE_DIR, platform)}...`);
  await mkdirp(path.resolve(CD_BASE_DIR, platform));

  // copy the extracted binary to the correct build dir
  const newBin = await getChromedriverBinaryPath(platform, arch);
  log(`Copying unzipped binary, reading from ${extractedBin}...`);
  const binContents = await fs.readFile(extractedBin, {encoding: 'binary'});
  log(`Writing to ${newBin}...`);
  await fs.writeFile(newBin, binContents, {encoding: 'binary', mode: 0o755});
  log(`${newBin} successfully put in place`);
}
github appium / appium-ios-simulator / test / unit / certificate-specs.js View on Github external
it('can get a subject from a PEM certificate', async function () {
    let subject = await certificate.getSubject(`${assetsDir}/test-pem.pem`);
    let testSubject = await fs.readFile(`${assetsDir}/Library/certificates/test-subj.txt`, 'utf-8');
    expect(subject).to.equal(testSubject);
  });
github appium / appium-xcuitest-driver / lib / utils.js View on Github external
async function encodeBase64OrUpload (localFile, remotePath = null, uploadOptions = {}) {
  if (!await fs.exists(localFile)) {
    log.errorAndThrow(`The file at '${localFile}' does not exist or is not accessible`);
  }

  const {size} = await fs.stat(localFile);
  log.debug(`The size of the file is ${util.toReadableSizeString(size)}`);
  if (_.isEmpty(remotePath)) {
    const maxMemoryLimit = v8.getHeapStatistics().total_available_size / 2;
    if (size >= maxMemoryLimit) {
      log.info(`The file might be too large to fit into the process memory ` +
        `(${util.toReadableSizeString(size)} >= ${util.toReadableSizeString(maxMemoryLimit)}). ` +
        `Provide a link to a remote writable location for video upload ` +
        `(http(s) and ftp protocols are supported) if you experience Out Of Memory errors`);
    }
    const content = await fs.readFile(localFile);
    return content.toString('base64');
  }

  const remoteUrl = url.parse(remotePath);
  let options = {};
  const {user, pass, method} = uploadOptions;
  if (remoteUrl.protocol.startsWith('http')) {
    options = {
      url: remoteUrl.href,
      method: method || 'PUT',
      multipart: [{ body: _fs.createReadStream(localFile) }],
    };
    if (user && pass) {
      options.auth = {user, pass};
    }
  } else if (remoteUrl.protocol === 'ftp:') {
github appium / appium-xcuitest-driver / lib / wda / utils.js View on Github external
async function replaceInFile (file, find, replace) {
  let contents = await fs.readFile(file, 'utf8');

  let newContents = contents.replace(find, replace);
  if (newContents !== contents) {
    await fs.writeFile(file, newContents, 'utf8');
  }
}
github appium / appium-ios-driver / test / e2e / driver / uiauto / base.js View on Github external
async function localPrepareBootstrap (opts = {}) {
  if (opts.bootstrap === 'basic') {
    let env = uiauto.getEnv();
    let postImports = [];
    if (opts.imports && opts.imports.post) {
      postImports = opts.imports.post;
    }
    postImports = postImports.map((item) => {
      return `#import "${path.resolve(rootDir , item)}"`;
    });
    let code = await fs.readFile(path.resolve(
      rootDir, 'test', 'assets', 'base-bootstrap.js'), 'utf8');
    let vars = {
      '': rootDir,
      '""': postImports.join('\n'),
      '': env.commandProxyClientPath,
      '': env.nodePath,
      '': env.instrumentsSock
    };
    for (let [key, value] of _.toPairs(vars)) {
      code = code.replace(new RegExp(key, 'g'), value);
    }
    return await uiauto.prepareBootstrap({
      code: code,
      isVerbose: true
    });
  } else {
github appium / appium-adb / lib / tools / apk-signing.js View on Github external
async function patchApksigner (originalPath) {
  const originalContent = await fs.readFile(originalPath, 'ascii');
  const patchedContent = originalContent.replace('-Djava.ext.dirs="%frameworkdir%"',
    '-cp "%frameworkdir%\\*"');
  if (patchedContent === originalContent) {
    return originalPath;
  }
  log.debug(`Patching '${originalPath}...`);
  const patchedPath = await tempDir.path({prefix: 'apksigner', suffix: '.bat'});
  await mkdirp(path.dirname(patchedPath));
  await fs.writeFile(patchedPath, patchedContent, 'ascii');
  return patchedPath;
}
github appium / appium / check-pruned-shrinkwrap.js View on Github external
async function main () {
  const shrinkwrapPath = path.resolve('npm-shrinkwrap.json');
  if (!(await fs.exists(shrinkwrapPath))) {
    log.info('No shrinkwrap found. Skipping shrinkwrap check');
    return;
  }
  const shrinkwrap = JSON.parse(await fs.readFile(shrinkwrapPath));
  const backupShrinkwrap = JSON.parse(await fs.readFile(path.resolve('npm-shrinkwrap-backup.json')));
  log.info('Checking that pruned shrinkwrap is a subset of primary shrinkwrap');
  if (!_.isMatch(backupShrinkwrap, shrinkwrap)) {
    log.errorAndThrow('Pruned shrinkwrap (shrinkwrap with dev dependencies removed) is not a subset of the original npm-shrinkwrap.json');
  }
  log.info('Shrinkwrap check passed');
}