How to use adb.pull method in Appium Android Driver

Best JavaScript code snippet using appium-android-driver

apk_pull.js

Source:apk_pull.js Github

copy

Full Screen

1#!/usr/bin/env node2/*3apk_pull CLI4Extract any APK from any connected Android device or Genymotion Player5Usage:6node apk_pull appname/appid [outputdirectory] 7*/8// init globals9var _shell = require('shelljs'),10 _colors = require('colors'),11 _ora = require('ora'),12 _path = require('path'),13 fs = require('fs'),14 _cheerio = require('cheerio'),15 _cur_dir = process.cwd(),16 args = process.argv.slice(2),17 connected = false,18 _packages = {},19 _packnames = {},20 _progress;21var _omit_packages = [22 'com.monotype.*',23 'com.sec.*',24 'com.samsung.*',25 'org.simalliance.*',26 'com.android.*',27 'com.example.*',28 'jp.co.omronsoft.openwnn',29 'com.svox.pico',30 'com.amaze.filemanager',31 'com.google.android.*',32 'com.gd.mobicore.pa',33 'android',34 'com.fmm.*',35 'com.visionobjects.*',36 'com.wssnps',37 'com.policydm',38 'com.wssyncmldm',39 'daemon*'40];41//shell run42var _run = function(cmd) {43 var _r = _shell.exec(cmd, { silent:true });44 return { out: _r.stdout, code: _r.code, error: _r.stderr };45};46//get appname from appid47var getName = function(appid, cb) {48 var request = require('request'), _resp='', res, body='', $;49 //console.log('requesting name for '.green+appid.yellow);50 request({ timeout:3000, url:'https://play.google.com/store/apps/details?id='+appid.toLowerCase() }, function (error, response, body) {51 if (!error && response.statusCode == 200) {52 _progress.color = 'cyan', _progress.text = 'reading package: '+this._appid;53 try {54 $ = _cheerio.load(body);55 _resp = $('div[class=id-app-title]').text();56 } catch(_i) {57 }58 } else {59 _resp = this._appid; // if app-title is not found, return appid60 }61 cb(_resp);62 }.bind({ _appid:appid }))63};64// GET USING ADB PULL65var getApkPath = function(appid) {66 var _resp = _run(__dirname + _path.sep + 'bin/adb shell pm path '+appid).out.split('package:').join('');67 return _resp;68};69var getApkPull = function(appdir, appname, cb) {70 //console.log("running: "+__dirname + _path.sep + "bin/adb pull '"+appdir+"' '" + _cur_dir + _path.sep + appname + ".apk'");71 var _copy = _run(__dirname + _path.sep + "bin/adb pull '"+appdir+"' '" + _cur_dir + _path.sep + appname + ".apk'").out;72 //console.log('reply:'+_copy);73 if (_copy.indexOf('adb: error')>-1) {74 cb(false);75 } else {76 cb(true);77 }78};79// GET USING ANDROID BACKUP (unrooted devices)80var getAndroidBackup = function(appid, cb) {81 console.log('Please unlock the device and accept the backup.'.green);82 var _ab = _run(__dirname + _path.sep + 'bin/adb backup -apk '+appid);83 console.log('backup ready'.yellow);84 cb(true);85};86var androidBackup2apk = function(appid, appname, cb) {87 var _appname = appname; //.split('.').join(''); // clean char names.88 _progress = _ora({ text: 'Extracting APK from backup: '+appname, spinner:'dots5' }).start();89 var _cvt = _run('dd if='+_cur_dir + _path.sep + 'backup.ab bs=1 skip=24 | python -c "import zlib,sys;sys.stdout.write(zlib.decompress(sys.stdin.read()))" | tar -xvf -');90 _progress.color = 'green', _progress.text = 'almost ready';91 var _src = _cur_dir + _path.sep + 'apps' + _path.sep + appid + _path.sep + 'a' + _path.sep + 'base.apk';92 var _dst = _cur_dir + _path.sep + _appname + '.apk';93 _shell.mv(_src,_dst);94 // clean95 _progress.color = 'green', _progress.text = 'cleaning';96 fs.unlink(_cur_dir + _path.sep + 'backup.ab');97 var _full_appdir = _path.join(_cur_dir,'apps'+_path.sep);98 deleteFolderRecursive(_full_appdir);99 //100 cb(true);101};102// END USING ANDROID BACKUP103//test if there is an android device connected104var getPackages = function(cb) {105 var _is = _run(__dirname + _path.sep + 'bin/adb shell pm list packages -3');106 _packages = {}, _packnames = {};107 if (_is.code==0) {108 connected = true;109 _progress.color = 'cyan', _progress.text = 'reading packages';110 var _lines = _is.out.split('\n');111 // get real packages from device112 for (var line_f in _lines) {113 var line = _lines[line_f].split('package:').join('').trim();114 // check this package isn't within omit_packages115 var _inc = true;116 for (var _om in _omit_packages) {117 var _omit = _omit_packages[_om];118 if (_omit.indexOf('*')>-1) {119 // test if omit in inside line120 var _omit_s = _omit.split('*').join('');121 if (line.indexOf(_omit_s)!==-1) {122 _inc = false;123 }124 } else {125 // test if omit is exactly the same as line126 if (line==_omit) {127 _inc = false;128 }129 }130 }131 if (_inc && line!='') {132 _packages[line]='';133 }134 }135 // get packages realnames136 var _completed = 0;137 var _total = Object.keys(_packages).length;138 for (var _id in _packages) {139 getName(_id, function(real) {140 _packages[this._id] = real;141 _packnames[real] = this._id;142 _completed++;143 if (_completed == _total) {144 cb(_packages);145 }146 }.bind({ _id:_id }));147 }148 if (_total==0) cb([]);149 //150 } else {151 if (_is.error.indexOf('no devices found')!=-1) {152 connected = false;153 _progress.color = 'red', _progress.text = 'no android device detected';154 //console.log('apk_pull -> no connected android device detected !'.red);155 } else {156 _progress.color = 'red', _progress.text = 'error reading bin/adb';157 //console.log('apk_pull -> error reading bin/adb'.red,_is);158 }159 cb([]);160 }161};162var deleteFolderRecursive = function(path) {163 if( fs.existsSync(path) ) {164 fs.readdirSync(path).forEach(function(file,index){165 var curPath = path + "/" + file;166 if(fs.lstatSync(curPath).isDirectory()) { // recurse167 deleteFolderRecursive(curPath);168 } else { // delete file169 fs.unlinkSync(curPath);170 }171 });172 fs.rmdirSync(path);173 }174};175//CLI start176console.log('APK Pull - Get Any APK from Any Connected Android Device'.green);177_progress = _ora({ text: 'Detecting android devices', spinner:'dots5' }).start();178getPackages(function(data) {179 _progress.stop();180 // TODO: process arguments here : apk_pull appname [apkdir]181 if (connected==false) {182 console.log('apk_pull -> no connected android device detected !'.red);183 } else {184 if (args.length>=1) {185 // search data for appname or appid186 var _appid_required = '';187 for (var _i in data) {188 if (data[_i].toLowerCase()==args[0].toLowerCase()) {189 _appid_required = _i; //appname found, assign appid190 } else if (_i.toLowerCase()==args[0].toLowerCase()) {191 _appid_required = _i; //appid found, assign appid192 }193 }194 //195 if (_appid_required!='') {196 var _apkpull = getApkPath(_appid_required);197 if (_apkpull!='') {198 // Get APK using ADB Pull199 getApkPull(_apkpull, _packages[_appid_required], function(result) {200 if (result) {201 _progress.stop();202 console.log('apk restored.'.green);203 } else {204 // there was an error using adb pull, retrieve using backup205 // Get APK Using Android Backup (unrooted devices)206 getAndroidBackup(_appid_required, function(ready) {207 androidBackup2apk(_appid_required,_packages[_appid_required],function(readyto) {208 _progress.stop();209 if (args.length==2) {210 // if apkdir given, move apk to that directory.211 // if apkdir doesn't exist, create it212 }213 console.log('apk restored.'.green);214 });215 });216 }217 });218 } else {219 // Get APK Using Android Backup (unrooted devices)220 getAndroidBackup(_appid_required, function(ready) {221 androidBackup2apk(_appid_required,_packages[_appid_required],function(readyto) {222 _progress.stop();223 if (args.length==2) {224 // if apkdir given, move apk to that directory.225 // if apkdir doesn't exist, create it226 }227 console.log('apk restored.'.green);228 });229 });230 }231 } else {232 console.log('appname or appid not found on device.');233 }234 //235 } else {236 // show menu237 var choices = [];238 for (var _i in data) {239 choices.push({ name:data[_i], value:_i });240 }241 if (choices.length==0) {242 _progress.stop();243 console.log('No real apps detected on device.'.red);244 } else {245 // show menu246 var inquirer = require('inquirer');247 choices.push(new inquirer.Separator());248 choices.push({ name:':: Exit ::', value:'_exit_' });249 choices.push(new inquirer.Separator());250 inquirer.prompt([251 { type:'list', 252 name:'appid', 253 message:'Please select an app of your device:',254 choices:choices255 }256 ]).then(function(answer) {257 if (answer.appid!='_exit_') {258 var _apkpull = getApkPath(answer.appid);259 if (_apkpull!='') {260 // Get APK using ADB Pull261 getApkPull(_apkpull, _packages[answer.appid], function(result) {262 if (result) {263 _progress.stop();264 console.log('apk restored.'.green);265 } else {266 // there was an error using adb pull, use Android Backup267 // Get APK using Android Backup (unrooted devices)268 getAndroidBackup(answer.appid, function(ready) {269 androidBackup2apk(answer.appid,_packages[answer.appid],function(readyto) {270 _progress.stop();271 console.log('apk restored.'.green);272 });273 });274 //275 }276 });277 } else {278 // Get APK using Android Backup (unrooted devices)279 getAndroidBackup(answer.appid, function(ready) {280 androidBackup2apk(answer.appid,_packages[answer.appid],function(readyto) {281 _progress.stop();282 console.log('apk restored.'.green);283 });284 });285 }286 } else {287 console.log('exit requested.'.yellow);288 }289 });290 // end menu291 }292 }293 }...

