How to use driver.pullFile method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

file-movement-specs.js

Source:file-movement-specs.js Github

copy

Full Screen

1"use strict";2var setup = require("../common/setup-base")3  , env = require('../../helpers/env')4  , getAppPath = require('../../helpers/app').getAppPath5  , fs = require('fs')6  , path = require('path')7  , Readable = require('stream').Readable8  , Simulator = require('../../../lib/devices/ios/simulator.js')9  , xcode = require('../../../lib/devices/ios/xcode.js')10  , exec = require('child_process').exec11  , getSimUdid = require('../../helpers/sim-udid.js').getSimUdid12  , Unzip = require('unzip');13describe('file movements - pullFile and pushFile', function () {14  var driver;15  var desired = {16    app: getAppPath('TestApp')17  };18  setup(this, desired).then(function (d) { driver = d; });19  it('should not be able to fetch a file from the file system at large', function (done) {20    driver21      .pullFile(__filename)22      .should.be.rejected23    .nodeify(done);24  });25  it('should be able to fetch the Address book', function (done) {26    driver27      .pullFile('Library/AddressBook/AddressBook.sqlitedb')28      .then(function (data) {29        var stringData = new Buffer(data, 'base64').toString();30        return stringData.indexOf('SQLite').should.not.equal(-1);31      })32    .nodeify(done);33  });34  it('should not be able to fetch something that does not exist', function (done) {35    driver36      .pullFile('Library/AddressBook/nothere.txt')37      .should.eventually.be.rejectedWith(/13/)38    .nodeify(done);39  });40  it('should be able to push and pull a file', function (done) {41    var stringData = "random string data " + Math.random();42    var base64Data = new Buffer(stringData).toString('base64');43    var remotePath = 'Library/AppiumTest/remote.txt';44    driver45      .pushFile(remotePath, base64Data)46      .pullFile(remotePath)47      .then(function (remoteData64) {48        var remoteData = new Buffer(remoteData64, 'base64').toString();49        remoteData.should.equal(stringData);50      })51      .nodeify(done);52  });53  describe('for a .app @skip-ci', function () {54    // TODO: skipping ci because of local files use, to review.55    var fileContent = "IAmTheVeryModelOfAModernMajorTestingTool";56    var fileName = "someFile.tmp";57    var fullPath = "";58    before(function (done) {59      var pv = env.CAPS.platformVersion || '7.1';60      var ios8 = parseFloat(pv) >= 8;61      xcode.getiOSSDKVersion(function (err, sdk) {62        if (err) return done(err);63        var next = function (udid) {64          var sim = new Simulator({65            platformVer: pv,66            sdkVer: sdk,67            udid: udid68          });69          var simRoots = sim.getDirs();70          if (simRoots.length < 1) {71            return done(new Error("Didn't find any simulator directories"));72          }73          var basePath;74          if (ios8) {75            // ios8 apps are stored in a different directory structure, need76            // to navigate down a few more here77            basePath = path.resolve(simRoots[0], 'Containers', 'Bundle',78                                       'Application');79          } else {80            basePath = path.resolve(simRoots[0], 'Applications');81          }82          basePath = basePath.replace(/\s/g, '\\ ');83          var findCmd = 'find ' + basePath + ' -name "TestApp.app"';84          exec(findCmd, function (err, stdout) {85            if (err) return done(err);86            if (!stdout) return done(new Error("Could not find testapp.app"));87            var appRoot = stdout.replace(/\n$/, '');88            fullPath = path.resolve(appRoot, fileName);89            fs.writeFile(fullPath, fileContent, done);90          });91        };92        if (parseFloat(sdk) >= 8) {93          getSimUdid('6', sdk, env.CAPS, function (err, udid) {94            if (err) return done(err);95            next(udid);96          });97        } else {98          next();99        }100      });101    });102    it('should be able to fetch a file from the app directory', function (done) {103      var arg = path.resolve('/TestApp.app', fileName);104      driver105        .pullFile(arg)106        .then(function (data) {107          var stringData = new Buffer(data, 'base64').toString();108          return stringData.should.equal(fileContent);109        })110        .nodeify(done);111    });112  });113  describe('file movements - pullFolder', function () {114    it('should pull all the files in Library/AddressBook', function (done) {115      var entryCount = 0;116      driver117        .pullFolder('Library/AddressBook')118        .then(function (data) {119          var zipStream = new Readable();120          zipStream._read = function noop() {};121          zipStream122            .pipe(Unzip.Parse())123            .on('entry', function (entry) {124              entryCount++;125              entry.autodrain();126            })127            .on('close', function () {128              entryCount.should.be.above(1);129              done();130            });131          zipStream.push(data, 'base64');132          zipStream.push(null);133        });134    });135    it('should not pull folders from file system', function (done) {136      driver137        .pullFolder(__dirname)138          .should.be.rejected139        .nodeify(done);140    });141    it('should not be able to fetch a folder that does not exist', function (done) {142      driver143        .pullFolder('Library/Rollodex')144          .should.eventually.be.rejectedWith(/13/)145        .nodeify(done);146    });147  });...

Full Screen

Full Screen

file-actions-specs.js

Source:file-actions-specs.js Github

copy

Full Screen

...25        .withArgs(localFile)26        .returns(Buffer.from('YXBwaXVt', 'utf8'));27      sandbox.stub(support.fs, 'exists').withArgs(localFile).returns(true);28      sandbox.stub(support.fs, 'unlink');29      await driver.pullFile('remote_path').should.become('YXBwaXVt');30      driver.adb.pull.calledWithExactly('remote_path', localFile)31        .should.be.true;32      support.fs.unlink.calledWithExactly(localFile).should.be.true;33    });34    it('should be able to pull file located in application container from the device', async function () {35      let localFile = 'local/tmp_file';36      const packageId = 'com.myapp';37      const remotePath = 'path/in/container';38      const tmpPath = '/data/local/tmp/container';39      sandbox.stub(support.tempDir, 'path').returns(localFile);40      sandbox.stub(driver.adb, 'pull');41      sandbox.stub(driver.adb, 'shell');42      sandbox.stub(support.util, 'toInMemoryBase64')43        .withArgs(localFile)44        .returns(Buffer.from('YXBwaXVt', 'utf8'));45      sandbox.stub(support.fs, 'exists').withArgs(localFile).returns(true);46      sandbox.stub(support.fs, 'unlink');47      await driver.pullFile(`@${packageId}/${remotePath}`).should.become('YXBwaXVt');48      driver.adb.pull.calledWithExactly(tmpPath, localFile).should.be.true;49      driver.adb.shell.calledWithExactly(['run-as', packageId, `chmod 777 '/data/data/${packageId}/${remotePath}'`]).should.be.true;50      driver.adb.shell.calledWithExactly(['cp', '-f', `/data/data/${packageId}/${remotePath}`, tmpPath]).should.be.true;51      support.fs.unlink.calledWithExactly(localFile).should.be.true;52      driver.adb.shell.calledWithExactly(['rm', '-f', tmpPath]).should.be.true;53    });54  });55  describe('pushFile', function () {56    it('should be able to push file to device', async function () {57      let localFile = 'local/tmp_file';58      let content = 'appium';59      sandbox.stub(support.tempDir, 'path').returns(localFile);60      sandbox.stub(driver.adb, 'push');61      sandbox.stub(driver.adb, 'shell');...

Full Screen

Full Screen

file-movement-e2e-specs.js

Source:file-movement-e2e-specs.js Github

copy

Full Screen

...18    after(async function () {19      await deleteSession();20    });21    async function pullFileAsString (remotePath) {22      let remoteData64 = await driver.pullFile(remotePath);23      return Buffer.from(remoteData64, 'base64').toString();24    }25    describe('sim relative', function () {26      describe('files', function () {27        it('should not be able to fetch a file from the file system at large', async function () {28          await driver.pullFile(__filename).should.eventually.be.rejected;29        });30        it('should be able to fetch the Address book', async function () {31          let stringData = await pullFileAsString(`${UICAT_CONTAINER}/PkgInfo`);32          stringData.indexOf('APPL').should.not.equal(-1);33        });34        it('should not be able to fetch something that does not exist', async function () {35          await driver.pullFile('Library/AddressBook/nothere.txt')36            .should.eventually.be.rejectedWith(/13/);37        });38        it('should be able to push and pull a file', async function () {39          let stringData = `random string data ${Math.random()}`;40          let base64Data = Buffer.from(stringData).toString('base64');41          let remotePath = `${UICAT_CONTAINER}/remote.txt`;42          await driver.pushFile(remotePath, base64Data);43          let remoteStringData = await pullFileAsString(remotePath);44          remoteStringData.should.equal(stringData);45        });46      });47      describe('folders', function () {48        it('should not pull folders from file system', async function () {49          await driver.pullFolder(__dirname).should.eventually.be.rejected;...

Full Screen

Full Screen

dowload.image.android.emulator.spec.js

Source:dowload.image.android.emulator.spec.js Github

copy

Full Screen

...54        expect(fileExists(filePath)).toEqual(false);55        // Pull the file from the device, it was uploaded in the before step56        // This is the `tricky` part, you need to know the file structure of the device and where you can download57        // the file from. I've checked this structure with the VUSB offering of Sauce Labs for private devices.58        const downloadedBase64Image = driver.pullFile(deviceFilePath);59        // Write the file to the file the correct folder60        writeFileSync(filePath, downloadedBase64Image, 'base64');61        // Now verify that the file does exist in our repo62        expect(fileExists(filePath)).toEqual(true);63    });...

Full Screen

Full Screen

dowload.image.android.simulator.spec.js

Source:dowload.image.android.simulator.spec.js Github

copy

Full Screen

...54        expect(fileExists(filePath)).toEqual(false);55        // Pull the file from the device, it was uploaded in the before step56        // This is the `tricky` part, you need to know the file structure of the device and where you can download57        // the file from. I've checked this structure with the VUSB offering of Sauce Labs for private devices.58        const downloadedBase64Image = driver.pullFile(deviceFilePath);59        // Write the file to the file the correct folder60        writeFileSync(filePath, downloadedBase64Image, 'base64');61        // Now verify that the file does exist in our repo62        expect(fileExists(filePath)).toEqual(true);63    });...

Full Screen

Full Screen

dowload.image.android.real.spec.js

Source:dowload.image.android.real.spec.js Github

copy

Full Screen

...50        expect(fileExists(filePath)).toEqual(false);51        // Pull the file from the device, it was uploaded in the before step52        // This is the `tricky` part, you need to know the file structure of the device and where you can download53        // the file from. I've checked this structure with the VUSB offering of Sauce Labs for private devices.54        const downloadedBase64Image = driver.pullFile(deviceFilePath);55        // Write the file to the file the correct folder56        writeFileSync(filePath, downloadedBase64Image, 'base64');57        // Now verify that the file does exist in our repo58        expect(fileExists(filePath)).toEqual(true);59    });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var fs = require('fs');2var wd = require('wd');3var path = require('path');4var assert = require('assert');5var username = process.env.SAUCE_USERNAME;6var accessKey = process.env.SAUCE_ACCESS_KEY;

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const assert = require('assert');3const serverConfig = {4};5const desiredCaps = {6};7const driver = wd.promiseChainRemote(serverConfig);8driver.init(desiredCaps)9    .then(() => driver.sleep(10000))10    .then(() => driver.pullFile('/Users/username/Library/Developer/CoreSimulator/Devices/6A8E6A7A-0D2A-4F2C-9C9E-6A0B5C1D1C8C/data/Containers/Data/Application/2D0F2B2B-1D6D-4F51-8A3A-3A8E6E2A2D9F/Documents/MyFile.txt'))11    .then((fileContent) => console.log(fileContent))12    .catch((err) => console.log(err))13    .finally(() => driver.quit());

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2   build();3driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');4driver.findElement(webdriver.By.name('btnG')).click();5driver.wait(function() {6  return driver.getTitle().then(function(title) {7    return title === 'webdriver - Google Search';8  });9}, 1000);10driver.quit();11driver.pullFile('Library/AddressBook/AddressBook.sqlitedb').then(function(base64String) {12});13driver.pullFolder('Library/AddressBook/').then(function(base64String) {14});15driver.pushFile('Library/AddressBook/AddressBook.sqlitedb', 'base64String').then(function() {16});17driver.pushFolder('Library/AddressBook/', 'base64String').then(function() {18});19driver.touchId(true).then(function() {20});21driver.toggleAirplaneMode().then(function() {22});23driver.toggleData().then(function() {24});25driver.toggleLocationServices().then(function() {26});27driver.toggleWiFi().then(function() {28});29driver.toggleTouchIdEnrollment(true).then(function() {30});

Full Screen

Using AI Code Generation

copy

Full Screen

1const path = require('path');2const {remote} = require('webdriverio');3(async () => {4    const browser = await remote({5        capabilities: {6            app: path.join(__dirname, 'test.app'),7        }8    })9    console.log(await browser.pullFile('/Library/Preferences/com.apple.springboard.plist'))10    await browser.deleteSession()11})().catch((e) => console.error(e))12const path = require('path');13const {remote} = require('webdriverio');14(async () => {15    const browser = await remote({16        capabilities: {17            app: path.join(__dirname, 'test.app'),18        }19    })20    console.log(await browser.pullFile('/Library/Preferences/com.apple.springboard.plist'))21    await browser.deleteSession()22})().catch((e) => console.error(e))23* Appium version (or git revision) that exhibits the issue: 1.10.024* Last Appium version that did not exhibit the issue (if applicable):25* Node.js version (unless using Appium.app|exe): 10.13.0

Full Screen

Using AI Code Generation

copy

Full Screen

1var driver = new wd.Builder()2    .forBrowser('safari')3    .build();4driver.init({5}).then(function () {6    return driver.execute('mobile: shell', {7    });8}).then(function () {9    return driver.pullFile('/Users/username/Documents/myfile.txt');10}).then(function (data) {11    console.log(data);12}).fin(function () { driver.quit(); })13    .done();14var fs = require('fs');15fs.writeFile('myfile.txt', data, function (err) {16    if (err) {17        return console.log(err);18    }19    console.log("The file was saved!");20});21driver.pullFile('/Users/username/Documents/mydir', { zip: true })22var iosDevice = require('appium-ios-device');23iosDevice.installApp('path/to/app.ipa').then(function (app) {24    return app.pullFile('myfile.txt');25}).then(function (data) {26    console.log(data);27}).fin(function () { iosDevice.cleanup(); })28    .done();

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var options = {3  desiredCapabilities: {4  }5};6var client = webdriverio.remote(options);7client.init()8  .then(function(){9    console.log('client initiated');10    return client.pullFile('/var/mobile/Containers/Data/Application/4A4F8B2E-7A6E-4F3B-8A4B-6E7C8E9F4F4E/Documents/MyFile.txt');11  })12  .then(function(file){13    console.log('File pulled from device');14    console.log(file);15  })16  .catch(function(err){17    console.log('Error pulling file from device');18    console.log(err);19  });20client.end();21var webdriverio = require('webdriverio');22var options = {23  desiredCapabilities: {24  }25};26var client = webdriverio.remote(options);27client.init()28  .then(function(){29    console.log('client initiated');30    return client.pullFolder('/var/mobile/Containers

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var fs = require('fs');4driver.init({5}).then(function () {6  return driver.pullFile('/Users/<username>/Library/Developer/Xcode/DerivedData/UICatalog-dhjzgkxqkajzgzbvzjxkxgjtnjwi/Build/Products/Debug-iphonesimulator/UICatalog.app/Info.plist');7}).then(function (data) {8  fs.writeFileSync('Info.plist', data);9  console.log('File pulled successfully');10  return driver.quit();11}).catch(function (err) {12  console.log('Error: ' + err);13});

Full Screen

Using AI Code Generation

copy

Full Screen

1const webdriverio = require('webdriverio');2const appium = require('wdio-appium-service');3const logger = require('wdio-logger').default;4const fs = require('fs');5const path = require('path');6const util = require('util');7const mkdirp = require('mkdirp');8const rimraf = require('rimraf');9const chai = require('chai');10const chaiAsPromised = require('chai-as-promised');11const chaiFs = require('chai-fs');12const chaiArrays = require('chai-arrays');13const chaiThings = require('chai-things');14const chaiString = require('chai-string');15const chaiXml = require('chai-xml');16const chaiJsonSchema = require('chai-json-schema');17const chaiJsonEqual = require('chai-json-equal');18const chaiJsonSchemaAjv = require('chai-json-schema-ajv');19const chaiDatetime = require('chai-datetime');20const chaiJestSnapshot = require('chai-jest-snapshot');21const chaiJestDiff = require('chai-jest-diff');22const chaiDom = require('chai-dom');23const chaiEnzyme = require('chai-enzyme');24const chaiJquery = require('chai-jquery');25const chaiShallowDeepEqual = require('chai-shallow-deep-equal');26const chaiSpies = require('chai-spies');

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var opts = {3    desiredCapabilities: {4    }5};6var client = webdriverio.remote(opts);7    .init()8    .pullFile('/private/var/mobile/Containers/Data/Application/.../Documents/MyFile.txt')9    .then(function (fileContent) {10        console.log(fileContent);11    })12    .end();13Error: Could not pull file: Error Domain=com.apple.dt.xctest.error Code=1 "Failed to copy file at /private/var/mobile/Containers/Data/Application/.../Documents/MyFile.txt to /var/folders/.../.../T/.../MyFile.txt" UserInfo={NSLocalizedFailureReason=Failed to copy file at /private/var/mobile/Containers/Data/Application/.../Documents/MyFile.txt to /var/folders/.../.../T/.../MyFile.txt, NSLocalizedDescription=Failed to copy file at /private/var/mobile/Containers/Data/Application/.../Documents/MyFile.txt to /var/folders/.../.../T/.../MyFile.txt, NSUnderlyingError=0x7f9f6e4e6b60 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium Xcuitest Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Sign up Free
_

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful