How to use this.bootstrap.sendAction method in Appium Android Driver

Best JavaScript code snippet using appium-android-driver

actions.js

Source:actions.js Github

copy

Full Screen

...18 log.warn("keyevent will be deprecated use pressKeyCode");19 return await this.pressKeyCode(keycode, metastate);20};21commands.pressKeyCode = async function (keycode, metastate = null) {22 return await this.bootstrap.sendAction("pressKeyCode", {keycode, metastate});23};24commands.longPressKeyCode = async function (keycode, metastate = null) {25 return await this.bootstrap.sendAction("longPressKeyCode", {keycode, metastate});26};27commands.getOrientation = async function () {28 let params = {29 naturalOrientation: !!this.opts.androidNaturalOrientation,30 };31 let orientation = await this.bootstrap.sendAction("orientation", params);32 return orientation.toUpperCase();33};34commands.setOrientation = async function (orientation) {35 orientation = orientation.toUpperCase();36 let params = {37 orientation,38 naturalOrientation: !!this.opts.androidNaturalOrientation,39 };40 return await this.bootstrap.sendAction("orientation", params);41};42commands.fakeFlick = async function (xSpeed, ySpeed) {43 return await this.bootstrap.sendAction('flick', {xSpeed, ySpeed});44};45commands.fakeFlickElement = async function (elementId, xoffset, yoffset, speed) {46 let params = {xoffset, yoffset, speed, elementId};47 return await this.bootstrap.sendAction('element:flick', params);48};49commands.swipe = async function (startX, startY, endX, endY, duration, touchCount, elId) {50 if (startX === 'null') {51 startX = 0.5;52 }53 if (startY === 'null') {54 startY = 0.5;55 }56 let swipeOpts = {startX, startY, endX, endY,57 steps: Math.round(duration * swipeStepsPerSec)};58 // going the long way and checking for undefined and null since59 // we can't be assured `elId` is a string and not an int60 if (util.hasValue(elId)) {61 swipeOpts.elementId = elId;62 }63 return await this.doSwipe(swipeOpts);64};65commands.doSwipe = async function (swipeOpts) {66 if (util.hasValue(swipeOpts.elementId)) {67 return await this.bootstrap.sendAction("element:swipe", swipeOpts);68 } else {69 return await this.bootstrap.sendAction("swipe", swipeOpts);70 }71};72commands.pinchClose = async function (startX, startY, endX, endY, duration, percent, steps, elId) {73 let pinchOpts = {74 direction: 'in',75 elementId: elId,76 percent,77 steps78 };79 return await this.bootstrap.sendAction("element:pinch", pinchOpts);80};81commands.pinchOpen = async function (startX, startY, endX, endY, duration, percent, steps, elId) {82 let pinchOpts = {direction: 'out', elementId: elId, percent, steps};83 return await this.bootstrap.sendAction("element:pinch", pinchOpts);84};85commands.flick = async function (element, xSpeed, ySpeed, xOffset, yOffset, speed) {86 if (element) {87 await this.fakeFlickElement(element, xOffset, yOffset, speed);88 } else {89 await this.fakeFlick(xSpeed, ySpeed);90 }91};92commands.drag = async function (startX, startY, endX, endY, duration, touchCount, elementId, destElId) {93 let dragOpts = {94 elementId, destElId, startX, startY, endX, endY,95 steps: Math.round(duration * dragStepsPerSec)96 };97 return await this.doDrag(dragOpts);98};99commands.doDrag = async function (dragOpts) {100 if (util.hasValue(dragOpts.elementId)) {101 return await this.bootstrap.sendAction("element:drag", dragOpts);102 } else {103 return await this.bootstrap.sendAction("drag", dragOpts);104 }105};106commands.lock = async function () {107 return await this.adb.lock();108};109commands.isLocked = async function () {110 return await this.adb.isScreenLocked();111};112commands.unlock = async function (unlockCapabilities) {113 return await androidHelpers.unlock(this, this.adb, unlockCapabilities);114};115commands.openNotifications = async function () {116 return await this.bootstrap.sendAction("openNotification");117};118commands.setLocation = async function (latitude, longitude) {119 return await this.adb.sendTelnetCommand(`geo fix ${longitude} ${latitude}`);120};121function parseContainerPath (remotePath) {122 const match = CONTAINER_PATH_PATTERN.exec(remotePath);123 if (!match) {124 log.errorAndThrow(`It is expected that package identifier is separated from the relative path with a single slash. ` +125 `'${remotePath}' is given instead`);126 }127 return [match[1], path.posix.resolve(`/data/data/${match[1]}`, match[2])];128}129commands.pullFile = async function (remotePath) {130 if (remotePath.endsWith('/')) {...

Full Screen

Full Screen

touch.js

Source:touch.js Github

copy

Full Screen

...283 opts = {284 elementId,285 actions: states286 };287 return await this.bootstrap.sendAction('element:performMultiPointerGesture', opts);288 } else {289 opts = {290 actions: states291 };292 return await this.bootstrap.sendAction('performMultiPointerGesture', opts);293 }294};295Object.assign(extensions, commands, helpers);296export { commands, helpers };...

