How to use driver.pullFile method in Appium Android Driver

Best JavaScript code snippet using appium-android-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 driver = new webdriver.Builder()2 .forBrowser('android')3 .build();4driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');5driver.findElement(webdriver.By.name('btnG')).click();6driver.wait(function() {7 return driver.getTitle().then(function(title) {8 return title === 'webdriver - Google Search';9 });10}, 1000);11driver.takeScreenshot().then(function(data){12 var base64Data = data.replace(/^data:image\/png;base64,/,"");13 require("fs").writeFile("out.png", base64Data, 'base64', function(err) {14 console.log(err);15 });16});17driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd'),2 path = require('path'),3 assert = require('assert'),4 Q = require('q'),5 _ = require('underscore'),6 fs = require('fs'),7 _ = require('underscore'),8 chai = require('chai'),9 chaiAsPromised = require('chai-as-promised'),10 should = chai.should(),11 chaiAsPromised = require('chai-as-promised'),12 chai = require('chai'),13 chaiAsPromised = require('chai-as-promised'),14 should = chai.should(),15 chaiAsPromised = require('chai-as-promised'),16 chai = require('chai'),17 chaiAsPromised = require('chai-as-promised'),18 should = chai.should(),19 chaiAsPromised = require('chai-as-promised'),20 chai = require('chai'),21 chaiAsPromised = require('chai-as-promised'),22 should = chai.should(),23 chaiAsPromised = require('chai-as-promised'),24 chai = require('chai'),25 chaiAsPromised = require('chai-as-promised'),26 should = chai.should(),27 chaiAsPromised = require('chai-as-promised'),28 chai = require('chai'),29 chaiAsPromised = require('chai-as-promised'),30 should = chai.should(),31 chaiAsPromised = require('chai-as-promised'),32 chai = require('chai'),33 chaiAsPromised = require('chai-as-promised'),34 should = chai.should(),35 chaiAsPromised = require('chai-as-promised'),36 chai = require('chai'),37 chaiAsPromised = require('chai-as-promised'),38 should = chai.should(),39 chaiAsPromised = require('chai-as-promised'),40 chai = require('chai'),41 chaiAsPromised = require('chai-as-promised'),42 should = chai.should(),43 chaiAsPromised = require('chai-as-promised'),44 chai = require('chai'),45 chaiAsPromised = require('chai-as-promised'),46 should = chai.should(),47 chaiAsPromised = require('chai-as-promised'),48 chai = require('chai'),49 chaiAsPromised = require('chai-as-promised'),50 should = chai.should(),51 chaiAsPromised = require('chai-as-promised'),52 chai = require('chai'),53 chaiAsPromised = require('chai-as-promised'),

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var desired = {3};4var driver = new webdriver.Builder()5 .withCapabilities(desired)6 .build();7driver.pullFile('/data/data/com.example.android.apis/files/ApiDemos-debug.apk').then(function (data) {8 console.log(data);9});10driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3 .forBrowser('chrome')4 .build();5driver.takeScreenshot().then(function(data) {6 require('fs').writeFile('out.png', data, 'base64', function(err) {7 console.log(err);8 });9});10driver.quit();11driver.quit();12driver.quit();13driver.quit();14driver.quit();15driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1var driver = require('appium-android-driver').driver;2var path = require('path');3var driver = new AndroidDriver();4driver.createSession({5 app: path.resolve(__dirname, 'android-debug.apk'),6});7driver.pullFile('/data/local/tmp/remote.txt').then(function (data) {8 console.log(data);9});10driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var path = require('path');4var desired = {5};6var username = process.env.SAUCE_USERNAME;7var accessKey = process.env.SAUCE_ACCESS_KEY;8var driver;9driver = wd.remote("ondemand.saucelabs.com", 80, username, accessKey);10driver.init(desired, function(err, sessionID) {11 if (err) {12 console.log(err);13 } else {14 console.log("sessionID: " + sessionID);15 driver.pullFile("/sdcard/DCIM/Camera/IMG_20130903_112501.jpg", function(err, data) {16 if (err) {17 console.log(err);18 } else {19 console.log("File pulled from device");20 driver.quit();21 }22 });23 }24});25driver.startActivity(appPackage, appActivity, appWaitPackage, appWaitActivity, intentAction, intentCategory, intentFlags, optionalIntentArguments, dontStopAppOnReset, function(err, status) {...});26driver.backgroundApp(seconds, function(err, status) {...});27driver.isAppInstalled(appPackage, function(err, status) {...});28driver.installApp(appPath, function(err, status) {...});29driver.removeApp(appPackage, function(err, status) {...});30driver.terminateApp(appPackage, function(err, status) {...});31driver.launchApp(function(err, status) {...});32driver.closeApp(function(err, status) {...});33driver.resetApp(function(err, status) {...});34driver.currentActivity(function(err, activity) {...});35driver.currentPackage(function(err, activity) {...});36driver.getDeviceTime(function(err, time) {...});37driver.getGeoLocation(function(err, location) {...});38driver.setGeoLocation(latitude, longitude, altitude, function(err, status) {...});39driver.hideKeyboard(strategy, keyName, function(err

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 Android Driver automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful