Best JavaScript code snippet using appium-xcuitest-driver
file-actions-specs.js
Source:file-actions-specs.js
...61 sandbox.stub(driver.adb, 'shell');62 sandbox.stub(support.fs, 'writeFile');63 sandbox.stub(support.fs, 'exists').withArgs(localFile).returns(true);64 sandbox.stub(support.fs, 'unlink');65 await driver.pushFile('remote_path', 'YXBwaXVt');66 support.fs.writeFile.calledWithExactly(localFile, content, 'binary').should.be.true;67 support.fs.unlink.calledWithExactly(localFile).should.be.true;68 driver.adb.push.calledWithExactly(localFile, 'remote_path').should.be.true;69 });70 it('should be able to push file located in application container to the device', async function () {71 let localFile = 'local/tmp_file';72 let content = 'appium';73 const packageId = 'com.myapp';74 const remotePath = 'path/in/container';75 const tmpPath = '/data/local/tmp/container';76 sandbox.stub(support.tempDir, 'path').returns(localFile);77 sandbox.stub(driver.adb, 'push');78 sandbox.stub(driver.adb, 'shell');79 sandbox.stub(support.fs, 'writeFile');80 sandbox.stub(support.fs, 'exists').withArgs(localFile).returns(true);81 sandbox.stub(support.fs, 'unlink');82 await driver.pushFile(`@${packageId}/${remotePath}`, 'YXBwaXVt');83 support.fs.writeFile.calledWithExactly(localFile, content, 'binary').should.be.true;84 driver.adb.push.calledWithExactly(localFile, tmpPath).should.be.true;85 driver.adb.shell.calledWithExactly(['run-as', packageId, `mkdir -p '/data/data/${packageId}/path/in'`]).should.be.true;86 driver.adb.shell.calledWithExactly(['run-as', packageId, `touch '/data/data/${packageId}/${remotePath}'`]).should.be.true;87 driver.adb.shell.calledWithExactly(['run-as', packageId, `chmod 777 '/data/data/${packageId}/${remotePath}'`]).should.be.true;88 driver.adb.shell.calledWithExactly(['cp', '-f', tmpPath, `/data/data/${packageId}/${remotePath}`]).should.be.true;89 support.fs.unlink.calledWithExactly(localFile).should.be.true;90 driver.adb.shell.calledWithExactly(['rm', '-f', tmpPath]).should.be.true;91 });92 });...
file-movement-e2e-specs.js
Source:file-movement-e2e-specs.js
...25 it('should push and pull a file', async function () {26 let stringData = `random string data ${Math.random()}`;27 let base64Data = Buffer.from(stringData).toString('base64');28 let remotePath = `${getRandomDir()}/remote.txt`;29 await driver.pushFile(remotePath, base64Data);30 // get the file and its contents, to check31 let remoteData64 = await driver.pullFile(remotePath);32 let remoteData = Buffer.from(remoteData64, 'base64').toString();33 remoteData.should.equal(stringData);34 });35 it('should delete pushed file', async function () {36 let stringData = `random string data ${Math.random()}`;37 let base64Data = Buffer.from(stringData).toString('base64');38 let remotePath = `${getRandomDir()}/remote.txt`;39 await driver.pushFile(remotePath, base64Data);40 (await driver.execute('mobile: deleteFile', {remotePath})).should.be.true;41 // The file should be already gone42 (await driver.execute('mobile: deleteFile', {remotePath})).should.be.false;43 });44 it('should pull a folder', async function () {45 const stringData = `random string data ${Math.random()}`;46 const base64Data = Buffer.from(stringData).toString('base64');47 // send the files, then pull the whole folder48 const remoteDir = getRandomDir();49 await driver.pushFile(`${remoteDir}/remote0.txt`, base64Data);50 await driver.pushFile(`${remoteDir}/remote1.txt`, base64Data);51 const data = await driver.pullFolder(remoteDir);52 const tmpRoot = await tempDir.openDir();53 try {54 const zipPath = path.resolve(tmpRoot, 'data.zip');55 await fs.writeFile(zipPath, Buffer.from(data, 'base64'));56 const extractedDataPath = path.resolve(tmpRoot, 'extracted_data');57 await fs.mkdir(extractedDataPath);58 await zip.extractAllTo(zipPath, extractedDataPath);59 const itemsCount = (await fs.readdir(extractedDataPath)).length;60 itemsCount.should.eql(2);61 } finally {62 await fs.rimraf(tmpRoot);63 }64 });...
upload.image.android.emulator.spec.js
Source:upload.image.android.emulator.spec.js
...24 const codingBot = readFileSync(join(process.cwd(), 'assets/sauce-bot-coding.png'), 'base64');25 // Push it to the device and wait till it is uploaded26 // Device manufacturers put pictures in different places, you do need to know the path on your device that27 // stores media. For emulators and at least some real devices, the path on the device is `/mnt/sdcard/Pictures`28 driver.pushFile('/mnt/sdcard/Pictures/sauce-bot-coding.png', codingBot);29 driver.waitUntil(() => GooglePhotos.amountOfPhotos > currentPhotos);30 // Delete the photo and verify that the amount of photos is equal to when the test started31 GooglePhotos.deletePhoto('last');32 expect(GooglePhotos.amountOfPhotos).toEqual(currentPhotos);33 });...
file-movement-specs.js
Source:file-movement-specs.js
1"use strict";2var setup = require("../../common/setup-base")3 , Readable = require('stream').Readable4 , Unzip = require('unzip')5 , desired = require("./desired");6describe("apidemos - file", function () {7 var driver;8 setup(this, desired).then(function (d) { driver = d; });9 it('should push and pull a file', function (done) {10 var stringData = "random string data " + Math.random();11 var base64Data = new Buffer(stringData).toString('base64');12 var remotePath = '/data/local/tmp/remote.txt';13 driver14 .pushFile(remotePath, base64Data)15 .pullFile(remotePath)16 .then(function (remoteData64) {17 var remoteData = new Buffer(remoteData64, 'base64').toString();18 remoteData.should.equal(stringData);19 })20 .nodeify(done);21 });22 it('should pull a folder', function (done) {23 var stringData = "random string data " + Math.random();24 var base64Data = new Buffer(stringData).toString('base64');25 var remotePath0 = '/data/local/tmp/remote0.txt';26 var remotePath1 = '/data/local/tmp/remote1.txt';27 var entryCount = 0;28 driver29 .pushFile(remotePath0, base64Data)30 .pushFile(remotePath1, base64Data)31 .pullFolder('/data/local/tmp')32 .then(function (data) {33 var zipStream = new Readable();34 zipStream._read = function noop() {};35 zipStream36 .pipe(Unzip.Parse())37 .on('entry', function (entry) {38 entryCount++;39 entry.autodrain();40 })41 .on('close', function () {42 entryCount.should.be.above(1);43 done();44 });45 zipStream.push(data, 'base64');46 zipStream.push(null);47 });48 });...
upload.image.android.real.spec.js
Source:upload.image.android.real.spec.js
...19 const codingBot = readFileSync(join(process.cwd(), 'assets/sauce-bot-coding.png'), 'base64');20 // Push it to the device and wait till it is uploaded21 // This is the `tricky` part, you need to know the file structure of the device and where you can download22 // the file from. I've checked this structure with the VUSB offering of Sauce Labs for private devices.23 driver.pushFile('/storage/self/primary/sauce-bot-coding.png', codingBot);24 driver.waitUntil(25 () => SamsungGallery.amountOfPhotos > currentPhotos,26 );27 // Delete the photo and verify that the amount of photos is equal to when the test started28 SamsungGallery.deletePhoto('last');29 expect(SamsungGallery.amountOfPhotos).toEqual(currentPhotos);30 });...
Using AI Code Generation
1const { remote } = require('webdriverio');2const fs = require('fs');3(async () => {4 const browser = await remote({5 capabilities: {6 }7 });8 const data = fs.readFileSync('/Users/username/Desktop/MyFile.txt');9 await browser.pushFile('/Documents/MyFile.txt', data);10 await browser.deleteSession();11})();
Using AI Code Generation
1const { remote } = require('webdriverio');2const { exec } = require('child_process');3const opts = {4 capabilities: {5 }6};7async function main() {8 const client = await remote(opts);9 await client.pause(10000);10 await client.pushFile('/var/mobile/Containers/Data/Application/12345678-1234-1234-1234-1234567890AB/Documents/test.txt', 'This is a test file');11 await client.pause(10000);12 await client.deleteSession();13}14main();15Appium version (or git revision) that exhibits the issue: 1.8.116Last Appium version that did not exhibit the issue (if applicable): N/A17Node.js version (unless using Appium.app|exe): 10.4.118[HTTP] {"path":"/var/mobile/Containers/Data/Application/12345678-1234-1234-1234-1234567890AB/Documents/test.txt","data":"VGhpcyBpcyBhIHRlc3QgZmlsZQ=="}19[debug] [MJSONWP] Calling AppiumDriver.pushFile() with args: ["/var/mobile/Containers/Data/Application/12345678-1234-1234-1234-1234567890AB/Documents/test.txt","VG
Using AI Code Generation
1const wd = require('wd');2const path = require('path');3async function test() {4 let desired = {5 };6 await driver.init(desired);7 let el = await driver.elementByCss('input[type="file"]');8 await driver.pushFile(el, path.resolve('test.txt'));9 await driver.quit();10}11test();
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!