How to use adb.shell method in Appium Android Driver

Best JavaScript code snippet using appium-android-driver

webview-helper-specs.js

Source:webview-helper-specs.js Github

copy

Full Screen

1import sinon from 'sinon';2import helpers from '../../lib/webview-helpers';3import ADB from 'appium-adb';4let sandbox = sinon.sandbox.create();5describe('Webview Helpers', () => {6  let adb = new ADB();7  afterEach(() => {8    sandbox.restore();9  });10  describe('procFromWebview', function () {11    const webview = 'WEBVIEW_123';12    const pkg = 'io.appium.android.apis';13    it('should get package name when all fields are filled', async function () {14      sandbox.stub(adb, 'shell', function () {15        return 'USER           PID  PPID     VSZ    RSS WCHAN            ADDR S NAME\n' +16               'root             1     0    9948   2344 SyS_epoll_wait      0 S init\n' +17               'root             2     0       0      0 kthreadd            0 S [kthreadd]\n' +18               'root             3     2       0      0 smpboot_thread_fn   0 S [ksoftirqd/0]\n' +19               'root             5     2       0      0 worker_thread       0 S [kworker/0:0H]\n' +20               'root             7     2       0      0 rcu_gp_kthread      0 S [rcu_preempt]\n' +21               'u0_a88         123  1313 1513968 135756 ffffffff            0 R io.appium.android.apis\n';22      });23      let name = await helpers.procFromWebview(adb, webview);24      name.should.eql(pkg);25    });26    it('should get package name when some fields are empty', async function () {27      sandbox.stub(adb, 'shell', function () {28        return 'USER           PID  PPID     VSZ    RSS WCHAN            ADDR S NAME\n' +29               'root             1     0    9948   2344 SyS_epoll_wait      0 S init\n' +30               'root             2     0       0      0 kthreadd            0 S [kthreadd]\n' +31               'root             3     2       0      0 smpboot_thread_fn   0 S [ksoftirqd/0]\n' +32               'root             5     2       0      0 worker_thread       0 S [kworker/0:0H]\n' +33               'root             7     2       0      0 rcu_gp_kthread      0 S [rcu_preempt]\n' +34               'u0_a88         123  1313 1513968 135756                     0 R io.appium.android.apis\n';35      });36      let name = await helpers.procFromWebview(adb, webview);37      name.should.eql(pkg);38    });39    it('should get package name when some headers are empty', async function () {40      sandbox.stub(adb, 'shell', function () {41        return 'USER           PID  PPID     VSZ    RSS WCHAN            ADDR   NAME\n' +42               'root             1     0    9948   2344 SyS_epoll_wait      0 S init\n' +43               'root             2     0       0      0 kthreadd            0 S [kthreadd]\n' +44               'root             3     2       0      0 smpboot_thread_fn   0 S [ksoftirqd/0]\n' +45               'root             5     2       0      0 worker_thread       0 S [kworker/0:0H]\n' +46               'root             7     2       0      0 rcu_gp_kthread      0 S [rcu_preempt]\n' +47               'u0_a88         123  1313 1513968 135756 ffffffff            0 R io.appium.android.apis\n';48      });49      let name = await helpers.procFromWebview(adb, webview);50      name.should.eql(pkg);51    });52    it('should get package name when some headers and fields are empty', async function () {53      sandbox.stub(adb, 'shell', function () {54        return 'USER           PID  PPID     VSZ    RSS WCHAN            ADDR   NAME\n' +55               'root             1     0    9948   2344 SyS_epoll_wait      0 S init\n' +56               'root             2     0       0      0 kthreadd            0 S [kthreadd]\n' +57               'root             3     2       0      0 smpboot_thread_fn   0 S [ksoftirqd/0]\n' +58               'root             5     2       0      0 worker_thread       0 S [kworker/0:0H]\n' +59               'root             7     2       0      0 rcu_gp_kthread      0 S [rcu_preempt]\n' +60               'u0_a88         123  1313 1513968 135756                     0 R io.appium.android.apis\n';61      });62      let name = await helpers.procFromWebview(adb, webview);63      name.should.eql(pkg);64    });65  });66  describe('When the webviews are obtained', function () {67    describe('for an app that embeds Chromium', function () {68      let webViews;69      beforeEach(async function () {70        sandbox.stub(adb, 'shell', () => {71          return 'Num       RefCount Protocol Flags    Type St Inode Path\n' +72                '0000000000000000: 00000002 00000000 00010000 0001 01  2818 /dev/socket/ss_conn_daemon\n' +73                '0000000000000000: 00000002 00000000 00010000 0001 01  9231 @mcdaemon\n' +74                '0000000000000000: 00000002 00000000 00010000 0001 01 245445 @webview_devtools_remote_123\n' +75                '0000000000000000: 00000002 00000000 00010000 0001 01  2826 /dev/socket/installd\n';76        });77        webViews = await helpers.getWebviews(adb, 'webview_devtools_remote_123');78      });79      it('then the unix sockets are queried', function () {80        adb.shell.calledOnce.should.be.true;81        adb.shell.getCall(0).args[0].should.deep.equal(['cat', '/proc/net/unix']);82      });83      it('then the webview is returned', function () {84        webViews.length.should.equal(1);85        webViews.should.deep.equal(['WEBVIEW_123']);86      });87    });88    describe('for a Chromium webview', function () {89      let webViews;90      beforeEach(async function () {91        sandbox.stub(adb, 'shell', function () {92          return 'Num       RefCount Protocol Flags    Type St Inode Path\n' +93                '0000000000000000: 00000002 00000000 00010000 0001 01  2818 /dev/socket/ss_conn_daemon\n' +94                '0000000000000000: 00000002 00000000 00010000 0001 01  9231 @mcdaemon\n' +95                '0000000000000000: 00000002 00000000 00010000 0001 01 245445 @chrome_devtools_remote\n' +96                '0000000000000000: 00000002 00000000 00010000 0001 01  2826 /dev/socket/installd\n';97        });98        webViews = await helpers.getWebviews(adb, 'chrome_devtools_remote');99      });100      it('then the unix sockets are queried', function () {101        adb.shell.calledOnce.should.be.true;102        adb.shell.getCall(0).args[0].should.deep.equal(['cat', '/proc/net/unix']);103      });104      it('then the webview is returned', function () {105        webViews.length.should.equal(1);106        webViews.should.deep.equal(['CHROMIUM']);107      });108    });109    describe('and no webviews exist', function () {110      let webViews;111      beforeEach(async () => {112        sandbox.stub(adb, 'shell', function () {113          return 'Num       RefCount Protocol Flags    Type St Inode Path\n' +114                '0000000000000000: 00000002 00000000 00010000 0001 01  2818 /dev/socket/ss_conn_daemon\n' +115                '0000000000000000: 00000002 00000000 00010000 0001 01  9231 @mcdaemon\n' +116                '0000000000000000: 00000002 00000000 00010000 0001 01  2826 /dev/socket/installd\n';117        });118        webViews = await helpers.getWebviews(adb);119      });120      it('then the unix sockets are queried', function () {121        adb.shell.calledOnce.should.be.true;122        adb.shell.getCall(0).args[0].should.deep.equal(['cat', '/proc/net/unix']);123      });124      it('then no webviews are returned', function () {125        webViews.length.should.equal(0);126      });127    });128    describe('and crosswalk webviews exist', function () {129      let webViews;130      beforeEach(() => {131        sandbox.stub(adb, 'shell', () => {132          return 'Num       RefCount Protocol Flags    Type St Inode Path\n' +133                '0000000000000000: 00000002 00000000 00010000 0001 01  2818 /dev/socket/ss_conn_daemon\n' +134                '0000000000000000: 00000002 00000000 00010000 0001 01  9231 @mcdaemon\n' +135                '0000000000000000: 00000002 00000000 00010000 0001 01 245445 @com.application.myapp_devtools_remote\n' +136                '0000000000000000: 00000002 00000000 00010000 0001 01  2826 /dev/socket/installd\n';137        });138      });139      describe('and the device socket is not specified', function () {140        beforeEach(async () => {141          webViews = await helpers.getWebviews(adb);142        });143        it('then the unix sockets are queried', function () {144          adb.shell.calledOnce.should.be.true;145          adb.shell.getCall(0).args[0].should.deep.equal(['cat', '/proc/net/unix']);146        });147        it('then the webview is returned', function () {148          webViews.length.should.equal(1);149          webViews.should.deep.equal(['WEBVIEW_com.application.myapp']);150        });151      });152      describe('and the device socket is specified', function () {153        beforeEach(async function () {154          webViews = await helpers.getWebviews(adb, 'com.application.myapp_devtools_remote');155        });156        it('then the unix sockets are queried', function () {157          adb.shell.calledOnce.should.be.true;158          adb.shell.getCall(0).args[0].should.deep.equal(['cat', '/proc/net/unix']);159        });160        it('then the webview is returned', function () {161          webViews.length.should.equal(1);162          webViews.should.deep.equal(['WEBVIEW_com.application.myapp']);163        });164      });165      describe('and the device socket is specified but is not found', function () {166        beforeEach(async function () {167          webViews = await helpers.getWebviews(adb, 'com.application.myotherapp_devtools_remote');168        });169        it('then the unix sockets are queried', function () {170          adb.shell.calledOnce.should.be.true;171          adb.shell.getCall(0).args[0].should.deep.equal(['cat', '/proc/net/unix']);172        });173        it('then no webviews are returned', function () {174          webViews.length.should.equal(0);175        });176      });177    });178    describe('and webviews exist', function () {179      let webViews;180      beforeEach(async function () {181        let shellStub = sandbox.stub(adb, 'shell');182        shellStub.onCall(0).returns('Num               RefCount Protocol Flags    Type St Inode Path\n' +183                                    '0000000000000000: 00000002 00000000 00010000 0001 01  2818 /dev/socket/ss_conn_daemon\n' +184                                    '0000000000000000: 00000002 00000000 00010000 0001 01  9231 @mcdaemon\n' +185                                    '0000000000000000: 00000002 00000000 00010000 0001 01 245445 @webview_devtools_remote_1234\n' +186                                    '0000000000000000: 00000002 00000000 00010000 0001 01  2826 /dev/socket/installd\n');187        shellStub.onCall(1).returns('USER    PID  PPID VSIZE   RSS   WCHAN              PC   NAME\n' +188                                    'root      1     0  5792   988   SyS_epoll_ 0000000000 S /init\n' +189                                    'root      2     0     0     0   kthreadd   0000000000 S kthreadd\n' +190                                    'root   1234     2     0     0   SyS_epoll_ 0000000000 S com.application.myapp\n');191        webViews = await helpers.getWebviews(adb);192      });193      it('then the unix sockets and process list are queried', function () {194        adb.shell.calledTwice.should.be.true;195        adb.shell.getCall(0).args[0].should.deep.equal(['cat', '/proc/net/unix']);196        adb.shell.getCall(1).args[0].should.equal('ps');197      });198      it('then the webview is returned', function () {199        webViews.length.should.equal(1);200        webViews.should.deep.equal(['WEBVIEW_com.application.myapp']);201      });202    });203  });...

Full Screen

Full Screen

mini0.js

Source:mini0.js Github

copy

Full Screen

1'option strict';2const cp = require('child_process'),3  $path = require('path'),4  https = require('https'),5  { URL } = require('url');6fs = require('fs'),7  net = require('net');8const exp = module.exports = {9  info: {}, exec, execSync, fetchFile,10  webSockets: []11};12exp.wsSendBin = o => {13  for (let ws of exp.webSockets) ws.send(o, {14    binary: true15  });16};17exp.wsSendObj = o => {18  for (let ws of exp.webSockets) ws.sendObj(o);19};20const procs = [], sockets = [];21/**************************************************************************** */22// get info23/**************************************************************************** */24const info = exp.info;25info.abi = execSync('adb shell getprop ro.product.cpu.abi');26info.sdk = execSync('adb shell getprop ro.build.version.sdk');27let dumpsys = execSync(`adb shell dumpsys window`);28[info.junk, info.w, info.h] = dumpsys.match(/init=(\d+)x(\d+)/);29[info.junk, info.rot] = dumpsys.match(/mCurrentRotation=(?:ROTATION_)?(\d+)/);30if (info.rot == 1) info.rot = 90;31console.log('WxH & Rot:', info.w, info.h, info.rot);32delete info.junk;33let revertSettings = () => { };34if (process.argv.indexOf('-s') > 0) {35  let show_touches = execSync('adb shell settings get system show_touches');36  let scr_off_time = execSync('adb shell settings get system screen_off_timeout');37  let scr_bl_mode = execSync('adb shell settings get system screen_brightness_mode');38  let scr_bl = execSync('adb shell settings get system screen_brightness');39  execSync('adb shell settings put system show_touches 1');40  execSync('adb shell settings put system screen_off_timeout 2147483647');41  execSync('adb shell settings put system screen_brightness_mode 0');42  execSync('adb shell settings put system screen_brightness 0');43  revertSettings = () => {44    execSync(`adb shell settings put system show_touches ${show_touches}`);45    execSync(`adb shell settings put system screen_off_timeout ${scr_off_time}`);46    execSync(`adb shell settings put system screen_brightness ${scr_bl}`);47    execSync(`adb shell settings put system screen_brightness_mode ${scr_bl_mode}`);48  };49}50exp.closeSocket = socket => {51  if (!socket) return;52  if (socket.isOpen) {53    console.log(socket.name, 'closing socket');54    socket.shouldClose = true;55    socket.end();56  }57  else console.log(socket.name, 'socket already closed');58};59exp.killProc = proc => {60  if (!proc) return;61  if (proc.isRunning) {62    proc.shouldStop = true;63    console.log(proc.name, 'killing process');64    proc.kill();65  } else console.log(proc.name, 'process already exited');66};67exp.onExit = () => {68  revertSettings();69  for (let socket of sockets) exp.closeSocket(socket);70  for (let proc of procs) exp.killProc(proc);71};72/**************************************************************************** */73// port stuff74/**************************************************************************** */75exp.listPorts = () => {76  let fwd = execSync('adb forward --list');77  let rev = execSync('adb reverse --list');78  return `forward:\n${fwd}\n\nreverse:\n${rev}`;79};80exp.addPort = (port, rev) => {81  let type = rev ? 'reverse' : 'forward';82  let fwd = execSync(`adb ${type} tcp:${port} tcp:${port}`);83};84/**************************************************************************** */85// exec stuff86/**************************************************************************** */87function execSync(cmd, pwd) {88  console.log('execSync', cmd);89  let out = cp.execSync(cmd, { encoding: 'utf8', cwd: pwd || '.' }).trim();90  if (out) console.log('output', out);91  return out;92}93function exec(cmd, name, pwd, restart) {94  console.log('exec', cmd);95  let proc = cp.exec(cmd, {96    encoding: 'utf8', cwd: pwd || '.'97  });98  proc.stdout.on('data', d => console.log(name, 'o', d));99  proc.stderr.on('data', d => console.log(name, 'e', d));100  proc.isRunning = true;101  proc.shouldStop = !restart;102  proc.name = name || cmd;103  proc.on('exit', () => {104    if (!proc.shouldStop) exec(cmd, name, pwd, restart);105    proc.isRunning = false;106    console.log('exit', name);107  });108  procs.push(proc);109  return proc;110}111exp.bindir = (base) => $path.join(base, info.abi, 'bin');112exp.libdir = (base) => $path.join(base, info.abi, 'lib', 'android-' + info.sdk);113exp.fwdAbs = (hport, absname) => execSync(`adb forward tcp:${hport} localabstract:${absname}`);114exp.fwdPort = (hport, aport) => execSync(`adb forward tcp:${hport} localabstract:${aport}`);115exp.execSocket = (cmd, port, name, cbData) => {116  exp.fwdAbs(port, name);117  const proc = exec(cmd, name);118  proc.stdout.on('data', d => {119    if (!proc.hasSocket) setTimeout(() => {120      if (proc.hasSocket) return;121      proc.hasSocket = true;122      trySocket(proc, port, name, cbData);123    }, 100);124  });125  return proc;126};127function trySocket(proc, port, name, cbData) {128  if (!proc.socketTry) proc.socketTry = 1;129  else proc.socketTry++;130  console.log('***** starting stream', port, name, proc.socketTry);131  proc.socket = net.connect({ port });132  proc.socket.on('data', cbData);133  proc.socket.on('error', err => console.log('stream error', port, name, err));134  proc.socket.isOpen = true;135  proc.socket.name = name;136  if (proc.cbSocketStatus) proc.cbSocketStatus(true);137  sockets.push(proc.socket);138  proc.socket.on('end', () => {139    proc.socket.isOpen = false;140    if (proc.cbSocketStatus) proc.cbSocketStatus(false);141    if (proc.socket.shouldClose) return;142    console.log(`socket ${port}/${name} has closed - program may need to be restarted.`);143    if (proc.socketTry < 5) setTimeout(() => {144      trySocket(proc, port, name, cbData);145    }, 2000);146  });147}148exp.trySocket = trySocket;149/**************************************************************************** */150// url fetch stuff151/**************************************************************************** */152function fetchFile(url, fname) {153  if (!fs.existsSync(fname)) {154    console.log('getting from github: ', fname);155    return new Promise((resolve, reject) => {156      https.get(url, (res) => {157        if (res.statusCode === 302) return fetchFile(res.headers.location, fname);158        else if (res.statusCode === 200 && res.headers['content-type'] === "application/octet-stream") {159          let fstream = fs.createWriteStream(fname);160          res.pipe(fstream);161          res.on('end', () => {162            console.log('complete: ', fname);163            resolve(fname);164          });165        } else {166          var out = '';167          res.on('data', d => out += d.toString());168          res.on('end', () => {169            console.log('problem getting file', fname, out);170            reject(out);171          });172        }173      });174    });175  } else {176    console.log('using local copy:', fname);177    return Promise.resolve(fname);178  }179}180exp.fetchVersion = (url, def) => {181  return new Promise((resolve, reject) => {182    https.get(url, (res) => {183      if (res.statusCode === 302) {184        const retval = res.headers.location.replace(/.*\/([^/?]+).*$/, '$1');185        resolve(retval);186      }187      else resolve(def);188    });189  });...

Full Screen

Full Screen

adb.js

Source:adb.js Github

copy

Full Screen

1/**2 * @author andhikayuana@gmail.com3 * @since july, 25 20184 * 5 * @see http://adbshell.com/commands6 * 7 * adb commands : 8 * 1. ADB Debugging9 *    - adb devices [v]10 *    - adb forward 11 *    - adb kill-server [v]12 *    - adb start-server [v]13 * 2. Wireless14 *    - adb connect15 *    - adb usb16 * 3. Package Manager17 *    - adb install18 *    - adb uninstall19 *    - adb shell pm list packages20 *    - adb shell pm path21 *    - adb shell pm clear22 * 4. File Manager23 *    - adb pull24 *    - adb push25 *    - adb shell ls26 *    - adb shell cd27 *    - adb shell rm28 *    - adb shell mkdir29 *    - adb shell touch30 *    - adb shell pwd31 *    - adb shell cp32 *    - adb shell mv33 * 5. Network34 *    - adb shell netstat35 *    - adb shell ping36 *    - adb shell netcfg37 *    - adb shell ip38 * 6. Logcat39 *    - adb logcat [-] not all40 *    - adb shell dumpsys41 *    - adb shell dumpstate42 * 7. Screenshot43 *    - adb shell screencap44 *    - adb shell screenrecord [4.4+]45 * 8. System46 *    - adb root47 *    - adb sideload48 *    - adb shell ps49 *    - adb shell top50 *    - adb shell getprop51 *    - adb shell setprop52 */53const { exec } = require('child_process')54var tester = () => { return 4 + 6; }55module.exports.tester = tester56/**57 * ADB Debugging58 */59module.exports.devices = (callback) => exec('adb devices', callback)60module.exports.killServer = (callback) => exec('adb kill-server', callback)61module.exports.startServer = (callback) => exec('adb start-server', callback)62module.exports.logcat = (callback) => exec('adb logcat', callback)63module.exports.logcatV = (callback) => exec('adb logcat *:V', callback)64module.exports.logcatD = (callback) => exec('adb logcat *:D', callback)65module.exports.logcatI = (callback) => exec('adb logcat *:I', callback)66module.exports.logcatW = (callback) => exec('adb logcat *:W', callback)67module.exports.logcatE = (callback) => exec('adb logcat *:E', callback)68module.exports.logcatF = (callback) => exec('adb logcat *:F', callback)...

Full Screen

Full Screen

auto.js

Source:auto.js Github

copy

Full Screen

1const exec = require('child_process').execSync;2const disX = 250, disY = 300, num = 3, py = 150;3// 位置14const originX = 303, originY = 814;5// 触发位置6const touchPoints = [[663, 1752], [820, 1700], [972, 1630]]7setInterval(() => {8  for(let i = 0; i < num; i++) {9    for(let j = 0; j < num; j++) {10      let targetY = originY + (j * disY);11      for(let z = 0; z < num; z++) {12        const targetX = originX + (z * disX);13        targetY = targetY - (z * py);14        exec(`adb shell input swipe ${touchPoints[i][0]} ${touchPoints[i][1]} ${targetX} ${targetY}`);15        exec(`sleep 0.01`);16      }17    }18  }19}, 1000)20// 开始点击位置21// for(let i = 0; i < num; i++) {22//   exec(`adb shell sendevent /dev/input/event0 3 0 ${touchPoints[i][0]}`);23//   exec(`adb shell sendevent /dev/input/event0 3 1 ${touchPoints[i][1]}`);24//   exec(`adb shell sendevent /dev/input/event0 1 330 1`);25//   exec(`adb shell sendevent /dev/input/event0 0 0 0`);26//   for(let j = 0; j < num; j++) {27//     let targetY = originY + (j * disY);28//     for(let z = 0; z < num; z++) {29//       const targetX = originX + (z * disX);30//       targetY = targetY - (z * py);31//       exec(`adb shell sendevent /dev/input/event0 3 0 ${targetX}`);32//       exec(`adb shell sendevent /dev/input/event0 0 0 0`);33//       exec(`adb shell sendevent /dev/input/event0 3 1 ${targetY}`);34//       exec(`adb shell sendevent /dev/input/event0 0 0 0`);35//     }36//   }37//   exec(`adb shell sendevent /dev/input/event0 1 330 0`);38//   exec(`adb shell sendevent /dev/input/event0 0 0 0`);...

Full Screen

Full Screen

guanaitong.js

Source:guanaitong.js Github

copy

Full Screen

1/*2 * @Author: maoguijun3 * @Date: 2021-08-26 19:07:434 * @LastEditors: maoguijun5 * @LastEditTime: 2021-08-26 21:56:446 * @FilePath: \guanaitongdaka\customer\guanaitong.js7 */8'use strict';9const shell = require('shelljs');1011const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));1213const start = async () => {14  console.log(13, 222222);15  // // 取屏幕的分辨率16  const st = shell.exec('adb shell wm size');17  const reg = /(\d+)x(\d+)/gi;18  reg.test(st);19  const width = RegExp.$1;20  const height = RegExp.$2;2122  // 打开关爱通23  shell.exec(24    'adb shell am start -n com.guanaitong/com.guanaitong.launch.activity.WelcomeActivity'25  );26  await sleep(5000);2728  // 点击我的29  shell.exec(`adb shell input tap ${width - 130} ${height - 90}`);30  await sleep(1000);3132  // 滑到底部33  shell.exec('adb shell input swipe 0 2000 0 0');34  await sleep(1000);3536  // 点击 奋斗食代37  shell.exec(`adb shell input tap 166 ${height - 840}`);38  await sleep(1000);3940  // 点击 领取41  shell.exec(`adb shell input tap 800 ${height - 540}`);42  await sleep(2000);43  // 关闭关爱通44  shell.exec(45    'adb shell am force-stop com.guanaitong'46  );47};48
...

Full Screen

Full Screen

android_utils.js

Source:android_utils.js Github

copy

Full Screen

1import { exec } from 'shell-utils'2const pressBack = () => exec.execSync('adb shell input keyevent 4')3const pressMenu = () => exec.execSync('adb shell input keyevent 82')4const pressEnter = keyCode => exec.execSync(`adb shell input keyevent 66`)5const pressLockButton = () => exec.execSync(`adb shell input keyevent 26`)6const pressKeyCode = keyCode => exec.execSync(`adb shell input keyevent ${keyCode}`)7const grantPermission = () =>8    exec.execSync('adb shell pm grant com.mentalhealth android.permission.READ_PHONE_STATE')9const revokePermission = () =>10    exec.execSync('adb shell pm revoke com.mentalhealth android.permission.READ_PHONE_STATE')11const openActivity = () => exec.execSync('adb shell am start -n com.mentalhealth/.MainActivity')12const executeShellCommand = command => exec.execSync(`adb shell ${command}`)13const enterText = text => exec.execSync(`adb shell input text ${text}`)14const swipeUp = () => exec.execSync('adb shell input touchscreen swipe 300 1200 500 0 100')15export {16    pressBack,17    pressMenu,18    pressEnter,19    pressLockButton,20    pressKeyCode,21    grantPermission,22    revokePermission,23    openActivity,24    executeShellCommand,25    enterText,26    swipeUp,...

Full Screen

Full Screen

AndroidUtils.js

Source:AndroidUtils.js Github

copy

Full Screen

1const exec = require('shell-utils').exec;2module.exports = {3  pressBack: () => {4    exec.execSync('adb shell input keyevent 4');5  },6  pressMenu: () => {7    exec.execSync('adb shell input keyevent 82');8  },9  pressKeyCode: (keyCode) => {10    exec.execSync(`adb shell input keyevent ${keyCode}`);11  },12  grantPermission: () => {13    exec.execSync('adb shell pm grant com.reactnativenavigation.playground android.permission.READ_PHONE_STATE');14  },15  revokePermission: () => {16    exec.execSync('adb shell pm revoke com.reactnativenavigation.playground android.permission.READ_PHONE_STATE');17  },18  openActivity: () => {19    exec.execSync('adb shell am start -n com.reactnativenavigation.playground/.MainActivity');20  },21  executeShellCommand: (command) => {22    exec.execSync(`adb shell ${command}`);23  }...

Full Screen

Full Screen

Api.js

Source:Api.js Github

copy

Full Screen

1export const GRAPHQLURL = "https://hrmfinance.com";2export const GRAPHQLURL45 = "http://localhost:8080";3//  2176036274/*5adb -s 4234355442593098 install Amazon_Flex.apk6adb shell pm list packages7// com.amazon.rabbit8adb shell monkey -p com.amazon.rabbit -c android.intent.category.LAUNCHER 19adb shell am force-stop com.amazon.rabbit10adb shell am kill com.amazon.rabbit11adb shell pm disable com.my.app.package...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var options = {3    desiredCapabilities: {4    }5};6var client = webdriverio.remote(options);7    .init()8    .shell('am start -n com.package.name/com.package.name.MainActivity')9    .end();10var adb = require('adbkit');11var client = adb.createClient();12client.shell('emulator-5554', 'am start -n com.package.name/com.package.name.MainActivity')13    .then(adb.util.readAll)14    .then(function(output) {15        console.log('[%s] %s', 'emulator-5554', output.toString().trim());16    })17    .catch(function(err) {18        console.error('Something went wrong:', err.stack);19    });

Full Screen

Using AI Code Generation

copy

Full Screen

1var adb = require('adbkit');2var client = adb.createClient();3client.shell('emulator-5554', 'ls')4    .then(adb.util.readAll)5    .then(function(output) {6        console.log('[%s] %s', 'emulator-5554', output.toString().trim());7    })8    .catch(function(err) {9        console.error('Something went wrong:', err.stack);10    });11client.exec('emulator-5554', 'ls')12    .then(function(transfer) {13        return new Promise(function(resolve, reject) {14            transfer.on('progress', function(stats) {15                console.log('[%s] Pushed %d bytes so far',16                    'emulator-5554', stats.bytesTransferred);17            });18            transfer.on('end', function() {19                console.log('[%s] Push complete', 'emulator-5554');20                resolve();21            });22            transfer.on('error', reject);23        });24    })25    .catch(function(err) {26        console.error('Something went wrong:', err.stack);27    });

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2}).build();3driver.execute("mobile: shell", {command: "ls -l", args: []}, function(err, res) {4    console.log(res);5});6driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1var adb = require('adbkit');2var client = adb.createClient();3client.shell('emulator-5554', 'ls /sdcard/').then(adb.util.readAll)4  .then(function(output) {5    console.log('[%s] %s', 'emulator-5554', output.toString().trim());6  });7var adb = require('adbkit');8var client = adb.createClient();9client.shell('emulator-5554', 'ls /sdcard/').then(adb.util.readAll)10  .then(function(output) {11    console.log('[%s] %s', 'emulator-5554', output.toString().trim());12  });13var adb = require('adbkit');14var client = adb.createClient();15client.shell('emulator-5554', 'ls /sdcard/').then(adb.util.readAll)16  .then(function(output) {17    console.log('[%s] %s', 'emulator-5554', output.toString().trim());18  });19var adb = require('adbkit');20var client = adb.createClient();21client.shell('emulator-5554', 'ls /sdcard/').then(adb.util.readAll)22  .then(function(output) {23    console.log('[%s] %s', 'emulator-5554', output.toString().trim());24  });25var adb = require('adbkit');26var client = adb.createClient();27client.shell('emulator-5554', 'ls /sdcard/').then(adb.util.readAll)28  .then(function(output) {29    console.log('[

Full Screen

Using AI Code Generation

copy

Full Screen

1var adb = require("adbkit");2var client = adb.createClient();3client.shell("emulator-5554", "ls /sdcard/Pictures/").then(adb.util.readAll).then(function(output) {4    console.log("[ADB] " + output.toString().trim());5});6var adb = require("adbkit");7var client = adb.createClient();8client.shell("emulator-5554", "ls /sdcard/Pictures/").then(adb.util.readAll).then(function(output) {9    console.log("[ADB] " + output.toString().trim());10});11var adb = require("adbkit");12var client = adb.createClient();13client.shell("emulator-5554", "ls /sdcard/Pictures/").then(adb.util.readAll).then(function(output) {14    console.log("[ADB] " + output.toString().trim());15});16var adb = require("adbkit");17var client = adb.createClient();18client.shell("emulator-5554", "ls /sdcard/Pictures/").then(adb.util.readAll).then(function(output) {19    console.log("[ADB] " + output.toString().trim());20});21var adb = require("adbkit");22var client = adb.createClient();23client.shell("emulator-5554", "ls /sdcard/Pictures/").then(adb.util.readAll).then(function(output) {24    console.log("[ADB] " + output.toString().trim());25});26var adb = require("adbkit");27var client = adb.createClient();28client.shell("emulator-5554", "ls /sdcard/Pictures/").then(adb.util.readAll).then(function(output) {29    console.log("[ADB] " + output.toString().trim());30});31var adb = require("adbkit");32var client = adb.createClient();33client.shell("emulator-5554", "ls /sdcard/P

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var desired = {4};5driver.init(desired).then(function(){6  driver.sleep(20000);7  driver.adb("shell", "input", "keyevent", "KEYCODE_MENU");8  driver.sleep(5000);9  driver.adb("shell", "input", "keyevent", "KEYCODE_DPAD_DOWN");10  driver.sleep(5000);11  driver.adb("shell", "input", "keyevent", "KEYCODE_DPAD_DOWN");12  driver.sleep(5000);13  driver.adb("shell", "input", "keyevent", "KEYCODE_DPAD_DOWN");14  driver.sleep(5000);15  driver.adb("shell", "input", "keyevent", "KEYCODE_DPAD_DOWN");16  driver.sleep(5000);17  driver.adb("shell", "input", "keyevent", "KEYCODE_DPAD_DOWN");18  driver.sleep(5000);19  driver.adb("shell", "input", "keyevent", "KEYCODE_DPAD_DOWN");20  driver.sleep(5000);21  driver.adb("shell", "input", "keyevent", "KEYCODE_DPAD_DOWN");22  driver.sleep(5000);23  driver.adb("shell", "input", "keyevent", "KEYCODE_DPAD_DOWN");24  driver.sleep(5000);25  driver.adb("shell", "input", "keyevent", "KEYCODE_DPAD_DOWN");26  driver.sleep(5000);27  driver.adb("shell", "input", "keyevent", "KEYCODE_DPAD_DOWN");28  driver.sleep(5000);29  driver.adb("shell", "input", "keyevent", "KEYCODE_DPAD_DOWN");30  driver.sleep(5000);31  driver.adb("shell", "input", "keyevent", "KEYCODE_DPAD_DOWN");

Full Screen

Using AI Code Generation

copy

Full Screen

1var adbShell = driver.adb.shell('ls /sdcard');2var fs = require('fs');3var path = require('path');4var adbShell = driver.adb.shell('ls /sdcard');5var filePath = path.resolve(__dirname, 'test.txt');6fs.writeFileSync(filePath, adbShell);

Full Screen

Using AI Code Generation

copy

Full Screen

1var activityName = driver.adb.shell(['dumpsys', 'window', 'w'])2.then(function (stdout) {3  var currentActivity = new RegExp(/mFocusedApp.+Record\{.+ (.+) \}/)4    .exec(stdout)[1];5    return currentActivity;6});7var activityName = driver.adb.shell(['dumpsys', 'window', 'w'])8.then(function (stdout) {9  var currentActivity = new RegExp(/mFocusedApp.+Record\{.+ (.+) \}/)10    .exec(stdout)[1];11    return currentActivity;12});13var activityName = driver.adb.shell(['dumpsys', 'window', 'w'])14.then(function (stdout) {15  var currentActivity = new RegExp(/mFocusedApp.+Record\{.+ (.+) \}/)16    .exec(stdout)[1];17    return currentActivity;18});19var activityName = driver.adb.shell(['dumpsys', 'window', 'w'])20.then(function (stdout) {21  var currentActivity = new RegExp(/mFocusedApp.+Record\{.+ (.+) \}/)22    .exec(stdout)[1];23    return currentActivity;24});25var activityName = driver.adb.shell(['dumpsys', 'window', 'w'])26.then(function (stdout) {27  var currentActivity = new RegExp(/mFocusedApp.+Record\{.+ (.+) \}/)28    .exec(stdout)[1];29    return currentActivity;30});31var activityName = driver.adb.shell(['dumpsys', 'window', 'w'])32.then(function (stdout) {33  var currentActivity = new RegExp(/mFocusedApp.+Record\{.+ (.+) \}/)34    .exec(stdout)[1];35    return currentActivity;36});37var activityName = driver.adb.shell(['dumpsys', 'window', 'w'])38.then(function (stdout) {39  var currentActivity = new RegExp(/mFocusedApp.+Record\{.+ (.+) \}/)40    .exec(stdout)[1];41    return currentActivity;42});43var activityName = driver.adb.shell(['dumpsys', 'window', 'w'])44.then(function (stdout) {

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