How to use the appium-support.fs.writeFile 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 / test / functional / helpers / ci-metrics.js View on Github external
// TODO: add identification info when the parser can handle it
          // build: {
          //   sessionId: driver.sessionID,
          //   date: buildDate,
          //   'git-sha': gitRev,
          // },
        });
        if (events) {
          log.info(`Event timings: ${JSON.stringify(events)}`);
          // write to a JSON file, for consumption at the end of the run
          let ciMetricsDir = path.resolve('ci-metrics');
          log.debug(`CI Metrics in directory: ${ciMetricsDir}`);
          if (!await fs.exists(ciMetricsDir)) {
            await mkdirp(ciMetricsDir);
          }
          await fs.writeFile(path.resolve(ciMetricsDir, `${driver.sessionID}.json`), JSON.stringify(events));

          try {
            log.debug('Sending event timing data to SumoLogic');
            await sendToSumoLogic(events);
          } catch (err) {
            log.debug(`Unable to send data to SumoLogic: ${err.message}`);
          }
        }
        return await quit.call(driver);
      };
github appium / appium-android-driver / lib / commands / actions.js View on Github external
commands.pushFile = async function pushFile (remotePath, base64Data) {
  if (remotePath.endsWith('/')) {
    log.errorAndThrow(`It is expected that remote path points to a file and not to a folder. ` +
                      `'${remotePath}' is given instead`);
  }
  const localFile = await tempDir.path({prefix: 'appium', suffix: '.tmp'});
  if (_.isArray(base64Data)) {
    // some clients (ahem) java, send a byte array encoding utf8 characters
    // instead of a string, which would be infinitely better!
    base64Data = Buffer.from(base64Data).toString('utf8');
  }
  const content = Buffer.from(base64Data, 'base64');
  let tmpDestination = null;
  try {
    await fs.writeFile(localFile, content.toString('binary'), 'binary');
    if (remotePath.startsWith(CONTAINER_PATH_MARKER)) {
      const [packageId, pathInContainer] = parseContainerPath(remotePath);
      log.info(`Parsed package identifier '${packageId}' from '${remotePath}'. Will put the data into '${pathInContainer}'`);
      tmpDestination = `/data/local/tmp/${path.posix.basename(pathInContainer)}`;
      try {
        await this.adb.shell(
          ['run-as', packageId, `mkdir -p '${path.posix.dirname(pathInContainer).replace(/'/g, '\\\'')}'`]
        );
        await this.adb.shell(['run-as', packageId, `touch '${pathInContainer.replace(/'/g, '\\\'')}'`]);
        await this.adb.shell(['run-as', packageId, `chmod 777 '${pathInContainer.replace(/'/g, '\\\'')}'`]);
        await this.adb.push(localFile, tmpDestination);
        await this.adb.shell(['cp', '-f', tmpDestination, pathInContainer]);
      } catch (e) {
        log.errorAndThrow(`Cannot access the container of '${packageId}' application. ` +
                          `Is the application installed and has 'debuggable' build option set to true? ` +
                          `Original error: ${e.message}`);
github appium / appium / commands-yml / parse.js View on Github external
const inputJSON = yaml.load(inputYML);
    inputJSON.ymlFileName = `/${path.relative(rootFolder, filename)}`;
    const validationErrors = validate(inputJSON, validator);
    if (validationErrors) {
      throw new Error(`Data validation error for ${filename}: ${JSON.stringify(validationErrors)}`);
    }

    // Pass the inputJS into our Handlebars template
    const markdown = template(inputJSON);

    // Write the markdown to its right place
    const markdownPath = replaceExt(relativeFilename, '.md');
    const outfile = path.resolve(rootFolder, 'docs', 'en', markdownPath);
    log(`    Writing to: ${outfile}`);
    await mkdirp(path.dirname(outfile));
    await fs.writeFile(outfile, markdown, 'utf8');

    fileCount++;
  }
  log(`Done writing ${fileCount} command documents`);
}
github appium / appium-adb / lib / tools / adb-commands.js View on Github external
methods.isScreenLocked = async function isScreenLocked () {
  let stdout = await this.shell(['dumpsys', 'window']);
  if (process.env.APPIUM_LOG_DUMPSYS) {
    // optional debugging
    // if the method is not working, turn it on and send us the output
    let dumpsysFile = path.resolve(process.cwd(), 'dumpsys.log');
    log.debug(`Writing dumpsys output to ${dumpsysFile}`);
    await fs.writeFile(dumpsysFile, stdout);
  }
  return (isShowingLockscreen(stdout) || isCurrentFocusOnKeyguard(stdout) ||
          !isScreenOnFully(stdout));
};
github appium / appium-xcuitest-driver / test / functional / device / file-movement-e2e-specs.js View on Github external
it('should pull all the files in Library/AddressBook', async function () {
          const remotePath = `Library/AddressBook`;
          const data = await driver.pullFolder(remotePath);
          const tmpRoot = await tempDir.openDir();
          try {
            const zipPath = path.resolve(tmpRoot, 'data.zip');
            const extractedDataPath = path.resolve(tmpRoot, 'extracted_data');
            await fs.writeFile(zipPath, Buffer.from(data, 'base64'));
            await fs.mkdir(extractedDataPath);
            await zip.extractAllTo(zipPath, extractedDataPath);
            const itemsCount = (await fs.readdir(extractedDataPath)).length;
            itemsCount.should.be.above(1);
          } finally {
            await fs.rimraf(tmpRoot);
          }
        });
      });
