Best JavaScript code snippet using appium-android-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
...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
...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 wd = require('wd');2const path = require('path');3const desiredCaps = {4};5 .init(desiredCaps)6 .then(() => driver.pushFile('/sdcard/test.txt', 'Hello World'))7 .then(() => driver.quit());
Using AI Code Generation
1var fs = require('fs'), 2 path = require('path'),3 appium = require('appium'),4 wd = require('wd'),5 _ = require('underscore'),6 assert = require('assert');7var desired = {8};9var driver = wd.promiseChainRemote('localhost', 4723);10driver.init(desired).then(function () {11 return driver.getCurrentActivity();12}).then(function (activity) {13 var pushFileOptions = {14 data: fs.readFileSync(path.resolve(__dirname, 'somefile.txt'))15 };16 return driver.pushFile(pushFileOptions);17}).then(function (result) {18 assert.equal(result, null);19 return driver.quit();20}).done();
Using AI Code Generation
1var pathToApp = "/Users/xyz/Downloads/myapp.apk";2var pathToApp = "/Users/xyz/Downloads/myapp.apk";3driver.pushFile("/data/local/tmp/myapp.apk", pathToApp).then(function(result) {4console.log(result);5});6var pathToApp = "/Users/xyz/Downloads/myapp.apk";7var pathToApp = "/Users/xyz/Downloads/myapp.apk";8driver.adb.push(pathToApp, "/data/local/tmp/myapp.apk").then(function(result) {9console.log(result);10});11[Appium] Welcome to Appium v1.5.3 (REV 0d9c6e0a6c4e6b1e6d4a7f4f4b4c7fb9d6f0c7b3)
Using AI Code Generation
1const path = require('path');2const { remote } = require('webdriverio');3(async () => {4 const driver = await remote({5 capabilities: {6 }7 })8 const file = path.join(__dirname, 'test.txt');9 await driver.pushFile('data/local/tmp/test.txt', file);10 await driver.deleteSession();11})().catch((e) => console.error(e));
Check out the latest blogs from LambdaTest on this topic:
Testing is a critical step in any web application development process. However, it can be an overwhelming task if you don’t have the right tools and expertise. A large percentage of websites still launch with errors that frustrate users and negatively affect the overall success of the site. When a website faces failure after launch, it costs time and money to fix.
The web development industry is growing, and many Best Automated UI Testing Tools are available to test your web-based project to ensure it is bug-free and easily accessible for every user. These tools help you test your web project and make it fully compatible with user-end requirements and needs.
Desired Capabilities is a class used to declare a set of basic requirements such as combinations of browsers, operating systems, browser versions, etc. to perform automated cross browser testing of a web application.
Manual cross browser testing is neither efficient nor scalable as it will take ages to test on all permutations & combinations of browsers, operating systems, and their versions. Like every developer, I have also gone through that ‘I can do it all phase’. But if you are stuck validating your code changes over hundreds of browsers and OS combinations then your release window is going to look even shorter than it already is. This is why automated browser testing can be pivotal for modern-day release cycles as it speeds up the entire process of cross browser compatibility.
Mobile devices and mobile applications – both are booming in the world today. The idea of having the power of a computer in your pocket is revolutionary. As per Statista, mobile accounts for more than half of the web traffic worldwide. Mobile devices (excluding tablets) contributed to 54.4 percent of global website traffic in the fourth quarter of 2021, increasing consistently over the past couple of years.
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!!