Full Screen

Full Screen

file-actions-specs.js

Source:file-actions-specs.js Github

copy

Full Screen

1import chai from 'chai';2import chaiAsPromised from 'chai-as-promised';3import sinon from 'sinon';4import AndroidDriver from '../../..';5import * as support from 'appium-support';6import ADB from 'appium-adb';7let driver;8let sandbox = sinon.createSandbox();9chai.should();10chai.use(chaiAsPromised);11describe('File Actions', function () {12 beforeEach(function () {13 driver = new AndroidDriver();14 driver.adb = new ADB();15 });16 afterEach(function () {17 sandbox.restore();18 });19 describe('pullFile', function () {20 it('should be able to pull file from device', async function () {21 let localFile = 'local/tmp_file';22 sandbox.stub(support.tempDir, 'path').returns(localFile);23 sandbox.stub(driver.adb, 'pull');24 sandbox.stub(support.util, 'toInMemoryBase64')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');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 });...

Full Screen

Full Screen

pull_logs.js

Source:pull_logs.js Github

copy

Full Screen

1const FS = require('fs');2const Exec = require('child_process').exec;3const SourceMap = require('source-map');4var cmdArgs = process.argv.slice(2);5function hasArg(a) {6 if (typeof(a) != typeof([]))7 a = [a];8 return cmdArgs.filter(arg => arg == a).length > 0;9}10/*11 * Files loaded from ADB and are ready, parse the crashlog.12 */13function onFilesReady(crashlog, sourcemap, deployment) {14 deployment = JSON.parse(deployment);15 sourcemap = JSON.parse(sourcemap);16 crashlog = crashlog.toString('utf-8').split('\n').join(' ');17 crashlog = crashlog.match(/==--~~==(.*?)==~~--==/gi);18 crashlog = crashlog.map(L => JSON.parse(L.substr(8, L.length - 16)));19 console.log("Deployment:", deployment.commit);20 SourceMap.SourceMapConsumer.with(sourcemap, null, consumer => {21 if (hasArg(["--latest", "-l"]))22 crashlog = crashlog.slice(crashlog.length-1);23 for (var i = 0; i < crashlog.length; i++) {24 if (typeof(crashlog[i]) == typeof({}) && crashlog[i].stack && crashlog[i].message) {25 console.log("\nStack trace: ");26 for (var j = crashlog[i].stack.length - 1; j >= 0; j--) {27 var frame = crashlog[i].stack[j];28 var location = consumer.originalPositionFor(frame);29 var actualLine = getActualLine(location.source, location.line);30 var trimmedLine = actualLine.trim();31 var trimmedCol = location.column - (actualLine.indexOf(trimmedLine));32 console.log("\033[31m" + actualLine.trim() + "\033[0m");33 console.log(Array.from(new Array(trimmedCol), (v, i) => ' ').join("") + Array.from(new Array(location.name ? location.name.length : 1), (v, i) => '^').join(""));34 console.log(' ' + location.source + ':' + location.line + ':' + location.column + ' (' + frame.function + ')');35 console.log("=================");36 }37 console.log("\n" + crashlog[i].message);38 } else {39 console.log(crashlog[i]);40 }41 }42 });43}44function getActualLine(filename, lineNumber) {45 // @TODO: store source files on the tablet and pull them when doing this comparison46 try {47 return FS.readFileSync(filename, 'utf-8').split('\n')[lineNumber-1];48 } catch(err) {49 return "<Unknown file>";50 }51}52/*53 * Pull crash logs, sourcemap and deployment files from ADB, load them,54 * delete them and call onFilesReady().55 */56Exec("adb pull /sdcard/crashlog.txt ./tmp_crashlog.txt", (err, stdout, stderr) => {57 console.log(stdout, stderr);58 if (err) {}59 else {60 Exec("adb pull /sdcard/android.main.bundle.map ./tmp_sourcemap.map", (err, stdout, stderr) => {61 console.log(stdout, stderr);62 if (err) {}63 else {64 Exec("adb pull /sdcard/deployment.txt ./tmp_deployment.json", (err, stdout, stderr) => {65 console.log(stdout, stderr);66 if (err) {}67 else {68 FS.readFile('./tmp_crashlog.txt', function(err, crashlog) {69 if (err) console.log(err);70 else {71 FS.readFile('./tmp_sourcemap.map', function(err, sourcemap) {72 if (err) console.log(err);73 else {74 FS.readFile('./tmp_deployment.json', function(err, deployment) {75 if (err) {}76 else {77 Exec("rm ./tmp_crashlog.txt; rm ./tmp_sourcemap.map; rm ./tmp_deployment.json", (err, stdout, stderr) => {78 console.log(stdout, stderr);79 if (err) console.log(err);80 else {81 onFilesReady(crashlog, sourcemap, deployment);82 }83 });84 }85 });86 }87 });88 }89 });90 }91 });92 }93 });94 }...

Full Screen

Full Screen

play.js

Source:play.js Github

copy

Full Screen

1'use strict';2const cp = require('child_process');3const path = require('path');4const _ = require('lodash');5var imageinfo = require('imageinfo'),6 fs = require('fs');7const binary_path = '/Users/arsalanahmad/Code/pianotiles/pianotiles/target/release/pianotiles';8const GetWindowIdPath = '/Users/arsalanahmad/Code/GetWindowID/GetWindowID';9function* getNextId() {10 let uniqueId = 0;11 while (true) {12 if (uniqueId > 30) {13 uniqueId = 0;14 }15 yield uniqueId++;16 }17}18const idMaker = getNextId();19const bluestacksWindowId = cp.execSync(`${GetWindowIdPath} "BlueStacks" "BlueStacks App Player"`).toString().trim();20cp.execSync(`adb shell "screencap -p /sdcard/screen.png"; adb pull /sdcard/screen.png reference.png`);21cp.execSync(`convert -rotate "> -90" reference.png reference.png`);22const refData = fs.readFileSync('reference.png');23const refInfo = imageinfo(refData);24console.log(" Dimensions:", refInfo.width, "x", refInfo.height);25const capturedInfo = {26 width: 404,27 height: 719,28 offset: {29 x: 438,30 y: 4431 }32};33const coordsMultiplier = {34 x: refInfo.width / capturedInfo.width,35 y: refInfo.height / capturedInfo.height,36};37console.log('multipliers', coordsMultiplier);38while (true) {39 const currentId = idMaker.next().value;40 // console.log(`adb shell "screencap -p /sdcard/screen.png"; adb pull /sdcard/screen.png screen-${currentId}.png`);41 // cp.execSync(`adb shell "screencap -p /sdcard/screen.png"; adb pull /sdcard/screen.png screen-${currentId}.png`);42 // cp.execSync(`convert -rotate "> -90" screen-${currentId}.png screen-${currentId}.png`)43 cp.execSync(`screencapture -l${bluestacksWindowId} -o screen-${currentId}.png`);44 cp.execSync(`convert -crop ${capturedInfo.width}x${capturedInfo.height}+${capturedInfo.offset.x}+${capturedInfo.offset.y} screen-${currentId}.png screen-${currentId}.png`);45 const imgPath = path.join(process.cwd(), `screen-${currentId}.png`);46 const output = cp.execSync(`${binary_path} "${imgPath}"`).toString();47 48 const lines = output.split('\n');49 if (lines.length === 0) {50 process.exit();51 }52 const coords = _(lines).map(line => {53 // console.log(line);54 const coords = line.split(',');55 if (coords[1])56 return { x: Math.round(Number(coords[0]) * coordsMultiplier.x), y: Math.round(Number(coords[1]) * coordsMultiplier.y) };57 }).filter().sortBy(c => -c.y).value();58 if (coords.length > 0) {59 const commands = _(coords).take(2).value().map(c => `input tap ${c.x} ${c.y + 1}; `).join('');60 console.log(`screen-${currentId}.png :: adb shell "${commands}"`);61 cp.execSync(`adb shell "${commands}"`);62 }...

Full Screen

Full Screen

upload.js

Source:upload.js Github

copy

Full Screen

1// const Promise = require("bluebird");2const fs = require("fs");3const adb = require("adbkit");4const path = require("path");5const adbPullFiles = require("../../services/adbPullFiles");6let client = adb.createClient();7const uploadFile = (id = null) => {8 return new Promise((resolve, reject) => {9 client10 .listDevices()11 .then(function (devices) {12 if (devices.length == 0) {13 return new Error("Device not Connected");14 }15 let device;16 if (id) {17 let i = 0;18 let n = devices.length;19 while (i < n && devices[i].id != id) {20 i++;21 }22 if (i == n) {23 reject(Error("Invalid ID"));24 }25 device = devices[i];26 } else {27 device = devices[0];28 }29 client.readdir(device.id, "/sdcard/metonics").then(function (files) {30 files.forEach(function (file) {31 if (file.isFile()) {32 adbPullFiles(file, device);33 }34 });35 });36 })37 .then(function () {38 console.log("Done checking /sdcard files on connected devices");39 return resolve("file successfully moved");40 })41 .catch(function (err) {42 console.error("Something went wrong:", err.stack);43 return reject("something went wrong" + err.stack);44 });45 });46};...

Full Screen

Full Screen

sendFromDevice.js

Source:sendFromDevice.js Github

copy

Full Screen

...21}22async function copyToLocal(adb, source, local, options) {23 let filename = path.basename(source);24 if (!options.isFolder) {25 await adb.pull(source, local);26 return path.resolve(local, filename);27 }28 // The dot is for recursive copy according to29 // android.stackexchange.com/questions/87326/recursive-adb-pull30 await adb.pull(`${source}/.`, local);31 await exec(`tar -cf ${filename}.tar *`, {cwd: local});32 await exec(`gzip ${filename}.tar`, {cwd: local});33 return path.resolve(local, `${filename}.tar.gz`);34}...

Full Screen

Full Screen

01.gameDataPhone.js

Source:01.gameDataPhone.js Github

copy

Full Screen

1module.exports = function (shared) {2 var toDir = shared.makeWinPath(shared.versionPath),3 dirs = {4 files: toDir + "\\files",5 cache: toDir + "\\cache"6 },7 cmds = shared._.flattenDeep([8 `echo "run adb pull"`,9 `echo move to "${shared.makeWinPath(shared.toolPath.adb)}"`,10 `pushd ${shared.makeWinPath(shared.toolPath.adb)}`, // navigate to adb tool11 shared.appFiles.map(file => {12 return [13 `echo "copy ${file}.dat"`,14 `adb pull ${shared.androidPath}${shared.appPath}/files/${file}.dat ${shared.versionPath}`15 ];16 }),17 ]);18 shared.grunt.config("exec.copyContentViaAdb.cmd", cmds.join(" & "));19 shared.ensureDirectoryExistence(shared.versionPath + "/adb.jo");20 //console.log(cmds)21 shared.grunt.task.run(["exec:copyContentViaAdb"]);...

Full Screen

Full Screen

adb.js

Source:adb.js Github

copy

Full Screen

1const fs = require('fs')2const path = require('path')3const { commandSpawn } = require('./sample/utils/terminal');4// adb shell screencap -p /sdcard/screen2.png5// adb pull /sdcard/screen1.png6// adb shell uiautomator dump /sdcard/ui.xml7commandSpawn("adb", ["shell", "uiautomator", "dump", "/sdcard/ui.xml"])8// adb pull /sdcard/ui.xml ...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var path = require('path');2var appium = require('appium');3var wd = require('wd');4var assert = require('assert');5var fs = require('fs');6var adb = require('adbkit');7var client = adb.createClient();8var desired = {9 app: path.resolve(__dirname, '../app/ApiDemos-debug.apk')10};11var driver = wd.promiseChainRemote('localhost', 4723);12 .init(desired)13 .sleep(3000)14 .then(function() {15 return client.listDevices();16 })17 .then(function(devices) {18 console.log(devices);19 return client.pull(devices[0].id, '/data/local/tmp/strings.json');20 })21 .then(adb.util.readAll)22 .then(function(transfer) {23 console.log('Received ' + transfer.bytesTransferred + ' bytes');24 fs.writeFileSync('strings.json', transfer.data);25 })26 .catch(function(err) {27 console.error('Something went wrong:', err.stack);28 })29 .fin(function() {30 driver.quit();31 })32 .done();33{

Full Screen

Using AI Code Generation

copy

Full Screen

1var AppiumAndroidDriver = require('appium-android-driver');2var adb = new AppiumAndroidDriver.ADB();3var pullPath = '/data/local/tmp/abc.txt';4var localPath = 'abc.txt';5adb.pull(pullPath, localPath);6var AppiumAndroidDriver = require('appium-android-driver');7var adb = new AppiumAndroidDriver.ADB();8var localPath = 'abc.txt';9var remotePath = '/data/local/tmp/abc.txt';10adb.push(localPath, remotePath);11var AppiumAndroidDriver = require('appium-android-driver');12var adb = new AppiumAndroidDriver.ADB();13var cmd = 'ls -l';14adb.shell(cmd);15var AppiumAndroidDriver = require('appium-android-driver');16var adb = new AppiumAndroidDriver.ADB();17var cmd = 'ls -l';18adb.shell(cmd);19var AppiumAndroidDriver = require('appium-android-driver');20var adb = new AppiumAndroidDriver.ADB();21var cmd = 'ls -l';22adb.shell(cmd);23var AppiumAndroidDriver = require('appium-android-driver');24var adb = new AppiumAndroidDriver.ADB();25var cmd = 'ls -l';26adb.shell(cmd);27var AppiumAndroidDriver = require('appium-android-driver');28var adb = new AppiumAndroidDriver.ADB();29var cmd = 'ls -l';30adb.shell(cmd);31var AppiumAndroidDriver = require('appium-android-driver');32var adb = new AppiumAndroidDriver.ADB();33var cmd = 'ls -l';34adb.shell(cmd);35var AppiumAndroidDriver = require('appium-android-driver');36var adb = new AppiumAndroidDriver.ADB();

Full Screen

Using AI Code Generation

copy

Full Screen

1var AppiumAndroidDriver = require('appium-android-driver');2var adb = new AppiumAndroidDriver.ADB();3adb.pull('data/local/tmp/test.txt', 'test.txt');4var AppiumAndroidDriver = require('appium-android-driver');5var adb = new AppiumAndroidDriver.ADB();6adb.pull('data/local/tmp/test.txt', 'test.txt');7var AppiumAndroidDriver = require('appium-android-driver');8var adb = new AppiumAndroidDriver.ADB();9adb.pull('data/local/tmp/test.txt', 'test.txt');10var AppiumAndroidDriver = require('appium-android-driver');11var adb = new AppiumAndroidDriver.ADB();12adb.pull('data/local/tmp/test.txt', 'test.txt');13var AppiumAndroidDriver = require('appium-android-driver');14var adb = new AppiumAndroidDriver.ADB();15adb.pull('data/local/tmp/test.txt', 'test.txt');16var AppiumAndroidDriver = require('appium-android-driver');17var adb = new AppiumAndroidDriver.ADB();18adb.pull('data/local/tmp/test.txt', 'test.txt');19var AppiumAndroidDriver = require('appium-android-driver');20var adb = new AppiumAndroidDriver.ADB();21adb.pull('data/local/tmp/test.txt', 'test.txt');22var AppiumAndroidDriver = require('appium-android-driver');23var adb = new AppiumAndroidDriver.ADB();24adb.pull('data/local/tmp/test.txt', 'test.txt');25var AppiumAndroidDriver = require('appium-android-driver');26var adb = new AppiumAndroidDriver.ADB();27adb.pull('data/local/tmp/test.txt', 'test.txt');

Full Screen

Using AI Code Generation

copy

Full Screen

1var fs = require('fs');2var wd = require('wd');3var assert = require('assert');4var path = require('path');5var adb = require('adbkit');6var client = adb.createClient();7var file = 'path/to/file/on/device';8var dest = 'path/to/save/file/on/local/machine';9var driver = wd.promiseChainRemote("localhost", 4723);10var desired = {11};12 .init(desired)13 .then(function() {14 return driver.pull(file, dest);15 })16 .then(function() {17 return driver.quit();18 })19 .then(function() {20 console.log('Done!');21 })22 .catch(function(err) {23 console.error(err.stack);24 });25var fs = require('fs');26var wd = require('wd');27var assert = require('assert');28var path = require('path');29var adb = require('adbkit');30var client = adb.createClient();31var file = 'path/to/file/on/local/machine';32var dest = 'path/to/save/file/on/device';33var driver = wd.promiseChainRemote("localhost", 4723);34var desired = {35};36 .init(desired)37 .then(function() {38 return driver.push(file, dest);39 })40 .then(function() {41 return driver.quit();42 })43 .then(function() {44 console.log('Done!');45 })46 .catch(function(err) {47 console.error(err.stack);48 });49var fs = require('fs');50var wd = require('wd');51var assert = require('assert');52var path = require('path');53var adb = require('adbkit');54var client = adb.createClient();55var command = 'shell command to execute';56var driver = wd.promiseChainRemote("localhost", 4723);57var desired = {

Full Screen

Using AI Code Generation

copy

Full Screen

1var AndroidDriver = require("appium-android-driver");2var driver = new AndroidDriver();3driver.pull("/data/local/tmp/test.js", "./test.js", function(err, data) {4 if(err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10var AndroidDriver = require("appium-android-driver");11var driver = new AndroidDriver();12driver.push("./test.js", "/data/local/tmp/test.js", function(err, data) {13 if(err) {14 console.log(err);15 } else {16 console.log(data);17 }18});19var AndroidDriver = require("appium-android-driver");20var driver = new AndroidDriver();21driver.shell("ls", function(err, data) {22 if(err) {23 console.log(err);24 } else {25 console.log(data);26 }27});28var AndroidDriver = require("appium-android-driver");29var driver = new AndroidDriver();30driver.startLogcat(function(err, data) {31 if(err) {32 console.log(err);33 } else {34 console.log(data);35 }36});37var AndroidDriver = require("appium-android-driver");38var driver = new AndroidDriver();39driver.stopLogcat(function(err, data) {40 if(err) {41 console.log(err);42 } else {43 console.log(data);44 }45});

Full Screen

Using AI Code Generation

copy

Full Screen

1const wdio = require("webdriverio");2const opts = {3 capabilities: {4 },5};6async function main() {7 const client = await wdio.remote(opts);8 const pull = await client.pullFile("/data/local/tmp/strings.json");9 console.log(pull);10}11main();12const wdio = require("webdriverio");13const opts = {14 capabilities: {15 },16};17async function main() {18 const client = await wdio.remote(opts);19 const pull = await client.pullFile("/data/local/tmp/strings.json");20 console.log(pull);21}22main();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { AndroidDriver } = require('appium-android-driver');2const driver = new AndroidDriver();3driver.createSession({4});5driver.adb.pull('/data/local/tmp/strings.json', 'strings.json');6driver.deleteSession();7{8}9const { AndroidDriver } = require('appium-android-driver');10const driver = new AndroidDriver();11driver.createSession({12});13driver.adb.push('strings.json', '/data/local/tmp/strings.json');14driver.deleteSession();15const { AndroidDriver } = require('appium-android-driver');16const driver = new AndroidDriver();17driver.createSession({18});19driver.adb.shell('ls /data/local/tmp').then((output) => {20 console.log(output);21 driver.deleteSession();22});

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