github appium / appium-xcuitest-driver / lib / commands / actions.js View on Github external
let ifuseArgs = ['-u', device.udid, mntRoot];
    if (remotePath.startsWith(CONTAINER_PATH_MARKER)) {
      const [bundleId, pathInContainer] = await parseContainerPath(remotePath, mntRoot);
      dstPath = pathInContainer;
      log.info(`Parsed bundle identifier '${bundleId}' from '${remotePath}'. ` +
               `Will put the data into '${dstPath}'`);
      ifuseArgs = ['-u', device.udid, '--container', bundleId, mntRoot];
    }
    await mountDevice(device, ifuseArgs);
    isUnmountSuccessful = false;
    try {
      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');
    } finally {
      await exec('umount', [mntRoot]);
      isUnmountSuccessful = true;
    }
  } finally {
    if (isUnmountSuccessful) {
      await fs.rimraf(mntRoot);
    } else {
      log.warn(`Umount has failed, so not removing '${mntRoot}'`);
    }
  }
}
github Samsung / appium-tizen-driver / lib / commands / action.js View on Github external
const localFile = path.resolve(fileDir, file);
  if (file.indexOf('/') > -1) {
    log.errorAndThrow(`It is expected that file point to a file and not to a folder. ` + `'${file}' is given instead`);
  }

  if (_.isArray(base64Data)) {
    base64Data = Buffer.from(base64Data).toString('utf8');
  }

  const content = Buffer.from(base64Data, 'base64');
  let isFileDir = await fs.exists(fileDir);
  if (!isFileDir) {
    await fs.mkdir(fileDir);
  }

  await fs.writeFile(localFile, content.toString('binary'), 'binary');

  return true;
};
github appium / appium-android-driver / lib / commands / recordscreen.js View on Github external
async function mergeScreenRecords (mediaFiles) {
  try {
    await fs.which(FFMPEG_BINARY);
  } catch (e) {
    throw new Error(`${FFMPEG_BINARY} utility is not available in PATH. Please install it from https://www.ffmpeg.org/`);
  }
  const configContent = mediaFiles
    .map((x) => `file '${x}'`)
    .join('\n');
  const configFile = path.resolve(path.dirname(mediaFiles[0]), 'config.txt');
  await fs.writeFile(configFile, configContent, 'utf8');
  log.debug(`Generated ffmpeg merging config '${configFile}' with items:\n${configContent}`);
  const result = path.resolve(path.dirname(mediaFiles[0]), `merge_${Math.floor(new Date())}${DEFAULT_EXT}`);
  const args = ['-safe', '0', '-f', 'concat', '-i', configFile, '-c', 'copy', result];
  log.info(`Initiating screen records merging using the command '${FFMPEG_BINARY} ${args.join(' ')}'`);
  await exec(FFMPEG_BINARY, args);
  return result;
}
github appium / appium-ios-driver / lib / commands / file-movement.js View on Github external
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
throw new Error(Object.prototype.toString.call(serverTestApk));
  }
  let serverFingerprint = await sha512(serverApk);
  let serverTestFingerprint = await sha512(serverTestApk);

  if (serverFingerprint !== SERVER_DOWNLOAD_SHA512) {
    log.errorAndThrow(`bad Server SHA512 fingerprint: ${serverFingerprint}`);
    log.error("Stopping the installation");
    return;
  }
  if (serverTestFingerprint !== SERVER_TEST_DOWNLOAD_SHA512) {
    log.errorAndThrow(`bad Server test SHA512 fingerprint: ${serverTestFingerprint}`);
    log.error("Stopping the installation");
    return;
  }
  await fs.writeFile(UI2_SERVER_APK_PATH, serverApk, {encoding: 'binary'});
  await fs.writeFile(UI2_TEST_APK_PATH, serverTestApk, {encoding: 'binary'});

  await fs.chmod(UI2_SERVER_APK_PATH, 0o0644);
  await fs.chmod(UI2_TEST_APK_PATH, 0o0644);

  log.info("UiAutomator2 Server APKs downloaded");
}