Appium iOS 真机未实现 push_file?& 如何通过 libimobiledevice or ios-deploy 关闭指定 app

xiaoxiaoyang · 2018年05月18日 · 最后由 xiaoxiaoyang 回复于 2018年05月21日 · 130 次阅读


操作系统:Mac OS 10.13.4
设备:iPhone 6 / iOS 10.3.3


  1. Appium 的文档中有关于push_file的接口说明Push File,但是没有说明/path/to/device/foo.bar具体的例子,想请教有成功在iOS真机上执行成功的吗?

  2. 查了一些资料(比较老了)说只在模拟器上实现了。但其实Appium使用的ifuse是可以在真机上完成push_file的操作的,如果没有实现真机,不知道出于什么考虑没有实现这个功能?

  3. 另外,因为我没有对UI操作的需求,所以可以不用Appium。我也用ios-deploy 和 ifuse完成了大部分功能。但是没有办法通过命令行退出APP,请教有什么工具可以吗?



driver.push_file('image_0.txt', 'test')




共收到 3 条回复 时间 点赞

 * Save the given base64 data chunk as a binary file on the device under test.
 * ifuse/osxfuse should be installed and configured on the target machine in order
 * for this function to work properly. Read
 * and for more details.
 * @param {Object} device - The device object, which represents the device under test.
 *                          This object is expected to have the `udid` property containing the
 *                          valid device ID.
 * @param {string} remotePath - The remote path on the device. This variable can be prefixed with
 *                              bundle id, so then the file will be uploaded to the corresponding
 *                              application container instead of the default media folder, for example
 *                              '@com.myapp.bla/RelativePathInContainer/111.png'. The '@' character at the
 *                              beginning of the argument is mandatory in such case.
 * @param {string} base64Data - Base-64 encoded content of the file to be uploaded.
async function pushFileToRealDevice (device, remotePath, base64Data) {
  await verifyIFusePresence();
  const mntRoot = await tempDir.openDir();
  let isUnmountSuccessful = true;
  try {
    let dstPath = path.resolve(mntRoot, remotePath);
    let ifuseArgs = ['-u', device.udid, mntRoot];
    if (remotePath.startsWith(CONTAINER_PATH_MARKER)) {
      const [bundleId, pathInContainer] = await parseContainerPath(remotePath, mntRoot);
      dstPath = pathInContainer;`Parsed bundle identifier '${bundleId}' from '${remotePath}'. ` +
               `Will put the data into '${dstPath}'`);
      ifuseArgs = ['-u', device.udid, '--container', bundleId, mntRoot];
    } else {
      verifyIsSubPath(dstPath, 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 mkdirp(path.dirname(dstPath));
      await fs.writeFile(dstPath, Buffer.from(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}'`);
Lihuazhang 回复


需要 登录 后方可回复, 如果你还没有账号请点击这里 注册