Full Screen

Full Screen

element.js

Source:element.js Github

copy

Full Screen

...7 let params = {8 attribute,9 elementId10 };11 return await this.bootstrap.sendAction("element:getAttribute", params);12};13commands.setAttribute = async function (attribute, value, elementId) {14 elementId = this.getAutomationId(elementId);15 let params = {16 attribute,17 value,18 elementId19 };20 return await this.bootstrap.sendAction("element:setAttribute", params);21};22commands.getLocation = async function (elementId) {23 elementId = this.getAutomationId(elementId);24 return await this.bootstrap.sendAction("element:location", { elementId });25};26commands.getLocationInView = async function (elementId) {27 return await this.getLocation(elementId);28};29commands.getLocationValueByElementId = async function (elementId) {30 return await this.getLocation(elementId);31};32commands.getText = async function (elementId) {33 elementId = this.getAutomationId(elementId);34 return await this.bootstrap.sendAction("element:getText", { elementId });35};36commands.elementEnabled = async function (elementId) {37 elementId = this.getAutomationId(elementId);38 return await this.bootstrap.sendAction("element:enabled", { elementId });39};40commands.elementDisplayed = async function (elementId) {41 elementId = this.getAutomationId(elementId);42 return await this.bootstrap.sendAction("element:displayed", { elementId });43};44commands.elementSelected = function () {45 log.info('elementSelected not supported');46 return false;47};48commands.getSize = async function (elementId) {49 elementId = this.getAutomationId(elementId);50 return await this.bootstrap.sendAction("element:size", { elementId });51};52commands.setValue = async function (keys, elementId) {53 let text = keys.join();54 elementId = this.getAutomationId(elementId);55 let params = {56 elementId,57 text,58 replace: false59 };60 return await this.bootstrap.sendAction("element:setText", params);61};62commands.setValueImmediate = async function (keys, elementId) {63 let text = _.isArray(keys) ? keys.join('') : keys;64 elementId = this.getAutomationId(elementId);65 let params = {66 elementId,67 text,68 replace: false69 };70 return await this.bootstrap.sendAction("element:setText", params);71};72commands.clear = async function (elementId) {73 elementId = this.getAutomationId(elementId);74 let params = {75 elementId,76 text: "",77 replace: true78 };79 return await this.bootstrap.sendAction("element:setText", params);80};81commands.replaceValue = async function (value, elementId) {82 elementId = this.getAutomationId(elementId);83 let params = {84 elementId,85 text: value,86 replace: true87 };88 return await this.bootstrap.sendAction("element:setText", params);89};90commands.click = async function (elementId, x = 0, y = 0) {91 if (x === this.sessionId) {92 x = 0;93 }94 if (y === this.sessionId) {95 y = 0;96 }97 if (elementId) {98 elementId = this.getAutomationId(elementId);99 } else {100 elementId = "";101 }102 let params = {103 elementId,104 x,105 y106 };107 return await this.bootstrap.sendAction("element:click", params);108};109commands.touchUp = async function (x = 1, y = 1, elementId = "") {110 if (elementId && elementId !== this.sessionId) {111 elementId = this.getAutomationId(elementId);112 } else {113 elementId = "";114 }115 let params = {116 elementId,117 x,118 y119 };120 return await this.bootstrap.sendAction("element:touchUp", params);121};122commands.touchDown = async function (x, y, elementId = "") {123 if (elementId && elementId !== this.sessionId) {124 elementId = this.getAutomationId(elementId);125 } else {126 elementId = "";127 }128 let params = {129 elementId,130 x,131 y132 };133 return await this.bootstrap.sendAction("element:touchDown", params);134};135commands.touchMove = async function (x, y, elementId = null) {136 if (elementId && elementId !== this.sessionId) {137 elementId = this.getAutomationId(elementId);138 } else {139 elementId = "";140 }141 let params = {142 elementId,143 x,144 y145 };146 return await this.bootstrap.sendAction("element:touchMove", params);147};148commands.touchLongClick = async function (elementId, x, y, duration) {149 await this.touchDown(x, y, elementId);150 await sleep(duration);151 return await this.touchUp(x, y, elementId);152};153commands.tap = async function (elementId, x = 0, y = 0, count = 1) {154 let result = true;155 let tapResult = false;156 for (let i = 0; i < count; i++) {157 tapResult = await this.click(elementId, x, y);158 if (!tapResult) {159 result = false;160 }...

Full Screen

Full Screen

action.js

Source:action.js Github

copy

Full Screen

...11 return await this.fakeFlick(xSpeed, ySpeed);12 }13};14commands.fakeFlick = async function (xSpeed, ySpeed) {15 return await this.bootstrap.sendAction('element:flick', { xSpeed, ySpeed });16};17commands.fakeFlickElement = async function (elementId, xoffset, yoffset, speed) {18 let steps = 1250.0 / speed + 1;19 let xStart = 1;20 let yStart = 1;21 if (elementId === this.sessionId) {22 elementId = null;23 }24 if (elementId) {25 let location = await this.getLocationValueByElementId(elementId);26 xStart = location[0];27 yStart = location[1];28 }29 let xEnd = xStart + xoffset;30 let yEnd = yStart + yoffset;31 let params = [xStart, yStart, xEnd, yEnd, steps];32 return await this.doSwipe(params);33};34commands.swipe = async function (startX, startY, endX, endY, duration) {35 if (startX === 'null') {36 startX = 1;37 }38 if (startY === 'null') {39 startY = 1;40 }41 let swipeOpts = [42 startX, startY, endX, endY,43 Math.round(duration * swipeStepsPerSec)44 ];45 return await this.doSwipe(swipeOpts);46};47commands.doSwipe = async function (swipeOpts) {48 return await this.bootstrap.sendAction("swipe", swipeOpts);49};50commands.pullFile = async function (remotePath) {51 const rootDir = path.resolve(__dirname, '..', '..');52 const filePath = path.resolve(rootDir, 'file');53 let localFile = filePath + '/appiumfile.tmp';54 await this.sdb.pull(remotePath, localFile);55 let data = await fs.readFile(localFile);56 let b64data = new Buffer(data).toString('base64');57 if (await fs.exists(localFile)) {58 await fs.unlink(localFile);59 }60 return b64data;61};62async function takeScreenShot (sdb) {...

Full Screen

Full Screen

general.js

Source:general.js Github

copy

Full Screen

...12 log.errorAndThrow(`Could not capture device date and time: ${err}`);13 }14};15commands.pressKeyCode = async function (key) {16 return await this.bootstrap.sendAction("pressKey", { key });17};18commands.releaseKeyCode = async function (key) {19 return await this.bootstrap.sendAction("releaseKey", { key });20};21commands.keys = async function (keys) {22 let text = _.isArray(keys) ? keys.join('') : keys;23 let params = {24 elementId: "",25 text,26 replace: false27 };28 return await this.bootstrap.sendAction("element:setText", params);29};30commands.sendKey = async function (key) {31 return await this.bootstrap.sendAction('sendKey', { key });32};33commands.pressHardwareKey = async function (key) {34 return await this.sendKey(key);35};36commands.back = async function () {37 return await this.sendKey("XF86Back");38};39commands.installApp = async function (tpk) {40 const rootDir = path.resolve(__dirname, '..', '..', '..');41 const tpkPath = path.resolve(rootDir, 'app');42 let fullPath = path.resolve(tpkPath, tpk);43 if (!(await fs.exists(fullPath))) {44 log.errorAndThrow(`Could not find app tpk at ${tpk}`);45 return false;...

Full Screen

Full Screen

find.js

Source:find.js Github

copy

Full Screen

...8 if (params.strategy === "name") {9 strategy = params.strategy;10 }11 let param = { "elementId": params.selector, strategy };12 let result = await this.bootstrap.sendAction('find', param);13 if (!_.isEmpty(result)) {14 result.forEach(function (element) {15 index++;16 elements[index] = element.ELEMENT;17 element.ELEMENT = `${index}`;18 });19 if (!params.multiple) {20 result = result[0];21 }22 }23 return result;24};25helpers.findElOrEls = async function (strategy, selector, mult, context = '') {26 this.validateLocatorStrategy(strategy);...

Full Screen

Full Screen

driver.js

Source:driver.js Github

copy

Full Screen

...19 }20 async executeCommand(cmd, ...args) {21 if (!Object.getOwnPropertyDescriptor(Object.getPrototypeOf(this), cmd)) {22 AuroraDriver.prototype[cmd] = async function() {23 return await this.bootstrap.sendAction(cmd, Array.from(arguments).slice(0, -1));24 };25 }26 return await super.executeCommand(cmd, ...args);27 }28 async startAppiumForAuroraSession () {29 this.bootstrap = new Bootstrap(this.opts);30 await this.bootstrap.start();31 }32 async deleteSession () {33 log.debug('Deleting AuroraDriver session');34 await this.bootstrap.shutDown();35 await super.deleteSession();36 }37 get driverData () {...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var bootstrap = require('appium-android-driver').bootstrap;2bootstrap.sendAction('action', 'data', function(err) {3 if (err) {4 console.log(err);5 }6});7var bootstrap = require('appium-ios-driver').bootstrap;8bootstrap.sendAction('action', 'data', function(err) {9 if (err) {10 console.log(err);11 }12});13var bootstrap = require('appium-windows-driver').bootstrap;14bootstrap.sendAction('action', 'data', function(err) {15 if (err) {16 console.log(err);17 }18});19var bootstrap = require('appium-mac-driver').bootstrap;20bootstrap.sendAction('action', 'data', function(err) {21 if (err) {22 console.log(err);23 }24});25var bootstrap = require('appium-youiengine-driver').bootstrap;26bootstrap.sendAction('action', 'data', function(err) {27 if (err) {28 console.log(err);29 }30});31var bootstrap = require('appium-espresso-driver').bootstrap;32bootstrap.sendAction('action', 'data', function(err) {33 if (err) {34 console.log(err);35 }36});37var bootstrap = require('appium-tizen-driver').bootstrap;38bootstrap.sendAction('action', 'data', function(err) {39 if (err) {40 console.log(err);41 }42});43var bootstrap = require('appium-webdriveragent-driver').bootstrap;44bootstrap.sendAction('action', 'data', function(err) {45 if (err) {46 console.log(err);47 }48});49var bootstrap = require('appium-xcuitest-driver').bootstrap;50bootstrap.sendAction('action', 'data', function(err) {51 if (err) {52 console.log(err);53 }54});

Full Screen

Using AI Code Generation

copy

Full Screen

1this.bootstrap.sendAction("action", {params}, function callback(err, data) {2 if(err) {3 console.log(err);4 } else {5 console.log(data);6 }7});

Full Screen

Using AI Code Generation

copy

Full Screen

1var action = new TouchAction(this.bootstrap);2action.tap({x: 100, y: 100})3this.bootstrap.sendAction("tap", action);4AndroidBootstrap.prototype.sendAction = function (action, params) {5 var data = {action: action, params: params};6 return this.sendCommand("action", data);7};8AndroidBootstrap.prototype.sendCommand = function (command, params) {9 var data = {cmd: command, params: params};10 return this.send(data);11};12AndroidBootstrap.prototype.send = function (data) {13 var d = q.defer();14 this.socketClient.send(JSON.stringify(data), function (err) {15 if (err) {16 d.reject(err);17 } else {18 d.resolve();19 }20 });21 return d.promise;22};23AndroidBootstrap.prototype.start = function (cb) {24 this.socketClient.connect(this.port, this.host, function () {25 logger.debug("Connected to bootstrap");26 cb();27 });28};29AndroidBootstrap.prototype.connect = function (port, host) {30 this.port = port;31 this.host = host;32 this.socketClient = net.connect({port: port, host: host});33 this.socketClient.on("error", function (err) {34 logger.error("Socket error: " + err.message);35 });36 this.socketClient.on("close", function () {37 logger.debug("Socket closed");38 });39};40AndroidBootstrap.prototype.createSocketClient = function () {41 return net.connect({port: this.port, host: this.host});42};

Full Screen

Using AI Code Generation

copy

Full Screen

1it('should work', function() {2 driver.bootstrap.sendAction('pressKeyCode', {keycode: 4});3});4exports.sendAction = function(action, params) {5 var data = {6 };7 return this.proxyCommand('/appium/bootstrap', 'POST', data);8};9Appium.prototype.sendAction = function(action, params) {10 var data = {11 };12 return this.proxyCommand('/appium/bootstrap', 'POST', data);13};14Bootstrap.prototype.sendAction = function(action, params) {15 var data = {16 };17 return this.proxyCommand('/appium/bootstrap', 'POST', data);18};19UiAutomator.prototype.sendAction = function(action, params) {20 var data = {21 };22 return this.proxyCommand('/appium/bootstrap', 'POST', data);23};24Appium.prototype.proxyCommand = function(url, method, data) {25 var data = {26 };27 return this.proxyCommand('/appium/proxy', 'POST', data);28};29Proxy.prototype.proxyCommand = function(url, method, data) {30 var data = {31 };32 return this.proxyCommand('/appium/proxy', 'POST', data);33};

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