How to use this.getNetworkConnection method in Appium Android Driver

Best JavaScript code snippet using appium-android-driver

commands.js

Source:commands.js Github

copy

Full Screen

1var fs = require("fs"),2 url = require('url'),3 path = require('path'),4 tmp = require('./tmp'),5 _ = require("./lodash"),6 mkdirp = require("mkdirp")7 async = require('async'),8 __slice = Array.prototype.slice,9 config = require('./config'),10 callbacks = require("./callbacks"),11 callbackWithData = callbacks.callbackWithData,12 simpleCallback = callbacks.simpleCallback,13 elementCallback = callbacks.elementCallback,14 elementsCallback = callbacks.elementsCallback,15 elementOrElementsCallback = callbacks.elementOrElementsCallback,16 utils = require("./utils"),17 findCallback = utils.findCallback,18 codeToString = utils.codeToString,19 deprecator = utils.deprecator,20 asserters = require("./asserters"),21 Asserter = asserters.Asserter;22var commands = {};23/**24 * init(desired, cb) -> cb(err, sessionID, capabilities)25 * Initialize the browser. capabilities return may be26 * absent, depending on driver.27 *28 * @jsonWire POST /session29 */30commands.init = function() {31 var args = __slice.call(arguments, 0);32 this._init.apply(this, args);33};34/**35 * status(cb) -> cb(err, status)36 *37 * @jsonWire GET /status38 */39commands.status = function() {40 var cb = findCallback(arguments);41 this._jsonWireCall({42 method: 'GET'43 , absPath: 'status'44 , cb: callbackWithData(cb, this)45 });46};47/**48 * sessions(cb) -> cb(err, sessions)49 *50 * @jsonWire GET /sessions51 */52commands.sessions = function() {53 var cb = findCallback(arguments);54 this._jsonWireCall({55 method: 'GET'56 , absPath: 'sessions'57 , cb: callbackWithData(cb, this)58 });59};60/**61 * Retrieves the current session id.62 * getSessionId(cb) -> cb(err, sessionId)63 * getSessionId()64 */65commands.getSessionId = function() {66 var cb = findCallback(arguments);67 if(cb) { cb(null, this.sessionID); }68 return this.sessionID;69};70commands.getSessionID = commands.getSessionId;71/**72 * execute(code, args, cb) -> cb(err, result)73 * execute(code, cb) -> cb(err, result)74 * args: script argument array (optional)75 *76 * @jsonWire POST /session/:sessionId/execute77 * @docOrder 178 */79commands.execute = function() {80 var fargs = utils.varargs(arguments);81 var cb = fargs.callback,82 code = fargs.all[0],83 args = fargs.all[1] || [];84 code = codeToString(code);85 this._jsonWireCall({86 method: 'POST'87 , relPath: '/execute'88 , cb: callbackWithData(cb, this)89 , data: {script: code, args: args}90 });91};92// script to be executed in browser93var safeExecuteJsScript =94 utils.inlineJs(fs.readFileSync( __dirname + "/../browser-scripts/safe-execute.js", 'utf8'));95/**96 * Safely execute script within an eval block, always returning:97 * safeExecute(code, args, cb) -> cb(err, result)98 * safeExecute(code, cb) -> cb(err, result)99 * args: script argument array (optional)100 *101 * @jsonWire POST /session/:sessionId/execute102 * @docOrder 2103 */104commands.safeExecute = function() {105 var fargs = utils.varargs(arguments);106 var cb = fargs.callback,107 code = fargs.all[0],108 args = fargs.all[1] || [];109 code = codeToString(code);110 this._jsonWireCall({111 method: 'POST'112 , relPath: '/execute'113 , cb: callbackWithData(cb, this)114 , data: {script: safeExecuteJsScript, args: [code, args]}115 });116};117/**118 * Evaluate expression (using execute):119 * eval(code, cb) -> cb(err, value)120 *121 * @jsonWire POST /session/:sessionId/execute122 */123(function() {124 // jshint evil: true125 commands.eval = function(code) {126 var cb = findCallback(arguments);127 code = codeToString(code);128 code = "return " + code + ";";129 commands.execute.apply(this, [code, function(err, res) {130 if(err) {return cb(err);}131 cb(null, res);132 }]);133 };134})();135/**136 * Safely evaluate expression, always returning (using safeExecute):137 * safeEval(code, cb) -> cb(err, value)138 *139 * @jsonWire POST /session/:sessionId/execute140 */141commands.safeEval = function(code) {142 var cb = findCallback(arguments);143 code = codeToString(code);144 commands.safeExecute.apply(this, [code, function(err, res) {145 if(err) {return cb(err);}146 cb(null, res);147 }]);148};149/**150 * executeAsync(code, args, cb) -> cb(err, result)151 * executeAsync(code, cb) -> cb(err, result)152 * args: script argument array (optional)153 *154 * @jsonWire POST /session/:sessionId/execute_async155 */156 commands.executeAsync = function() {157 var fargs = utils.varargs(arguments);158 var cb = fargs.callback,159 code = fargs.all[0],160 args = fargs.all[1] || [];161 code = codeToString(code);162 this._jsonWireCall({163 method: 'POST'164 , relPath: '/execute_async'165 , cb: callbackWithData(cb, this)166 , data: {script: code, args: args}167 });168};169// script to be executed in browser170var safeExecuteAsyncJsScript =171 utils.inlineJs(fs.readFileSync( __dirname + "/../browser-scripts/safe-execute-async.js", 'utf8'));172/**173 * Safely execute async script within an eval block, always returning:174 * safeExecuteAsync(code, args, cb) -> cb(err, result)175 * safeExecuteAsync(code, cb) -> cb(err, result)176 * args: script argument array (optional)177 *178 * @jsonWire POST /session/:sessionId/execute_async179 */180commands.safeExecuteAsync = function() {181 var fargs = utils.varargs(arguments);182 var cb = fargs.callback,183 code = fargs.all[0],184 args = fargs.all[1] || [];185 code = codeToString(code);186 this._jsonWireCall({187 method: 'POST'188 , relPath: '/execute_async'189 , cb: callbackWithData(cb, this)190 , data: {script: safeExecuteAsyncJsScript , args: [code, args]}191 });192};193/**194 * Alternate strategy to get session capabilities from server session list:195 * altSessionCapabilities(cb) -> cb(err, capabilities)196 *197 * @jsonWire GET /sessions198 */199commands.altSessionCapabilities = function() {200 var cb = findCallback(arguments);201 var _this = this;202 // looking for the current session203 commands.sessions.apply(this, [function(err, sessions) {204 if(err) {205 cb(err, sessions);206 } else {207 sessions = sessions.filter(function(session) {208 return session.id === _this.sessionID;209 });210 cb(null, sessions[0]? sessions[0].capabilities : 0);211 }212 }]);213};214/**215 * sessionCapabilities(cb) -> cb(err, capabilities)216 *217 * @jsonWire GET /session/:sessionId218 */219commands.sessionCapabilities = function() {220 var cb = findCallback(arguments);221 this._jsonWireCall({222 method: 'GET'223 // default url224 , cb: callbackWithData(cb, this)225 });226};227/**228 * Opens a new window (using Javascript window.open):229 * newWindow(url, name, cb) -> cb(err)230 * newWindow(url, cb) -> cb(err)231 * name: optional window name232 * Window can later be accessed by name with the window method,233 * or by getting the last handle returned by the windowHandles method.234 */235commands.newWindow = function() {236 var fargs = utils.varargs(arguments);237 var cb = fargs.callback,238 url = fargs.all[0],239 name = fargs.all[1];240 commands.execute.apply(241 this,242 [ "var url=arguments[0], name=arguments[1]; window.open(url, name);",243 [url,name] , cb]);244};245/**246 * close(cb) -> cb(err)247 *248 * @jsonWire DELETE /session/:sessionId/window249 */250commands.close = function() {251 var cb = findCallback(arguments);252 this._jsonWireCall({253 method: 'DELETE'254 , relPath: '/window'255 , cb: simpleCallback(cb)256 });257};258/**259 * currentContext(cb) -> cb(err)260 *261 * @jsonWire GET /session/:sessionId/context262 */263commands.currentContext = function() {264 var cb = findCallback(arguments);265 this._jsonWireCall({266 method: 'GET'267 , relPath: '/context'268 , cb: callbackWithData(cb, this)269 });270};271/**272 * context(contextRef, cb) -> cb(err, context)273 *274 * @jsonWire POST /session/:sessionId/context275 */276commands.context = function(contextRef) {277 var cb = findCallback(arguments);278 this._jsonWireCall({279 method: 'POST'280 , relPath: '/context'281 , cb: simpleCallback(cb)282 , data: { name: contextRef }283 });284};285/**286 * contexts(cb) -> cb(err, handle)287 *288 * @jsonWire GET /session/:sessionId/contexts289 */290commands.contexts = function() {291 var cb = findCallback(arguments);292 this._jsonWireCall({293 method: 'GET'294 , relPath: '/contexts'295 , cb: callbackWithData(cb, this)296 });297};298/**299 * window(name, cb) -> cb(err)300 *301 * @jsonWire POST /session/:sessionId/window302 */303commands.window = function(windowRef) {304 var cb = findCallback(arguments);305 this._jsonWireCall({306 method: 'POST'307 , relPath: '/window'308 , cb: simpleCallback(cb)309 , data: { name: windowRef }310 });311};312/**313 * frame(frameRef, cb) -> cb(err)314 *315 * @jsonWire POST /session/:sessionId/frame316 */317commands.frame = function(frameRef) {318 var cb = findCallback(arguments);319 // avoid using this, Webdriver seems very buggy320 // doesn't work at all with chromedriver321 if(typeof(frameRef) === 'function'){322 frameRef = null;323 }324 if(frameRef !== null && typeof(frameRef.value) !== "undefined"){325 // we have an element object326 frameRef = {ELEMENT: frameRef.value};327 }328 this._jsonWireCall({329 method: 'POST'330 , relPath: '/frame'331 , cb: simpleCallback(cb)332 , data: { id: frameRef }333 });334};335/**336 * windowName(cb) -> cb(err, name)337 */338commands.windowName = function() {339 var cb = findCallback(arguments);340 // jshint evil: true341 commands.eval.apply(this, ["window.name", cb]);342};343/**344 * windowHandle(cb) -> cb(err, handle)345 *346 * @jsonWire GET /session/:sessionId/window_handle347 */348commands.windowHandle = function() {349 var cb = findCallback(arguments);350 this._jsonWireCall({351 method: 'GET'352 , relPath: '/window_handle'353 , cb: callbackWithData(cb, this)354 });355};356/**357 * windowHandles(cb) -> cb(err, arrayOfHandles)358 *359 * @jsonWire GET /session/:sessionId/window_handles360 */361commands.windowHandles = function() {362 var cb = findCallback(arguments);363 this._jsonWireCall({364 method: 'GET'365 , relPath: '/window_handles'366 , cb: callbackWithData(cb, this)367 });368};369/**370 * getGeoLocation(cb) -> cb(err, geoLocationObj)371 *372 * @jsonWire GET /session/:sessionId/location373 */374commands.getGeoLocation = function() {375 var cb = findCallback(arguments);376 this._jsonWireCall({377 method: 'GET'378 , relPath: '/location'379 , cb: callbackWithData(cb, this)380 });381};382/**383 * setGeoLocation(lat, lon, alt, cb) -> cb(err)384 *385 * @jsonWire POST /session/:sessionId/location386 */387commands.setGeoLocation = function(lat, lon, alt) {388 var cb = findCallback(arguments);389 if(typeof(alt) === 'function'){390 alt = 0;391 }392 this._jsonWireCall({393 method: 'POST'394 , relPath: '/location'395 , cb: simpleCallback(cb)396 , data: {location :{latitude: lat, longitude: lon, altitude: alt }}397 });398};399/**400 * scroll(xOffset, yOffset, cb) -> cb(err)401 *402 * @jsonWire POST /session/:sessionId/touch/scroll403 */404commands.scroll = function(xOffset, yOffset) {405 var cb = findCallback(arguments);406 this._jsonWireCall({407 method: 'POST'408 , relPath: '/touch/scroll'409 , cb: simpleCallback(cb, this)410 , data: { xoffset: xOffset, yoffset: yOffset }411 });412};413/**414 * logTypes(cb) -> cb(err, arrayOfLogTypes)415 *416 * @jsonWire GET /session/:sessionId/log/types417 */418commands.logTypes = function() {419 var cb = findCallback(arguments);420 this._jsonWireCall({421 method: 'GET'422 , relPath: '/log/types'423 , cb: callbackWithData(cb, this)424 });425};426/**427 * log(logType, cb) -> cb(err, arrayOfLogs)428 *429 * @jsonWire POST /session/:sessionId/log430 */431commands.log = function(logType) {432 var cb = findCallback(arguments);433 this._jsonWireCall({434 method: 'POST'435 , relPath: '/log'436 , cb: callbackWithData(cb, this)437 , data: { type: logType }438 });439};440/**441 * quit(cb) -> cb(err)442 * Destroy the browser.443 *444 * @jsonWire DELETE /session/:sessionId445 */446commands.quit = function() {447 var cb = findCallback(arguments);448 this._jsonWireCall({449 method: 'DELETE'450 // default url451 , emit: {event: 'status', message: '\nEnding your web drivage..\n'}452 , cb: simpleCallback(cb)453 });454};455/**456 * get(url,cb) -> cb(err)457 * Get a new url.458 *459 * @jsonWire POST /session/:sessionId/url460 */461commands.get = function(_url) {462 if(this._httpConfig.baseUrl) {_url = url.resolve(this._httpConfig.baseUrl, _url); }463 var cb = findCallback(arguments);464 this._jsonWireCall({465 method: 'POST'466 , relPath: '/url'467 , data: {'url': _url}468 , cb: simpleCallback(cb)469 });470};471/**472 * refresh(cb) -> cb(err)473 *474 * @jsonWire POST /session/:sessionId/refresh475 */476commands.refresh = function() {477 var cb = findCallback(arguments);478 this._jsonWireCall({479 method: 'POST'480 , relPath: '/refresh'481 , cb: simpleCallback(cb)482 });483};484/**485 * maximize(handle, cb) -> cb(err)486 *487 * @jsonWire POST /session/:sessionId/window/:windowHandle/maximize488 */489commands.maximize = function(win) {490var cb = findCallback(arguments);491if (typeof win === 'function') {492 win = 'current';493}494this._jsonWireCall({495 method: 'POST'496 , relPath: '/window/'+ win + '/maximize'497 , cb: simpleCallback(cb)498 });499};500/**501 * windowSize(handle, width, height, cb) -> cb(err)502 *503 * @jsonWire POST /session/:sessionId/window/:windowHandle/size504 */505commands.windowSize = function(win, width, height) {506var cb = findCallback(arguments);507this._jsonWireCall({508 method: 'POST'509 , relPath: '/window/'+ win + '/size'510 , data: {'width':width, 'height':height}511 , cb: simpleCallback(cb)512 });513};514/**515 * getWindowSize(handle, cb) -> cb(err, size)516 * getWindowSize(cb) -> cb(err, size)517 * handle: window handle to get size (optional, default: 'current')518 *519 * @jsonWire GET /session/:sessionId/window/:windowHandle/size520 */521commands.getWindowSize = function() {522 var fargs = utils.varargs(arguments);523 var cb = fargs.callback,524 win = fargs.all[0] || 'current';525this._jsonWireCall({526 method: 'GET'527 , relPath: '/window/'+ win + '/size'528 , cb: callbackWithData(cb, this)529 });530};531/**532 * setWindowSize(width, height, handle, cb) -> cb(err)533 * setWindowSize(width, height, cb) -> cb(err)534 * width: width in pixels to set size to535 * height: height in pixels to set size to536 * handle: window handle to set size for (optional, default: 'current')537 * @jsonWire POST /session/:sessionId/window/:windowHandle/size538 */539commands.setWindowSize = function() {540 var fargs = utils.varargs(arguments);541 var cb = fargs.callback,542 width = fargs.all[0],543 height = fargs.all[1],544 win = fargs.all[2] || 'current';545this._jsonWireCall({546 method: 'POST'547 , relPath: '/window/'+ win + '/size'548 , cb: simpleCallback(cb)549 , data: {width: width, height: height}550 });551};552/**553 * getWindowPosition(handle, cb) -> cb(err, position)554 * getWindowPosition(cb) -> cb(err, position)555 * handle: window handle to get position (optional, default: 'current')556 *557 * @jsonWire GET /session/:sessionId/window/:windowHandle/position558 */559commands.getWindowPosition = function() {560 var fargs = utils.varargs(arguments);561 var cb = fargs.callback,562 win = fargs.all[0] || 'current';563 this._jsonWireCall({564 method: 'GET'565 , relPath: '/window/'+ win + '/position'566 , cb: callbackWithData(cb, this)567 });568};569/**570 * setWindowPosition(x, y, handle, cb) -> cb(err)571 * setWindowPosition(x, y, cb) -> cb(err)572 * x: the x-coordinate in pixels to set the window position573 * y: the y-coordinate in pixels to set the window position574 * handle: window handle to set position for (optional, default: 'current')575 * @jsonWire POST /session/:sessionId/window/:windowHandle/position576 */577commands.setWindowPosition = function() {578 var fargs = utils.varargs(arguments);579 var cb = fargs.callback,580 x = fargs.all[0],581 y = fargs.all[1],582 win = fargs.all[2] || 'current';583 this._jsonWireCall({584 method: 'POST'585 , relPath: '/window/'+ win + '/position'586 , cb: simpleCallback(cb)587 , data: {x: x, y: y}588 });589};590/**591 * forward(cb) -> cb(err)592 *593 * @jsonWire POST /session/:sessionId/forward594 */595commands.forward = function() {596 var cb = findCallback(arguments);597 this._jsonWireCall({598 method: 'POST'599 , relPath: '/forward'600 , cb: simpleCallback(cb)601 });602};603/**604 * back(cb) -> cb(err)605 *606 * @jsonWire POST /session/:sessionId/back607 */608commands.back = function() {609 var cb = findCallback(arguments);610 this._jsonWireCall({611 method: 'POST'612 , relPath: '/back'613 , cb: simpleCallback(cb)614 });615};616commands.setHttpTimeout = function() {617 deprecator.warn('setHttpTimeout',618 'setHttpTimeout/setHTTPInactivityTimeout has been deprecated, use configureHttp instead.');619 var fargs = utils.varargs(arguments);620 var cb = fargs.callback,621 ms = fargs.all[0];622 commands.configureHttp( {timeout: ms}, cb );623};624commands.setHTTPInactivityTimeout = commands.setHttpTimeout;625/**626 * configureHttp(opts)627 *628 * opts example:629 * {timeout:60000, retries: 3, 'retryDelay': 15, baseUrl='http://example.com/'}630 * more info in README.631 *632 */633commands.configureHttp = function() {634 var fargs = utils.varargs(arguments);635 var cb = fargs.callback,636 opts = fargs.all[0];637 config._configureHttp(this._httpConfig, opts);638 if(cb) { cb(null); }639};640/**641 * setImplicitWaitTimeout(ms, cb) -> cb(err)642 *643 * @jsonWire POST /session/:sessionId/timeouts/implicit_wait644 */645commands.setImplicitWaitTimeout = function(ms) {646 var cb = findCallback(arguments);647 this._jsonWireCall({648 method: 'POST'649 , relPath: '/timeouts/implicit_wait'650 , data: {ms: ms}651 , cb: simpleCallback(cb)652 });653};654// for backward compatibility655commands.setWaitTimeout = commands.setImplicitWaitTimeout;656/**657 * setAsyncScriptTimeout(ms, cb) -> cb(err)658 *659 * @jsonWire POST /session/:sessionId/timeouts/async_script660 */661commands.setAsyncScriptTimeout = function(ms) {662 var cb = findCallback(arguments);663 this._jsonWireCall({664 method: 'POST'665 , relPath: '/timeouts/async_script'666 , data: {ms: ms}667 , cb: simpleCallback(cb)668 });669};670/**671 * setPageLoadTimeout(ms, cb) -> cb(err)672 * (use setImplicitWaitTimeout and setAsyncScriptTimeout to set the other timeouts)673 *674 * @jsonWire POST /session/:sessionId/timeouts675 */676commands.setPageLoadTimeout = function(ms) {677 var cb = findCallback(arguments);678 this._jsonWireCall({679 method: 'POST'680 , relPath: '/timeouts'681 , data: {type: 'page load', ms: ms}682 , cb: simpleCallback(cb)683 });684};685/**686 * setCommandTimeout(ms, cb) -> cb(err)687 * (this is for Appium only)688 * @jsonWire POST /session/:sessionId/timeouts689 */690commands.setCommandTimeout = function(ms) {691 var cb = findCallback(arguments);692 this._jsonWireCall({693 method: 'POST'694 , relPath: '/timeouts'695 , data: {type: 'command', ms: ms}696 , cb: simpleCallback(cb)697 });698};699/**700 * element(using, value, cb) -> cb(err, element)701 *702 * @jsonWire POST /session/:sessionId/element703 */704commands.element = function(using, value) {705 var cb = findCallback(arguments);706 this._jsonWireCall({707 method: 'POST'708 , relPath: '/element'709 , data: {using: using, value: value}710 , cb: elementCallback(cb, this)711 });712};713/**714 * Retrieve an element avoiding not found exception and returning null instead:715 * elementOrNull(using, value, cb) -> cb(err, element)716 *717 * @jsonWire POST /session/:sessionId/elements718 * @docOrder 3719 */720commands.elementOrNull = function(using, value) {721 var cb = findCallback(arguments);722 commands.elements.apply(this, [using, value,723 function(err, elements) {724 if(!err) {725 if(elements.length>0) {cb(null,elements[0]);} else {cb(null,null);}726 } else {727 cb(err); }728 }729 ]);730};731/**732 * Retrieve an element avoiding not found exception and returning undefined instead:733 * elementIfExists(using, value, cb) -> cb(err, element)734 *735 * @jsonWire POST /session/:sessionId/elements736 * @docOrder 5737 */738commands.elementIfExists = function(using, value) {739 var cb = findCallback(arguments);740 commands.elements.apply(this, [using, value,741 function(err, elements) {742 if(!err) {743 if(elements.length>0) {cb(null,elements[0]);} else {cb(null);}744 } else {745 cb(err); }746 }747 ]);748};749/**750 * elements(using, value, cb) -> cb(err, elements)751 *752 * @jsonWire POST /session/:sessionId/elements753 * @docOrder 1754 */755commands.elements = function(using, value) {756 var cb = findCallback(arguments);757 this._jsonWireCall({758 method: 'POST'759 , relPath: '/elements'760 , data: {using: using, value: value}761 , cb: elementsCallback(cb, this)762 });763};764/**765 * Check if element exists:766 * hasElement(using, value, cb) -> cb(err, boolean)767 *768 * @jsonWire POST /session/:sessionId/elements769 * @docOrder 7770 */771commands.hasElement = function(using, value){772 var cb = findCallback(arguments);773 commands.elements.apply( this, [using, value, function(err, elements){774 if(!err) {775 cb(null, elements.length > 0 );776 } else {777 cb(err); }778 }]);779};780/**781 * waitFor(asserter, timeout, pollFreq, cb) -> cb(err, return_value)782 * timeout and pollFreq are optional (default 1000ms/200ms)783 * waitFor(opts, cb) -> cb(err)784 * opts with the following fields: timeout, pollFreq, asserter.785 * asserter like: function(browser , cb) -> cb(err, satisfied, return_value)786 */787commands.waitFor = function() {788 var cb = findCallback(arguments);789 var fargs = utils.varargs(arguments);790 var opts;791 // retrieving options792 if (typeof fargs.all[0] === 'object' && !(fargs.all[0] instanceof Asserter)) {793 opts = fargs.all[0];794 } else {795 opts = {796 asserter: fargs.all[0],797 timeout: fargs.all[1],798 pollFreq: fargs.all[2]799 };800 }801 const {802 MACACA_WD_CLIENT_WAITFOR_TIMEOUT,803 MACACA_WD_CLIENT_WAITFOR_POLL_FREQ,804 } = process.env;805 // default806 opts.timeout = opts.timeout || parseInt(MACACA_WD_CLIENT_WAITFOR_TIMEOUT, 10) || 10 * 1000;807 opts.pollFreq = opts.pollFreq || parseInt(MACACA_WD_CLIENT_WAITFOR_POLL_FREQ, 10) || 1000;808 if(!opts.asserter) {809 throw new Error('Missing asserter!');810 }811 var _this = this;812 var endTime = Date.now() + opts.timeout;813 var unpromisedAsserter = new Asserter(814 function(browser, cb) {815 var promise = opts.asserter.assert(browser, cb);816 if (promise && promise.then && typeof promise.then === 'function') {817 promise.then(818 function(res) { cb(null, true, res); },819 function(err) {820 if(err.retriable) { cb(null, false); }821 else { throw err; }822 }823 );824 }825 }826 );827 function poll(isFinalCheck){828 unpromisedAsserter.assert(_this, function(err, satisfied, value) {829 if(err) { return cb(err); }830 if(satisfied) {831 cb(null, value);832 } else {833 if(isFinalCheck) {834 cb(new Error("Condition wasn't satisfied!"));835 } else if(Date.now() > endTime){836 // trying one more time for safety837 setTimeout(poll.bind(null, true) , opts.pollFreq);838 } else {839 setTimeout(poll, opts.pollFreq);840 }841 }842 });843 }844 poll();845};846/**847 * waitForElement(using, value, asserter, timeout, pollFreq, cb) -> cb(err, el)848 * waitForElement(using, value, timeout, pollFreq, cb) -> cb(err, el)849 * timeout and pollFreq are optional (default 1000ms/200ms)850 * waitForElement(using, value, opts, cb) -> cb(err, el)851 * opts with the following fields: timeout, pollFreq, asserter.852 * asserter like: function(element , cb) -> cb(err, satisfied, el)853 */854commands.waitForElement = function() {855 var cb = findCallback(arguments);856 var fargs = utils.varargs(arguments);857 var using = fargs.all[0],858 value = fargs.all[1];859 var opts;860 // retrieving options861 if (typeof fargs.all[2] === 'object' && !(fargs.all[2] instanceof Asserter)) {862 opts = fargs.all[2];863 } else if(fargs.all[2] instanceof Asserter) {864 opts = {865 asserter: fargs.all[2],866 timeout: fargs.all[3],867 pollFreq: fargs.all[4]868 };869 } else {870 opts = {871 timeout: fargs.all[2],872 pollFreq: fargs.all[3]873 };874 }875 // default876 opts.asserter = opts.asserter || new Asserter(function(el, cb) { cb(null, true); });877 var unpromisedAsserter = new Asserter(878 function(el, cb) {879 var promise = opts.asserter.assert(el, cb);880 if(promise && promise.then && typeof promise.then === 'function'){881 promise.then(882 function() { cb(null, true); },883 function(err) {884 if(err.retriable) { cb(null, false); }885 else { throw err; }886 }887 );888 }889 }890 );891 var wrappedAsserter = new Asserter(892 function(browser, cb){893 browser.elements(using, value, function(err, els){894 if(err) { return cb(err); }895 var seq = [];896 var satisfiedEl;897 _(els).each(function(el) {898 seq.push(function(cb) {899 if(satisfiedEl) { return cb(); }900 unpromisedAsserter.assert(el, function(err, satisfied) {901 if(err) { return cb(err); }902 if(satisfied) { satisfiedEl = el; }903 cb(err);904 });905 });906 }).value();907 async.series(seq, function(err) {908 if(err) { return cb(err); }909 cb(err, !_.isUndefined(satisfiedEl) , satisfiedEl);910 });911 });912 }913 );914 commands.waitFor.apply(this,[915 {916 asserter: wrappedAsserter,917 timeout: opts.timeout,918 pollFreq: opts.pollFreq919 }, function(err, value) {920 if(err && err.message && err.message.match(/Condition/)) {921 cb(new Error("Element condition wasn't satisfied!"));922 } else {923 cb(err, value);924 }925 }]);926};927/**928 * waitForElements(using, value, asserter, timeout, pollFreq, cb) -> cb(err, els)929 * waitForElements(using, value, timeout, pollFreq, cb) -> cb(err, els)930 * timeout and pollFreq are optional (default 1000ms/200ms)931 * waitForElements(using, value, opts, cb) -> cb(err, els)932 * opts with the following fields: timeout, pollFreq, asserter.933 * asserter like: function(element , cb) -> cb(err, satisfied, el)934 */935commands.waitForElements = function(){936 var cb = findCallback(arguments);937 var fargs = utils.varargs(arguments);938 var using = fargs.all[0],939 value = fargs.all[1];940 var opts;941 // retrieving options942 if(typeof fargs.all[2] === 'object' && !(fargs.all[2] instanceof Asserter)){943 opts = fargs.all[2];944 } else if(fargs.all[2] instanceof Asserter) {945 opts = {946 asserter: fargs.all[2],947 timeout: fargs.all[3],948 pollFreq: fargs.all[4]949 };950 } else {951 opts = {952 timeout: fargs.all[2],953 pollFreq: fargs.all[3]954 };955 }956 // default957 opts.asserter = opts.asserter || new Asserter(function(el, cb) { cb(null, true); });958 var unpromisedAsserter = new Asserter(959 function(el, cb) {960 var promise = opts.asserter.assert(el, cb);961 if(promise && promise.then && typeof promise.then === 'function'){962 promise.then(963 function() { cb(null, true); },964 function(err) {965 if(err.retriable) { cb(null, false); }966 else { throw err; }967 }968 );969 }970 }971 );972 var wrappedAsserter = new Asserter(973 function(browser, cb){974 browser.elements(using, value, function(err, els){975 if(err) { return cb(err); }976 var seq = [];977 var satisfiedEls = [];978 _(els).each(function(el) {979 seq.push(function(cb) {980 unpromisedAsserter.assert(el, function(err, satisfied) {981 if(err) { return cb(err); }982 if(satisfied) { satisfiedEls.push(el); }983 cb(err);984 });985 });986 }).value();987 async.series(seq, function(err) {988 if(err) { return cb(err); }989 cb(err, satisfiedEls.length > 0 , satisfiedEls);990 });991 });992 }993 );994 commands.waitFor.apply(this,[995 {996 asserter: wrappedAsserter,997 timeout: opts.timeout,998 pollFreq: opts.pollFreq999 }, function(err, value) {1000 if(err && err.message && err.message.match(/Condition/)) {1001 cb(new Error("Element condition wasn't satisfied!"));1002 } else {1003 cb(err, value);1004 }1005 }]);1006};1007commands.waitForVisible = function(using, value, timeout, pollFreq) {1008 deprecator.warn('waitForVisible',1009 'waitForVisible has been deprecated, use waitForElement + isVisible asserter instead.');1010 var cb = findCallback(arguments);1011 commands.waitForElement.apply(this, [using, value, asserters.isVisible, timeout, pollFreq, function(err, isVisible) {1012 if(err && err.message && err.message.match(/Element condition wasn't satisfied!/)){1013 cb(new Error("Element didn't become visible"));1014 } else {1015 cb(err, isVisible);1016 }1017 }]);1018};1019/**1020 * takeScreenshot(cb) -> cb(err, screenshot)1021 *1022 * @jsonWire GET /session/:sessionId/screenshot1023 */1024commands.takeScreenshot = function() {1025 var cb = findCallback(arguments);1026 var params = arguments[0];1027 this._jsonWireCall({1028 method: 'GET'1029 , relPath: `/screenshot${url.format({ query: params })}`1030 , cb: callbackWithData(cb, this)1031 });1032};1033/**1034 * saveScreenshot(path, cb) -> cb(err, filePath)1035 *1036 * path maybe a full file path, a directory path (finishing with /),1037 * the screenshot name, or left blank (will create a file in the system temp dir).1038 */1039commands.saveScreenshot = function() {1040 var _this = this;1041 var cb = findCallback(arguments);1042 var fargs = utils.varargs(arguments);1043 var _path = fargs.all[0];1044 var _params = fargs.all[1];1045 var dir = process.env.CUSTOM_DIR || '';1046 function buildFilePath(_path, cb) {1047 if(!_path) { _path = tmp.tmpdir + '/'; }1048 if(_path.match(/.*\/$/)) {1049 tmp.tmpName( {template: 'screenshot-XXXXXX.png'}, function(err, fileName) {1050 if(err) { return cb(err); }1051 if(dir) { _path = dir + '/screenshot/'; }1052 mkdirp(_path, function(err) {1053 if(err) { return cb(err); }1054 cb(null, path.join(_path , fileName));1055 })1056 });1057 } else {1058 if(path.extname(_path) === '') { _path = _path + '.png'; }1059 if(dir) { _path = path.join(dir, 'screenshot', _path)}1060 cb(null, _path);1061 }1062 }1063 buildFilePath(_path, function(err, filePath) {1064 commands.takeScreenshot.apply(_this, [_params, function(err, base64Data) {1065 if(err) { return cb(err); }1066 require("fs").writeFile(filePath, base64Data, 'base64', function(err) {1067 if(err) { return cb(err); }1068 cb(null, filePath);1069 });1070 }]);1071 });1072};1073// adding all elementBy... , elementsBy... function1074var addMethodsForSuffix = function(type, singular, plural) {1075 if(singular){1076 /**1077 * elementByClassName(value, cb) -> cb(err, element)1078 * elementByCssSelector(value, cb) -> cb(err, element)1079 * elementById(value, cb) -> cb(err, element)1080 * elementByName(value, cb) -> cb(err, element)1081 * elementByLinkText(value, cb) -> cb(err, element)1082 * elementByPartialLinkText(value, cb) -> cb(err, element)1083 * elementByTagName(value, cb) -> cb(err, element)1084 * elementByXPath(value, cb) -> cb(err, element)1085 * elementByCss(value, cb) -> cb(err, element)1086 * elementByIosUIAutomation(value, cb) -> cb(err, element)1087 * elementByAndroidUIAutomator(value, cb) -> cb(err, element)1088 * elementByAccessibilityId(value, cb) -> cb(err, element)1089 *1090 * @jsonWire POST /session/:sessionId/element1091 */1092 commands['element' + utils.elFuncSuffix(type)] = function() {1093 var args = __slice.call(arguments, 0);1094 args.unshift(utils.elFuncFullType(type));1095 commands.element.apply(this, args);1096 };1097 /**1098 * elementByClassNameOrNull(value, cb) -> cb(err, element)1099 * elementByCssSelectorOrNull(value, cb) -> cb(err, element)1100 * elementByIdOrNull(value, cb) -> cb(err, element)1101 * elementByNameOrNull(value, cb) -> cb(err, element)1102 * elementByLinkTextOrNull(value, cb) -> cb(err, element)1103 * elementByPartialLinkTextOrNull(value, cb) -> cb(err, element)1104 * elementByTagNameOrNull(value, cb) -> cb(err, element)1105 * elementByXPathOrNull(value, cb) -> cb(err, element)1106 * elementByCssOrNull(value, cb) -> cb(err, element)1107 * elementByIosUIAutomationOrNull(value, cb) -> cb(err, element)1108 * elementByAndroidUIAutomatorOrNull(value, cb) -> cb(err, element)1109 * elementByAccessibilityIdOrNull(value, cb) -> cb(err, element)1110 *1111 * @jsonWire POST /session/:sessionId/elements1112 * @docOrder 41113 */1114 commands['element' + utils.elFuncSuffix(type)+ 'OrNull'] = function() {1115 var fargs = utils.varargs(arguments);1116 var cb = fargs.callback;1117 var args = fargs.all;1118 args.unshift(utils.elFuncFullType(type));1119 args.push(1120 function(err, elements) {1121 if(!err) {1122 if(elements.length>0) {cb(null,elements[0]);} else {cb(null,null);}1123 } else {1124 cb(err);1125 }1126 }1127 );1128 commands.elements.apply(this, args );1129 };1130 /**1131 * elementByClassNameIfExists(value, cb) -> cb(err, element)1132 * elementByCssSelectorIfExists(value, cb) -> cb(err, element)1133 * elementByIdIfExists(value, cb) -> cb(err, element)1134 * elementByNameIfExists(value, cb) -> cb(err, element)1135 * elementByLinkTextIfExists(value, cb) -> cb(err, element)1136 * elementByPartialLinkTextIfExists(value, cb) -> cb(err, element)1137 * elementByTagNameIfExists(value, cb) -> cb(err, element)1138 * elementByXPathIfExists(value, cb) -> cb(err, element)1139 * elementByCssIfExists(value, cb) -> cb(err, element)1140 * elementByIosUIAutomationIfExists(value, cb) -> cb(err, element)1141 * elementByAndroidUIAutomatorIfExists(value, cb) -> cb(err, element)1142 * elementByAccessibilityIdIfExists(value, cb) -> cb(err, element)1143 *1144 * @jsonWire POST /session/:sessionId/elements1145 * @docOrder 61146 */1147 commands['element' + utils.elFuncSuffix(type)+ 'IfExists'] = function() {1148 var fargs = utils.varargs(arguments);1149 var cb = fargs.callback;1150 var args = fargs.all;1151 args.unshift(utils.elFuncFullType(type));1152 args.push(1153 function(err, elements) {1154 if(!err) {1155 if(elements.length>0) {cb(null,elements[0]);} else {cb(null);}1156 } else {1157 cb(err); }1158 }1159 );1160 commands.elements.apply(this, args);1161 };1162 /**1163 * hasElementByClassName(value, cb) -> cb(err, boolean)1164 * hasElementByCssSelector(value, cb) -> cb(err, boolean)1165 * hasElementById(value, cb) -> cb(err, boolean)1166 * hasElementByName(value, cb) -> cb(err, boolean)1167 * hasElementByLinkText(value, cb) -> cb(err, boolean)1168 * hasElementByPartialLinkText(value, cb) -> cb(err, boolean)1169 * hasElementByTagName(value, cb) -> cb(err, boolean)1170 * hasElementByXPath(value, cb) -> cb(err, boolean)1171 * hasElementByCss(value, cb) -> cb(err, boolean)1172 * hasElementByIosUIAutomation(value, cb) -> cb(err, boolean)1173 * hasElementByAndroidUIAutomator(value, cb) -> cb(err, boolean)1174 * hasElementByAccessibilityId(value, cb) -> cb(err, boolean)1175 *1176 * @jsonWire POST /session/:sessionId/elements1177 * @docOrder 81178 */1179 commands['hasElement' + utils.elFuncSuffix(type)] = function() {1180 var args = __slice.call(arguments, 0);1181 args.unshift(utils.elFuncFullType(type));1182 commands.hasElement.apply(this, args);1183 };1184 /**1185 * waitForElementByClassName(value, asserter, timeout, pollFreq, cb) -> cb(err, el)1186 * waitForElementByCssSelector(value, asserter, timeout, pollFreq, cb) -> cb(err, el)1187 * waitForElementById(value, asserter, timeout, pollFreq, cb) -> cb(err, el)1188 * waitForElementByName(value, asserter, timeout, pollFreq, cb) -> cb(err, el)1189 * waitForElementByLinkText(value, asserter, timeout, pollFreq, cb) -> cb(err, el)1190 * waitForElementByPartialLinkText(value, asserter, timeout, pollFreq, cb) -> cb(err, el)1191 * waitForElementByTagName(value, asserter, timeout, pollFreq, cb) -> cb(err, el)1192 * waitForElementByXPath(value, asserter, timeout, pollFreq, cb) -> cb(err, el)1193 * waitForElementByCss(value, asserter, timeout, pollFreq, cb) -> cb(err, el)1194 * waitForElementByIosUIAutomation(value, asserter, timeout, pollFreq, cb) -> cb(err, el)1195 * waitForElementByAndroidUIAutomator(value, asserter, timeout, pollFreq, cb) -> cb(err, el)1196 * waitForElementByAccessibilityId(value, asserter, timeout, pollFreq, cb) -> cb(err, el)1197 * asserter, timeout, pollFreq are optional, opts may be passed instead,1198 * as in waitForElement.1199 */1200 commands['waitForElement' + utils.elFuncSuffix(type)] = function() {1201 var args = __slice.call(arguments, 0);1202 args.unshift(utils.elFuncFullType(type));1203 commands.waitForElement.apply(this, args);1204 };1205 /**1206 * waitForElementsByClassName(value, asserter, timeout, pollFreq, cb) -> cb(err, els)1207 * waitForElementsByCssSelector(value, asserter, timeout, pollFreq, cb) -> cb(err, els)1208 * waitForElementsById(value, asserter, timeout, pollFreq, cb) -> cb(err, els)1209 * waitForElementsByName(value, asserter, timeout, pollFreq, cb) -> cb(err, els)1210 * waitForElementsByLinkText(value, asserter, timeout, pollFreq, cb) -> cb(err, els)1211 * waitForElementsByPartialLinkText(value, asserter, timeout, pollFreq, cb) -> cb(err, els)1212 * waitForElementsByTagName(value, asserter, timeout, pollFreq, cb) -> cb(err, els)1213 * waitForElementsByXPath(value, asserter, timeout, pollFreq, cb) -> cb(err, els)1214 * waitForElementsByCss(value, asserter, timeout, pollFreq, cb) -> cb(err, els)1215 * waitForElementsByIosUIAutomation(value, asserter, timeout, pollFreq, cb) -> cb(err, el)1216 * waitForElementsByAndroidUIAutomator(value, asserter, timeout, pollFreq, cb) -> cb(err, el)1217 * waitForElementsByAccessibilityId(value, asserter, timeout, pollFreq, cb) -> cb(err, el)1218 * asserter, timeout, pollFreq are optional, opts may be passed instead,1219 * as in waitForElements.1220 */1221 commands['waitForElements' + utils.elFuncSuffix(type)] = function() {1222 var args = __slice.call(arguments, 0);1223 args.unshift(utils.elFuncFullType(type));1224 commands.waitForElements.apply(this, args);1225 };1226 commands['waitForVisible' + utils.elFuncSuffix(type)] = function() {1227 var args = __slice.call(arguments, 0);1228 args.unshift(utils.elFuncFullType(type));1229 commands.waitForVisible.apply(this, args);1230 };1231 /**1232 * elementsByClassName(value, cb) -> cb(err, elements)1233 * elementsByCssSelector(value, cb) -> cb(err, elements)1234 * elementsById(value, cb) -> cb(err, elements)1235 * elementsByName(value, cb) -> cb(err, elements)1236 * elementsByLinkText(value, cb) -> cb(err, elements)1237 * elementsByPartialLinkText(value, cb) -> cb(err, elements)1238 * elementsByTagName(value, cb) -> cb(err, elements)1239 * elementsByXPath(value, cb) -> cb(err, elements)1240 * elementsByCss(value, cb) -> cb(err, elements)1241 * elementsByIosUIAutomation(value, cb) -> cb(err, elements)1242 * elementsByAndroidUIAutomator(value, cb) -> cb(err, elements)1243 * elementsByAccessibilityId(value, cb) -> cb(err, elements)1244 *1245 * @jsonWire POST /session/:sessionId/elements1246 * @docOrder 21247 */1248 }1249 if(plural){1250 commands['elements' + utils.elFuncSuffix(type)] = function() {1251 var args = __slice.call(arguments, 0);1252 args.unshift(utils.elFuncFullType(type));1253 commands.elements.apply(this, args);1254 };1255 }1256};1257_.each(utils.elementFuncTypes, function(suffix) {1258 addMethodsForSuffix(suffix, true, true);1259});1260/**1261 * getTagName(element, cb) -> cb(err, name)1262 *1263 * @jsonWire GET /session/:sessionId/element/:id/name1264 */1265commands.getTagName = function(element) {1266 var cb = findCallback(arguments);1267 this._jsonWireCall({1268 method: 'GET'1269 , relPath: '/element/' + element + '/name'1270 , cb: callbackWithData(cb, this)1271 });1272};1273/**1274 * getAttribute(element, attrName, cb) -> cb(err, value)1275 *1276 * @jsonWire GET /session/:sessionId/element/:id/attribute/:name1277 * @docOrder 11278 */1279commands.getAttribute = function() {1280 var fargs = utils.varargs(arguments);1281 var cb = fargs.callback,1282 element = fargs.all[0],1283 attrName = fargs.all[1];1284 if(!element) { throw new Error('Missing element.'); }1285 if(!attrName) { throw new Error('Missing attribute name.'); }1286 this._jsonWireCall({1287 method: 'GET'1288 , relPath: '/element/' + element + '/attribute/' + attrName1289 , cb: callbackWithData(cb, this)1290 });1291};1292/**1293 * getProperty(element, propertyName, cb) -> cb(err, value)1294 *1295 * @jsonWire GET /session/:sessionId/element/:id/property/:name1296 * @docOrder 11297 */1298commands.getProperty = function() {1299 var fargs = utils.varargs(arguments);1300 var cb = fargs.callback,1301 element = fargs.all[0],1302 propertyName = fargs.all[1];1303 if(!element) { throw new Error('Missing element.'); }1304 if(!propertyName) { throw new Error('Missing property name.'); }1305 this._jsonWireCall({1306 method: 'GET'1307 , relPath: '/element/' + element + '/property/' + propertyName1308 , cb: callbackWithData(cb, this)1309 });1310};1311/**1312 * getRect(element, cb) -> cb(err, value)1313 *1314 * @jsonWire GET /session/:sessionId/element/:id/rect1315 * @docOrder 11316 */1317commands.getRect = function() {1318 var fargs = utils.varargs(arguments);1319 var cb = fargs.callback,1320 element = fargs.all[0];1321 if(!element) { throw new Error('Missing element.'); }1322 this._jsonWireCall({1323 method: 'GET'1324 , relPath: '/element/' + element + '/rect'1325 , cb: callbackWithData(cb, this)1326 });1327};1328/**1329 * isDisplayed(element, cb) -> cb(err, displayed)1330 *1331 * @jsonWire GET /session/:sessionId/element/:id/displayed1332 */1333commands.isDisplayed = function(element) {1334 var cb = findCallback(arguments);1335 this._jsonWireCall({1336 method: 'GET'1337 , relPath: '/element/' + element + '/displayed'1338 , cb: callbackWithData(cb, this)1339 });1340};1341commands.displayed = commands.isDisplayed;1342/**1343 * isEnabled(element, cb) -> cb(err, enabled)1344 *1345 * @jsonWire GET /session/:sessionId/element/:id/enabled1346 */1347commands.isEnabled = function(element) {1348 var cb = findCallback(arguments);1349 this._jsonWireCall({1350 method: 'GET'1351 , relPath: '/element/' + element + '/enabled'1352 , cb: callbackWithData(cb, this)1353 });1354};1355commands.enabled = commands.isEnabled;1356/**1357 * isSelected(element, cb) -> cb(err, selected)1358 *1359 * @jsonWire GET /session/:sessionId/element/:id/selected1360 */1361commands.isSelected = function(element) {1362 var cb = findCallback(arguments);1363 this._jsonWireCall({1364 method: 'GET'1365 , relPath: '/element/' + element + '/selected'1366 , cb: callbackWithData(cb, this)1367 });1368};1369// commands.selected = commands.isSelected;1370/**1371 * Get element value (in value attribute):1372 * getValue(element, cb) -> cb(err, value)1373 *1374 * @jsonWire GET /session/:sessionId/element/:id/attribute/:name1375 * @docOrder 31376 */1377commands.getValue = function() {1378 var fargs = utils.varargs(arguments);1379 var cb = fargs.callback,1380 element = fargs.all[0];1381 if(!element) { throw new Error('Missing element.'); }1382 commands.getAttribute.apply(this, [element, 'value', cb]);1383};1384/**1385 * clickElement(element, cb) -> cb(err)1386 *1387 * @jsonWire POST /session/:sessionId/element/:id/click1388 */1389commands.clickElement = function(element) {1390 var cb = findCallback(arguments);1391 this._jsonWireCall({1392 method: 'POST'1393 , relPath: '/element/' + element + '/click'1394 , cb: simpleCallback(cb)1395 });1396};1397/**1398 * getComputedCss(element, cssProperty , cb) -> cb(err, value)1399 *1400 * @jsonWire GET /session/:sessionId/element/:id/css/:propertyName1401 */1402commands.getComputedCss = function(element, cssProperty) {1403 var cb = findCallback(arguments);1404 this._jsonWireCall({1405 method: 'GET'1406 , relPath: '/element/' + element + '/css/' + cssProperty1407 , cb: callbackWithData(cb, this)1408 });1409};1410commands.getComputedCSS = commands.getComputedCss;1411/**1412 * equalsElement(element, other , cb) -> cb(err, value)1413 *1414 * @jsonWire GET /session/:sessionId/element/:id/equals/:other1415 */1416commands.equalsElement = function(element, other) {1417 var cb = findCallback(arguments);1418 this._jsonWireCall({1419 method: 'GET'1420 , relPath: '/element/' + element + '/equals/' + other1421 , cb: callbackWithData(cb, this)1422 });1423};1424var _flick1 = function(){1425 var fargs = utils.varargs(arguments);1426 var cb = fargs.callback,1427 xspeed = fargs.all[0],1428 yspeed = fargs.all[1],1429 swipe = fargs.all[2];1430 var data = { xspeed: xspeed, yspeed: yspeed };1431 if (swipe) {1432 data.swipe = swipe;1433 }1434 this._jsonWireCall({1435 method: 'POST'1436 , relPath: '/touch/flick'1437 , data: data1438 , cb: simpleCallback(cb)1439 });1440};1441var _flick2 = function() {1442 var fargs = utils.varargs(arguments);1443 var cb = fargs.callback,1444 element = fargs.all[0],1445 xoffset = fargs.all[1],1446 yoffset = fargs.all[2],1447 speed = fargs.all[3];1448 this._jsonWireCall({1449 method: 'POST'1450 , relPath: '/touch/flick'1451 , data: { element: element, xoffset: xoffset, yoffset: yoffset, speed: speed }1452 , cb: simpleCallback(cb)1453 });1454};1455/**1456 * flick(xSpeed, ySpeed, swipe, cb) -> cb(err)1457 * Flicks, starting anywhere on the screen.1458 *1459 * flick(element, xoffset, yoffset, speed, cb) -> cb(err)1460 * Flicks, starting at element center.1461 *1462 * @jsonWire POST /session/:sessionId/touch/flick1463 */1464commands.flick = function() {1465 var args = __slice.call(arguments, 0);1466 if (args.length <= 4) {1467 _flick1.apply(this, args);1468 } else {1469 _flick2.apply(this, args);1470 }1471};1472/**1473 * tapElement(element) -> cb(err)1474 * Taps element1475 *1476 * @jsonWire POST /session/:sessionId/touch/click1477 */1478commands.tapElement = function(element, cb) {1479 this._jsonWireCall({1480 method: 'POST'1481 , relPath: '/touch/click'1482 , data: { element: element.value.toString() }1483 , cb: simpleCallback(cb)1484 });1485};1486/**1487 * performTouchAction(touchAction) -> cb(err)1488 *1489 * @jsonWire POST /session/:sessionId/touch/perform1490 */1491commands.performTouchAction = function () {1492 var _this = this;1493 var fargs = utils.varargs(arguments);1494 var cb = fargs.callback,1495 touchAction = fargs.all[0];1496 try {1497 _this._jsonWireCall({1498 method: 'POST',1499 relPath: '/touch/perform',1500 data: {actions: touchAction.toJSON()},1501 cb: callbackWithData(cb, this)1502 });1503 } catch (err) {1504 return cb(err);1505 }1506};1507/**1508 * performMultiAction(element, multiAction) -> cb(err, touchStateObjects)1509 * performMultiAction(multiAction) -> cb(err, touchStateObjects)1510 *1511 * @jsonWire POST /session/:sessionId/touch/multi/perform1512 */1513commands.performMultiAction = function () {1514 var _this = this;1515 var fargs = utils.varargs(arguments);1516 var cb = fargs.callback,1517 element = fargs.all[0],1518 multiTouchAction = fargs.all[1];1519 if(!multiTouchAction) {1520 multiTouchAction = element;1521 element = null;1522 }1523 element = element || multiTouchAction.element;1524 try {1525 var data = multiTouchAction.toJSON(element);1526 if(element) { data.elementId = element.value.toString(); }1527 _this._jsonWireCall({1528 method: 'POST',1529 relPath: '/touch/multi/perform',1530 data: data,1531 cb: callbackWithData(cb, this)1532 });1533 } catch (err) {1534 return cb(err);1535 }1536};1537/**1538 * moveTo(element, xoffset, yoffset, cb) -> cb(err)1539 * Move to element, element may be null, xoffset and y offset1540 * are optional.1541 *1542 * @jsonWire POST /session/:sessionId/moveto1543 */1544commands.moveTo = function() {1545 var fargs = utils.varargs(arguments);1546 var cb = fargs.callback,1547 element = fargs.all[0],1548 xoffset = fargs.all[1],1549 yoffset = fargs.all[2];1550 this._jsonWireCall({1551 method: 'POST'1552 , relPath: '/moveto'1553 , data: { element:1554 element? element.toString(): null,1555 xoffset: xoffset,1556 yoffset: yoffset }1557 , cb: simpleCallback(cb)1558 });1559};1560/**1561 * buttonDown(button ,cb) -> cb(err)1562 * button is optional.1563 * {LEFT = 0, MIDDLE = 1 , RIGHT = 2}.1564 * LEFT if not specified.1565 *1566 * @jsonWire POST /session/:sessionId/buttondown1567 */1568commands.buttonDown = function() {1569 var fargs = utils.varargs(arguments);1570 var cb = fargs.callback,1571 button = fargs.all[0];1572 this._jsonWireCall({1573 method: 'POST'1574 , relPath: '/buttondown'1575 , data: {button: button}1576 , cb: simpleCallback(cb)1577 });1578};1579/**1580 * buttonUp(button, cb) -> cb(err)1581 * button is optional.1582 * {LEFT = 0, MIDDLE = 1 , RIGHT = 2}.1583 * LEFT if not specified.1584 *1585 * @jsonWire POST /session/:sessionId/buttonup1586 */1587commands.buttonUp = function() {1588 var fargs = utils.varargs(arguments);1589 var cb = fargs.callback,1590 button = fargs.all[0];1591 this._jsonWireCall({1592 method: 'POST'1593 , relPath: '/buttonup'1594 , data: {button: button}1595 , cb: simpleCallback(cb)1596 });1597};1598/**1599 * click(button, cb) -> cb(err)1600 * Click on current element.1601 * Buttons: {left: 0, middle: 1 , right: 2}1602 *1603 * @jsonWire POST /session/:sessionId/click1604 */1605commands.click = function() {1606 // parsing args, button optional1607 var fargs = utils.varargs(arguments);1608 var cb = fargs.callback,1609 button = fargs.all[0];1610 this._jsonWireCall({1611 method: 'POST'1612 , relPath: '/click'1613 , data: {button: button}1614 , cb: simpleCallback(cb)1615 });1616};1617/**1618 * swipe(startX, startY, endX, endY, cb) -> cb(err)1619 *1620 * @jsonWire POST /session/:sessionId/element/:id/swipe1621 */1622commands.swipe = function() {1623 var fargs = utils.varargs(arguments);1624 var cb = fargs.callback,1625 startX = fargs.all[0],1626 startY = fargs.all[1],1627 endX = fargs.all[2],1628 endY = fargs.all[3],1629 duration = fargs.all[4];1630 this._jsonWireCall({1631 method: 'POST',1632 relPath: `/element/${startX}/swipe`,1633 data: {1634 startX: startX,1635 startY: startY,1636 endX: endX,1637 endY: endY,1638 duration: duration1639 },1640 cb: simpleCallback(cb)1641 });1642};1643/**1644 * doubleclick(cb) -> cb(err)1645 *1646 * @jsonWire POST /session/:sessionId/doubleclick1647 */1648commands.doubleclick = function() {1649 var cb = findCallback(arguments);1650 this._jsonWireCall({1651 method: 'POST'1652 , relPath: '/doubleclick'1653 , cb: simpleCallback(cb)1654 });1655};1656/**1657 * type(element, keys, cb) -> cb(err)1658 * Type keys (all keys are up at the end of command).1659 * special key map: wd.SPECIAL_KEYS (see lib/special-keys.js)1660 *1661 * @jsonWire POST /session/:sessionId/element/:id/value1662 */1663commands.type = function(element, keys) {1664 var cb = findCallback(arguments);1665 if (!(keys instanceof Array)) {keys = [keys];}1666 // ensure all keystrokes are strings to conform to JSONWP1667 _.each(keys, function(key, idx) {1668 if (typeof key !== "string") {1669 keys[idx] = key.toString();1670 }1671 });1672 this._jsonWireCall({1673 method: 'POST'1674 , relPath: '/element/' + element + '/value'1675 , data: {value: keys}1676 , cb: simpleCallback(cb)1677 });1678};1679commands.replace = function(element, keys) {1680 var cb = findCallback(arguments);1681 if (!(keys instanceof Array)) {keys = [keys];}1682 // ensure all keystrokes are strings to conform to JSONWP1683 _.each(keys, function(key, idx) {1684 if (typeof key !== "string") {1685 keys[idx] = key.toString();1686 }1687 });1688 this._jsonWireCall({1689 method: 'POST'1690 , relPath: '/appium/element/' + element + '/replace_value'1691 , data: {value: keys}1692 , cb: simpleCallback(cb)1693 });1694};1695/**1696 * submit(element, cb) -> cb(err)1697 * Submit a `FORM` element.1698 *1699 * @jsonWire POST /session/:sessionId/element/:id/submit1700 */1701commands.submit = function(element) {1702 var cb = findCallback(arguments);1703 this._jsonWireCall({1704 method: 'POST'1705 , relPath: '/element/' + element + '/submit'1706 , cb: simpleCallback(cb)1707 });1708};1709/**1710 * keys(keys, cb) -> cb(err)1711 * Press keys (keys may still be down at the end of command).1712 * special key map: wd.SPECIAL_KEYS (see lib/special-keys.js)1713 *1714 * @jsonWire POST /session/:sessionId/keys1715 */1716commands.keys = function(keys) {1717 var cb = findCallback(arguments);1718 if (!(keys instanceof Array)) {keys = [keys];}1719 // ensure all keystrokes are strings to conform to JSONWP1720 _.each(keys, function(key, idx) {1721 if (typeof key !== "string") {1722 keys[idx] = key.toString();1723 }1724 });1725 this._jsonWireCall({1726 method: 'POST'1727 , relPath: '/keys'1728 , data: {value: keys}1729 , cb: simpleCallback(cb)1730 });1731};1732/**1733 * clear(element, cb) -> cb(err)1734 *1735 * @jsonWire POST /session/:sessionId/element/:id/clear1736 */1737commands.clear = function(element) {1738 var cb = findCallback(arguments);1739 this._jsonWireCall({1740 method: 'POST'1741 , relPath: '/element/' + element + '/clear'1742 , cb: simpleCallback(cb)1743 });1744};1745/**1746 * title(cb) -> cb(err, title)1747 *1748 * @jsonWire GET /session/:sessionId/title1749 */1750commands.title = function() {1751 var cb = findCallback(arguments);1752 this._jsonWireCall({1753 method: 'GET'1754 , relPath: '/title'1755 , cb: callbackWithData(cb, this)1756 });1757};1758/**1759 * source(cb) -> cb(err, source)1760 *1761 * @jsonWire GET /session/:sessionId/source1762 */1763commands.source = function() {1764 var cb = findCallback(arguments);1765 this._jsonWireCall({1766 method: 'GET'1767 , relPath: '/source'1768 , cb: callbackWithData(cb, this)1769 });1770};1771// element must be specified1772var _rawText = function(element) {1773 var cb = findCallback(arguments);1774 this._jsonWireCall({1775 method: 'GET'1776 , relPath: '/element/' + element + '/text'1777 , cb: callbackWithData(cb, this)1778 });1779};1780/**1781 * text(element, cb) -> cb(err, text)1782 * element: specific element, 'body', or undefined1783 *1784 * @jsonWire GET /session/:sessionId/element/:id/text1785 * @docOrder 11786 */1787commands.text = function() {1788 var cb = findCallback(arguments);1789 var fargs = utils.varargs(arguments);1790 var element = fargs.all[0];1791 var _this = this;1792 if (!element || element === 'body') {1793 commands.element.apply(this, ['tag name', 'body', function(err, bodyEl) {1794 if (!err) {_rawText.apply(_this, [bodyEl, cb]);} else {cb(err);}1795 }]);1796 }else {1797 _rawText.apply(_this, [element, cb]);1798 }1799};1800/**1801 * Check if text is present:1802 * textPresent(searchText, element, cb) -> cb(err, boolean)1803 * element: specific element, 'body', or undefined1804 *1805 * @jsonWire GET /session/:sessionId/element/:id/text1806 * @docOrder 31807 */1808commands.textPresent = function(searchText, element) {1809 var cb = findCallback(arguments);1810 commands.text.apply(this, [element, function(err, text) {1811 if (err) {1812 cb(err, null);1813 } else {1814 cb(err, text.indexOf(searchText) >= 0);1815 }1816 }]);1817};1818/**1819 * alertText(cb) -> cb(err, text)1820 *1821 * @jsonWire GET /session/:sessionId/alert_text1822 */1823commands.alertText = function() {1824 var cb = findCallback(arguments);1825 this._jsonWireCall({1826 method: 'GET'1827 , relPath: '/alert_text'1828 , cb: callbackWithData(cb, this)1829 });1830};1831/**1832 * alertKeys(keys, cb) -> cb(err)1833 *1834 * @jsonWire POST /session/:sessionId/alert_text1835 */1836commands.alertKeys = function(keys) {1837 var cb = findCallback(arguments);1838 this._jsonWireCall({1839 method: 'POST'1840 , relPath: '/alert_text'1841 , data: {text: keys}1842 , cb: simpleCallback(cb)1843 });1844};1845/**1846 * acceptAlert(cb) -> cb(err)1847 *1848 * @jsonWire POST /session/:sessionId/accept_alert1849 */1850commands.acceptAlert = function() {1851 var cb = findCallback(arguments);1852 this._jsonWireCall({1853 method: 'POST'1854 , relPath: '/accept_alert'1855 , cb: simpleCallback(cb)1856 });1857};1858/**1859 * dismissAlert(cb) -> cb(err)1860 *1861 * @jsonWire POST /session/:sessionId/dismiss_alert1862 */1863commands.dismissAlert = function() {1864 var cb = findCallback(arguments);1865 this._jsonWireCall({1866 method: 'POST'1867 , relPath: '/dismiss_alert'1868 , cb: simpleCallback(cb)1869 });1870};1871/**1872 * active(cb) -> cb(err, element)1873 *1874 * @jsonWire POST /session/:sessionId/element/active1875 */1876commands.active = function() {1877 var cb = findCallback(arguments);1878 this._jsonWireCall({1879 method: 'POST'1880 , relPath: '/element/active'1881 , cb: callbackWithData(cb, this)1882 });1883};1884/**1885 * url(cb) -> cb(err, url)1886 *1887 * @jsonWire GET /session/:sessionId/url1888 */1889commands.url = function() {1890 var cb = findCallback(arguments);1891 this._jsonWireCall({1892 method: 'GET'1893 , relPath: '/url'1894 , cb: callbackWithData(cb, this)1895 });1896};1897/**1898 * allCookies() -> cb(err, cookies)1899 *1900 * @jsonWire GET /session/:sessionId/cookie1901 */1902commands.allCookies = function() {1903 var cb = findCallback(arguments);1904 this._jsonWireCall({1905 method: 'GET'1906 , relPath: '/cookie'1907 , cb: callbackWithData(cb, this)1908 });1909};1910/**1911 * setCookie(cookie, cb) -> cb(err)1912 * cookie example:1913 * {name:'fruit', value:'apple'}1914 * Optional cookie fields:1915 * path, domain, secure, expiry1916 *1917 * @jsonWire POST /session/:sessionId/cookie1918 */1919commands.setCookie = function(cookie) {1920 var cb = findCallback(arguments);1921 // setting secure otherwise selenium server throws1922 if(cookie){ cookie.secure = cookie.secure || false; }1923 this._jsonWireCall({1924 method: 'POST'1925 , relPath: '/cookie'1926 , data: { cookie: cookie }1927 , cb: simpleCallback(cb)1928 });1929};1930/**1931 * deleteAllCookies(cb) -> cb(err)1932 *1933 * @jsonWire DELETE /session/:sessionId/cookie1934 */1935commands.deleteAllCookies = function() {1936 var cb = findCallback(arguments);1937 this._jsonWireCall({1938 method: 'DELETE'1939 , relPath: '/cookie'1940 , cb: simpleCallback(cb)1941 });1942};1943/**1944 * deleteCookie(name, cb) -> cb(err)1945 *1946 * @jsonWire DELETE /session/:sessionId/cookie/:name1947 */1948commands.deleteCookie = function(name) {1949 var cb = findCallback(arguments);1950 this._jsonWireCall({1951 method: 'DELETE'1952 , relPath: '/cookie/' + encodeURIComponent(name)1953 , cb: simpleCallback(cb)1954 });1955};1956/**1957 * getOrientation(cb) -> cb(err, orientation)1958 *1959 * @jsonWire GET /session/:sessionId/orientation1960 */1961commands.getOrientation = function() {1962 var cb = findCallback(arguments);1963 this._jsonWireCall({1964 method: 'GET'1965 , relPath: '/orientation'1966 , cb: callbackWithData(cb, this)1967 });1968};1969/**1970 * setOrientation(cb) -> cb(err, orientation)1971 *1972 * @jsonWire POST /session/:sessionId/orientation1973 */1974commands.setOrientation = function(orientation) {1975 var cb = findCallback(arguments);1976 this._jsonWireCall({1977 method: 'POST'1978 , relPath: '/orientation'1979 , data: { orientation: orientation }1980 , cb: simpleCallback(cb)1981 });1982};1983/**1984 * setLocalStorageKey(key, value, cb) -> cb(err)1985 *1986 * # uses safeExecute() due to localStorage bug in Selenium1987 *1988 * @jsonWire POST /session/:sessionId/local_storage1989 */1990commands.setLocalStorageKey = function() {1991 var fargs = utils.varargs(arguments);1992 var cb = fargs.callback,1993 key = fargs.all[0],1994 value = fargs.all[1];1995 commands.safeExecute.apply(1996 this,1997 ["localStorage.setItem(arguments[0], arguments[1])", [key, value], cb]1998 );1999};2000/**2001 * getLocalStorageKey(key, cb) -> cb(err)2002 *2003 * # uses safeEval() due to localStorage bug in Selenium2004 *2005 * @jsonWire GET /session/:sessionId/local_storage/key/:key2006 */2007commands.getLocalStorageKey = function() {2008 var fargs = utils.varargs(arguments);2009 var cb = fargs.callback,2010 key = fargs.all[0];2011 commands.safeEval.apply(2012 this,2013 ["localStorage.getItem('" + key + "')", cb]2014 );2015};2016/**2017 * removeLocalStorageKey(key, cb) -> cb(err)2018 *2019 * # uses safeExecute() due to localStorage bug in Selenium2020 *2021 * @jsonWire DELETE /session/:sessionId/local_storage/key/:key2022 */2023commands.removeLocalStorageKey = function() {2024 var fargs = utils.varargs(arguments);2025 var cb = fargs.callback,2026 key = fargs.all[0];2027 commands.safeExecute.apply(2028 this,2029 ["localStorage.removeItem(arguments[0])", [key], cb]2030 );2031};2032/**2033 * clearLocalStorage(cb) -> cb(err)2034 *2035 * # uses safeExecute() due to localStorage bug in Selenium2036 *2037 * @jsonWire DELETE /session/:sessionId/local_storage2038 */2039commands.clearLocalStorage = function() {2040 var fargs = utils.varargs(arguments);2041 var cb = fargs.callback;2042 commands.safeExecute.apply(2043 this,2044 ["localStorage.clear()", cb]2045 );2046};2047// deprecated2048var _isVisible1 = function(element){2049 var cb = findCallback(arguments);2050 commands.getComputedCSS.apply(this, [element, "display", function(err, display){2051 if(err){2052 return cb(err);2053 }2054 cb(null, display !== "none");2055 }]);2056};2057// deprecated2058var _isVisible2 = function(queryType, querySelector){2059 var cb = findCallback(arguments);2060 commands.elementIfExists.apply(this, [queryType, querySelector, function(err, element){2061 if(err){2062 return cb(err);2063 }2064 if(element){2065 element.isVisible(cb);2066 } else {2067 cb(null, false); }2068 }]);2069};2070// deprecated2071commands.isVisible = function() {2072 deprecator.warn('isVisible', 'isVisible has been deprecated, use isDisplayed instead.');2073 var args = __slice.call(arguments, 0);2074 if (args.length <= 2) {2075 _isVisible1.apply(this, args);2076 } else {2077 _isVisible2.apply(this, args);2078 }2079};2080/**2081 * Retrieves the pageIndex element (added for Appium):2082 * getPageIndex(element, cb) -> cb(err, pageIndex)2083 */2084commands.getPageIndex = function(element) {2085 var cb = findCallback(arguments);2086 this._jsonWireCall({2087 method: 'GET'2088 , relPath: '/element/' + element + '/pageIndex'2089 , cb: callbackWithData(cb, this)2090 });2091};2092/**2093 * getLocation(element, cb) -> cb(err, location)2094 *2095 * @jsonWire GET /session/:sessionId/element/:id/location2096 */2097commands.getLocation = function(element) {2098 var cb = findCallback(arguments);2099 this._jsonWireCall({2100 method: 'GET'2101 , relPath: '/element/' + element + '/location'2102 , cb: callbackWithData(cb, this)2103 });2104};2105/**2106 * getLocationInView(element, cb) -> cb(err, location)2107 *2108 * @jsonWire GET /session/:sessionId/element/:id/location_in_view2109 */2110commands.getLocationInView = function(element) {2111 var cb = findCallback(arguments);2112 this._jsonWireCall({2113 method: 'GET'2114 , relPath: '/element/' + element + '/location_in_view'2115 , cb: callbackWithData(cb, this)2116 });2117};2118/**2119 * getSize(element, cb) -> cb(err, size)2120 *2121 * @jsonWire GET /session/:sessionId/element/:id/size2122 */2123commands.getSize = function(element) {2124 var cb = findCallback(arguments);2125 this._jsonWireCall({2126 method: 'GET'2127 , relPath: '/element/' + element + '/size'2128 , cb: callbackWithData(cb, this)2129 });2130};2131/**2132 * Uploads a local file using undocumented2133 * POST /session/:sessionId/file2134 * uploadFile(filepath, cb) -> cb(err, filepath)2135 */2136commands.uploadFile = function(filepath) {2137 var cb = findCallback(arguments);2138 var _this = this;2139 var archiver = require('archiver');2140 var archive = archiver('zip');2141 var dataList = [];2142 archive2143 .on('error', function(err) {2144 cb(err);2145 })2146 .on('data', function(data) {2147 dataList.push(data);2148 })2149 .on('end', function() {2150 _this._jsonWireCall({2151 method: 'POST'2152 , relPath: '/file'2153 , data: { file: Buffer.concat(dataList).toString('base64') },2154 cb: callbackWithData(cb, _this)2155 });2156 });2157 archive2158 .append(2159 fs.createReadStream(filepath),2160 { name: path.basename(filepath) }2161 );2162 archive.finalize(function(err) {2163 if (err) {2164 cb(err);2165 }2166 });2167};2168commands.waitForJsCondition = function(){2169 deprecator.warn('waitForJsCondition',2170 'waitForJsCondition has been deprecated, use waitFor + jsCondition asserter instead.');2171 var cb = findCallback(arguments);2172 var fargs = utils.varargs(arguments);2173 var jsConditionExpr = fargs.all[0],2174 timeout = fargs.all[1],2175 pollFreq = fargs.all[2];2176 commands.waitFor.apply(this, [2177 {2178 asserter: asserters.jsCondition(jsConditionExpr, true),2179 timeout: timeout,2180 pollFreq: pollFreq2181 }, function(err, value) {2182 if(err && err.message && err.message.match(/Condition/)) {2183 cb(new Error("Element condition wasn't satisfied!"));2184 } else {2185 cb(err, value);2186 }2187 }]);2188};2189commands.waitForCondition = commands.waitForJsCondition;2190// script to be executed in browser2191var _waitForConditionInBrowserJsScript =2192 utils.inlineJs(fs.readFileSync( __dirname + "/../browser-scripts/wait-for-cond-in-browser.js", 'utf8'));2193/**2194 * Waits for JavaScript condition to be true (async script polling within browser):2195 * waitForConditionInBrowser(conditionExpr, timeout, pollFreq, cb) -> cb(err, boolean)2196 * conditionExpr: condition expression, should return a boolean2197 * timeout and pollFreq are optional, default: 1000/100.2198 * return true if condition satisfied, error otherwise.2199 */2200commands.waitForConditionInBrowser = function() {2201 var _this = this;2202 // parsing args2203 var fargs = utils.varargs(arguments);2204 var cb = fargs.callback,2205 conditionExpr = fargs.all[0],2206 timeout = fargs.all[1] || 1000,2207 poll = fargs.all[2] || 100;2208 // calling script2209 commands.safeExecuteAsync.apply( _this, [_waitForConditionInBrowserJsScript,2210 [conditionExpr,timeout,poll], function(err,res) {2211 if(err) {return cb(err);}2212 if(res !== true) {return cb("waitForConditionInBrowser failure for: " + conditionExpr);}2213 cb(null, res);2214 }2215 ]);2216};2217/**2218 * sleep(ms, cb) -> cb(err)2219 */2220commands.sleep = function(ms, cb) {2221 cb = cb || function() {};2222 setTimeout(cb , ms);2223};2224/**2225 * noop(cb) -> cb(err)2226 */2227commands.noop = function(cb) {2228 if(cb) { cb(); }2229};2230/**2231 * shakeDevice(cb) -> cb(err)2232 *2233 * @jsonWire POST /session/:sessionId/appium/device/shake2234 */2235commands.shakeDevice = function() {2236 var cb = findCallback(arguments);2237 this._jsonWireCall({2238 method: 'POST'2239 , relPath: '/appium/device/shake'2240 , cb: simpleCallback(cb)2241 });2242};2243/**2244 * shake(cb) -> cb(err)2245 *2246 * @jsonWire POST /session/:sessionId/appium/device/shake2247 */2248commands.shake = commands.shakeDevice;2249/**2250 * lockDevice(seconds, cb) -> cb(err)2251 *2252 * @jsonWire POST /session/:sessionId/appium/device/lock2253 */2254commands.lockDevice = function() {2255 var fargs = utils.varargs(arguments);2256 var cb = fargs.callback,2257 seconds = fargs.all[0];2258 this._jsonWireCall({2259 method: 'POST'2260 , relPath: '/appium/device/lock'2261 , data: {seconds: seconds}2262 , cb: simpleCallback(cb)2263 });2264};2265/**2266 * lock(seconds, cb) -> cb(err)2267 *2268 * @jsonWire POST /session/:sessionId/appium/device/lock2269 */2270commands.lock = commands.lockDevice;2271/**2272 * unlockDevice(cb) -> cb(err)2273 *2274 * @jsonWire POST /session/:sessionId/appium/device/lock2275 */2276commands.unlockDevice = function() {2277 var fargs = utils.varargs(arguments);2278 var cb = fargs.callback;2279 this._jsonWireCall({2280 method: 'POST'2281 , relPath: '/appium/device/unlock'2282 , cb: simpleCallback(cb)2283 });2284};2285/**2286 * unlock(cb) -> cb(err)2287 *2288 * @jsonWire POST /session/:sessionId/appium/device/lock2289 */2290commands.unlock = commands.unlockDevice;2291/**2292 * isLocked(cb) -> cb(err)2293 *2294 * @jsonWire POST /session/:sessionId/appium/device/is_locked2295 */2296commands.isLocked = function() {2297 var fargs = utils.varargs(arguments);2298 var cb = fargs.callback;2299 this._jsonWireCall({2300 method: 'POST'2301 , relPath: '/appium/device/is_locked'2302 , cb: callbackWithData(cb)2303 });2304};2305/**2306 * deviceKeyEvent(keycode, metastate, cb) -> cb(err)2307 * metastate is optional2308 *2309 * @jsonWire POST /session/:sessionId/appium/device/keyevent2310 */2311commands.deviceKeyEvent = function() {2312 var fargs = utils.varargs(arguments);2313 var cb = fargs.callback,2314 keycode = fargs.all[0],2315 metastate = fargs.all[1];2316 var data = {keycode: keycode};2317 if(metastate) { data.metastate = metastate; }2318 this._jsonWireCall({2319 method: 'POST'2320 , relPath: '/appium/device/keyevent'2321 , data: data2322 , cb: simpleCallback(cb)2323 });2324};2325/**2326 * pressDeviceKey(keycode, metastate, cb) -> cb(err)2327 * metastate is optional2328 *2329 * @jsonWire POST /session/:sessionId/appium/device/keyevent2330 */2331commands.pressDeviceKey = commands.deviceKeyEvent;2332/**2333 * rotateDevice(element, opts, cb) -> cb(err)2334 * rotateDevice(opts, cb) -> cb(err)2335 * opts is like the following:2336 * {x: 114, y: 198, duration: 5, radius: 3, rotation: 220, touchCount: 2}2337 *2338 * @jsonWire POST /session/:sessionId/appium/device/rotate2339 */2340commands.rotateDevice = function() {2341 var fargs = utils.varargs(arguments);2342 var cb = fargs.callback,2343 element = fargs.all[0],2344 opts = fargs.all[1];2345 if(!(element && element.value)) {2346 opts = element;2347 element = null;2348 }2349 var data = _.clone(opts);2350 if(element) { data.element = element.value.toString(); }2351 this._jsonWireCall({2352 method: 'POST'2353 , relPath: '/appium/device/rotate'2354 , data: data2355 , cb: simpleCallback(cb)2356 });2357};2358/**2359 * rotate(element, opts, cb) -> cb(err)2360 * rotate(opts, cb) -> cb(err)2361 * opts is like the following:2362 * {x: 114, y: 198, duration: 5, radius: 3, rotation: 220, touchCount: 2}2363 *2364 * @jsonWire POST /session/:sessionId/appium/device/rotate2365 */2366commands.rotate = commands.rotateDevice;2367/**2368 * getCurrentDeviceActivity(cb) -> cb(err)2369 *2370 * @jsonWire GET /session/:sessionId/appium/device/current_activity2371 */2372commands.getCurrentDeviceActivity = function() {2373 var cb = findCallback(arguments);2374 this._jsonWireCall({2375 method: 'GET'2376 , relPath: '/appium/device/current_activity'2377 , cb: callbackWithData(cb, this)2378 });2379};2380/**2381 * getCurrentActivity(cb) -> cb(err)2382 *2383 * @jsonWire GET /session/:sessionId/appium/device/current_activity2384 */2385commands.getCurrentActivity = commands.getCurrentDeviceActivity;2386/**2387 * installAppOnDevice(appPath, cb) -> cb(err)2388 *2389 * @jsonWire POST /session/:sessionId/appium/device/install_app2390 */2391commands.installAppOnDevice = function() {2392 var fargs = utils.varargs(arguments);2393 var cb = fargs.callback,2394 appPath = fargs.all[0];2395 this._jsonWireCall({2396 method: 'POST'2397 , relPath: '/appium/device/install_app'2398 , data: { appPath: appPath}2399 , cb: simpleCallback(cb)2400 });2401};2402/**2403 * installApp(appPath, cb) -> cb(err)2404 *2405 * @jsonWire POST /session/:sessionId/appium/device/install_app2406 */2407commands.installApp = commands.installAppOnDevice;2408/**2409 * removeAppFromDevice(appId, cb) -> cb(err)2410 *2411 * @jsonWire POST /session/:sessionId/appium/device/remove_app2412 */2413commands.removeAppFromDevice = function() {2414 var fargs = utils.varargs(arguments);2415 var cb = fargs.callback,2416 appId = fargs.all[0];2417 this._jsonWireCall({2418 method: 'POST'2419 , relPath: '/appium/device/remove_app'2420 , data: { appId: appId}2421 , cb: simpleCallback(cb)2422 });2423};2424/**2425 * removeApp(appId, cb) -> cb(err)2426 *2427 * @jsonWire POST /session/:sessionId/appium/device/remove_app2428 */2429commands.removeApp = commands.removeAppFromDevice;2430/**2431 * isAppInstalledOnDevice(bundleId, cb) -> cb(isInstalled, err)2432 *2433 * @jsonWire POST /session/:sessionId/appium/device/app_installed2434 */2435commands.isAppInstalledOnDevice = function() {2436 var fargs = utils.varargs(arguments);2437 var cb = fargs.callback,2438 bundleId = fargs.all[0];2439 this._jsonWireCall({2440 method: 'POST'2441 , relPath: '/appium/device/app_installed'2442 , data: {bundleId: bundleId}2443 , cb: callbackWithData(cb, this)2444 });2445};2446/**2447 * isAppInstalled(bundleId, cb) -> cb(isInstalled, err)2448 *2449 * @jsonWire POST /session/:sessionId/appium/device/app_installed2450 */2451commands.isAppInstalled = commands.isAppInstalledOnDevice;2452/**2453 * hideKeyboard() -> cb(err)2454 * hideKeyboard(keyName, cb) -> cb(err)2455 * hideKeyboard({strategy: 'pressKey', key:'<key>'}) -> cb(err)2456 * hideKeyboard({strategy: 'tapOutside'}) -> cb(err)2457 *2458 * @jsonWire POST /session/:sessionId/appium/device/hide_keyboard2459 */2460commands.hideDeviceKeyboard = function() {2461 var fargs = utils.varargs(arguments);2462 var cb = fargs.callback;2463 var data = {};2464 switch(typeof fargs.all[0]) {2465 case 'string':2466 data = {keyName: fargs.all[0]};2467 break;2468 case 'object':2469 data = fargs.all[0];2470 break;2471 default:2472 data= null;2473 }2474 this._jsonWireCall({2475 method: 'POST'2476 , relPath: '/appium/device/hide_keyboard'2477 , data: data2478 , cb: simpleCallback(cb)2479 });2480};2481commands.hideKeyboard = commands.hideDeviceKeyboard;2482/**2483 * pushFileToDevice(pathOnDevice, base64Data, cb) -> cb(err)2484 *2485 * @jsonWire POST /session/:sessionId/appium/device/push_file2486 */2487commands.pushFileToDevice = function() {2488 var fargs = utils.varargs(arguments);2489 var cb = fargs.callback,2490 pathOnDevice = fargs.all[0],2491 base64Data = fargs.all[1];2492 this._jsonWireCall({2493 method: 'POST'2494 , relPath: '/appium/device/push_file'2495 , data: {path: pathOnDevice, data: base64Data}2496 , cb: simpleCallback(cb)2497 });2498};2499/**2500 * pushFile(pathOnDevice, base64Data, cb) -> cb(err)2501 *2502 * @jsonWire POST /session/:sessionId/appium/device/push_file2503 */2504commands.pushFile = commands.pushFileToDevice;2505/**2506 * pullFileFromDevice(pathOnDevice, cb) -> cb(base64EncodedData, err)2507 *2508 * @jsonWire POST /session/:sessionId/appium/device/pull_file2509 */2510commands.pullFileFromDevice = function() {2511 var fargs = utils.varargs(arguments);2512 var cb = fargs.callback,2513 pathOnDevice = fargs.all[0];2514 this._jsonWireCall({2515 method: 'POST'2516 , relPath: '/appium/device/pull_file'2517 , data: {path: pathOnDevice}2518 , cb: callbackWithData(cb, this)2519 });2520};2521/**2522 * pullFile(pathOnDevice, cb) -> cb(base64EncodedData, err)2523 *2524 * @jsonWire POST /session/:sessionId/appium/device/pull_file2525 */2526commands.pullFile = commands.pullFileFromDevice;2527/**2528 * pullFolderFromDevice(pathOnDevice, cb) -> cb(base64EncodedData, err)2529 *2530 * @jsonWire POST /session/:sessionId/appium/device/pull_folder2531 */2532 commands.pullFolderFromDevice = function() {2533 var fargs = utils.varargs(arguments);2534 var cb = fargs.callback,2535 pathOnDevice = fargs.all[0];2536 this._jsonWireCall({2537 method: 'POST'2538 , relPath: '/appium/device/pull_folder'2539 , data: {path: pathOnDevice}2540 , cb: callbackWithData(cb, this)2541 });2542 };2543 /**2544 * pullFolder(pathOnDevice, cb) -> cb(base64EncodedData, err)2545 *2546 * @jsonWire POST /session/:sessionId/appium/device/pull_folder2547 */2548commands.pullFolder = commands.pullFolderFromDevice;2549/**2550 * toggleAirplaneModeOnDevice(cb) -> cb(err)2551 *2552 * @jsonWire POST /session/:sessionId/appium/device/toggle_airplane_mode2553 */2554commands.toggleAirplaneModeOnDevice = function() {2555 var cb = findCallback(arguments);2556 this._jsonWireCall({2557 method: 'POST'2558 , relPath: '/appium/device/toggle_airplane_mode'2559 , cb: simpleCallback(cb)2560 });2561};2562/**2563 * toggleAirplaneMode(cb) -> cb(err)2564 *2565 * @jsonWire POST /session/:sessionId/appium/device/toggle_airplane_mode2566 */2567commands.toggleAirplaneMode = commands.toggleAirplaneModeOnDevice;2568/**2569 * toggleFlightMode(cb) -> cb(err)2570 *2571 * @jsonWire POST /session/:sessionId/appium/device/toggle_airplane_mode2572 */2573commands.toggleFlightMode = commands.toggleAirplaneModeOnDevice;2574/**2575 * toggleWiFiOnDevice(cb) -> cb(err)2576 *2577 * @jsonWire POST /session/:sessionId/appium/device/toggle_wifi2578 */2579commands.toggleWiFiOnDevice = function() {2580 var cb = findCallback(arguments);2581 this._jsonWireCall({2582 method: 'POST'2583 , relPath: '/appium/device/toggle_wifi'2584 , cb: simpleCallback(cb)2585 });2586};2587/**2588 * toggleWiFi(cb) -> cb(err)2589 *2590 * @jsonWire POST /session/:sessionId/appium/device/toggle_wifi2591 */2592commands.toggleWiFi = commands.toggleWiFiOnDevice;2593/**2594 * toggleLocationServicesOnDevice(cb) -> cb(err)2595 *2596 * @jsonWire POST /session/:sessionId/appium/device/toggle_location_services2597 */2598commands.toggleLocationServicesOnDevice = function() {2599 var cb = findCallback(arguments);2600 this._jsonWireCall({2601 method: 'POST'2602 , relPath: '/appium/device/toggle_location_services'2603 , cb: simpleCallback(cb)2604 });2605};2606/**2607 * toggleLocationServices(cb) -> cb(err)2608 *2609 * @jsonWire POST /session/:sessionId/appium/device/toggle_location_services2610 */2611commands.toggleLocationServices = commands.toggleLocationServicesOnDevice;2612/**2613 * toggleDataOnDevice(cb) -> cb(err)2614 *2615 * @jsonWire POST /session/:sessionId/appium/device/toggle_data2616 */2617commands.toggleDataOnDevice = function() {2618 var cb = findCallback(arguments);2619 this._jsonWireCall({2620 method: 'POST'2621 , relPath: '/appium/device/toggle_data'2622 , cb: simpleCallback(cb)2623 });2624};2625/**2626 * toggleData(cb) -> cb(err)2627 *2628 * @jsonWire POST /session/:sessionId/appium/device/toggle_data2629 */2630commands.toggleData = commands.toggleDataOnDevice;2631/**2632 * launchApp(cb) -> cb(err)2633 *2634 * @jsonWire POST /session/:sessionId/appium/app/launch2635 */2636commands.launchApp = function() {2637 var cb = findCallback(arguments);2638 this._jsonWireCall({2639 method: 'POST'2640 , relPath: '/appium/app/launch'2641 , cb: simpleCallback(cb)2642 });2643};2644/**2645 * closeApp(cb) -> cb(err)2646 *2647 * @jsonWire POST /session/:sessionId/appium/app/close2648 */2649commands.closeApp = function() {2650 var cb = findCallback(arguments);2651 this._jsonWireCall({2652 method: 'POST'2653 , relPath: '/appium/app/close'2654 , cb: simpleCallback(cb)2655 });2656};2657/**2658 * resetApp(cb) -> cb(err)2659 *2660 * @jsonWire POST /session/:sessionId/appium/app/reset2661 */2662commands.resetApp = function() {2663 var cb = findCallback(arguments);2664 this._jsonWireCall({2665 method: 'POST'2666 , relPath: '/appium/app/reset'2667 , cb: simpleCallback(cb)2668 });2669};2670/**2671 * backgroundApp(seconds, cb) -> cb(err)2672 *2673 * @jsonWire POST /session/:sessionId/appium/app/background2674 */2675commands.backgroundApp = function() {2676 var fargs = utils.varargs(arguments);2677 var cb = fargs.callback,2678 seconds = fargs.all[0];2679 this._jsonWireCall({2680 method: 'POST'2681 , relPath: '/appium/app/background'2682 , data: {seconds: seconds}2683 , cb: simpleCallback(cb)2684 });2685};2686/**2687 * endTestCoverageForApp(intentToBroadcast, pathOnDevice) -> cb(base64Data,err)2688 *2689 * @jsonWire POST /session/:sessionId/appium/app/end_test_coverage2690 */2691commands.endTestCoverageForApp = function() {2692 var fargs = utils.varargs(arguments);2693 var cb = fargs.callback,2694 intent = fargs.all[0],2695 path = fargs.all[1];2696 this._jsonWireCall({2697 method: 'POST'2698 , relPath: '/appium/app/end_test_coverage'2699 , data: {intent: intent, path: path}2700 , cb: callbackWithData(cb, this)2701 });2702};2703/**2704 * endTestCoverage(intentToBroadcast, pathOnDevice) -> cb(base64Data,err)2705 *2706 * @jsonWire POST /session/:sessionId/appium/app/end_test_coverage2707 */2708commands.endTestCoverage = commands.endTestCoverageForApp;2709/**2710 * endCoverage(intentToBroadcast, pathOnDevice) -> cb(base64Data,err)2711 *2712 * @jsonWire POST /session/:sessionId/appium/app/end_test_coverage2713 */2714commands.endCoverage = commands.endTestCoverageForApp;2715/**2716 * complexFindInApp(selector) -> cb(element(s))2717 * Return a single element or an elements array depending on2718 * selector2719 *2720 * @jsonWire POST /session/:sessionId/appium/app/complex_find2721 */2722commands.complexFindInApp = function() {2723 var fargs = utils.varargs(arguments);2724 var cb = fargs.callback,2725 selector = fargs.all[0];2726 this._jsonWireCall({2727 method: 'POST'2728 , relPath: '/appium/app/complex_find'2729 , data: {selector: selector}2730 , cb: elementOrElementsCallback(cb, this)2731 });2732};2733/**2734 * complexFind(selector) -> cb(element(s))2735 * Return a single element or an elements array depending on2736 * selector2737 *2738 * @jsonWire POST /session/:sessionId/appium/app/complex_find2739 */2740commands.complexFind = commands.complexFindInApp;2741/**2742 * getAppStrings(cb) -> cb(err)2743 *2744 * @jsonWire POST /session/:sessionId/appium/app/strings2745 */2746commands.getAppStrings = function() {2747 var fargs = utils.varargs(arguments);2748 var cb = fargs.callback,2749 language = fargs.all[0];2750 this._jsonWireCall({2751 method: 'POST'2752 , relPath: '/appium/app/strings'2753 , data: {language: language}2754 , cb: callbackWithData(cb, this)2755 });2756};2757/**2758 * setImmediateValueInApp(element, value, cb) -> cb(err)2759 *2760 * @jsonWire POST /session/:sessionId/appium/element/:elementId?/value2761 */2762commands.setImmediateValueInApp = function(element, value) {2763 var cb = findCallback(arguments);2764 this._jsonWireCall({2765 method: 'POST'2766 , relPath: '/appium/element/' + element.value.toString() + '/value'2767 , data: {value: value}2768 , cb: simpleCallback(cb)2769 });2770};2771/**2772 * startActivity(options, cb) -> cb(err)2773 * Start an arbitrary Android activity during a session. The 'options' parameter should2774 * implement the interface {appPackage, appActivity, [appWaitPackage], [appWaitActivity]}.2775 *2776 * @jsonWire POST /session/:sessionId/appium/device/start_activity2777 */2778commands.startActivity = function() {2779 var fargs = utils.varargs(arguments);2780 var cb = fargs.callback,2781 options = fargs.all[0];2782 this._jsonWireCall({2783 method: 'POST'2784 , relPath: '/appium/device/start_activity'2785 , data: options2786 , cb: simpleCallback(cb)2787 });2788};2789/**2790 * setImmediateValue(element, value, cb) -> cb(err)2791 *2792 * @jsonWire POST /session/:sessionId/appium/element/:elementId?/value2793 */2794commands.setImmediateValue = commands.setImmediateValueInApp;2795/**2796 * setNetworkConnection(type, cb) -> cb(err)2797 *2798 * @jsonWire POST /session/:sessionId/network_connection2799 */2800commands.setNetworkConnection = function() {2801 var fargs = utils.varargs(arguments);2802 var cb = fargs.callback;2803 this._jsonWireCall({2804 method: 'POST'2805 , relPath: '/network_connection'2806 , data: {parameters: {type: fargs.all[0]}}2807 , cb: callbackWithData(cb, this)2808 });2809};2810/**2811 * getNetworkConnection(cb) -> cb(err, networkConnectionInfo)2812 *2813 * @jsonWire GET /session/:sessionId/network_connection2814 */2815commands.getNetworkConnection = function() {2816 var cb = findCallback(arguments);2817 this._jsonWireCall({2818 method: 'GET'2819 , relPath: '/network_connection'2820 , cb: callbackWithData(cb, this)2821 });2822};2823/**2824 * openNotifications(cb) -> cb(err)2825 *2826 * @jsonWire POST /session/:sessionId/appium/device/open_notifications2827 */2828commands.openNotifications = function() {2829 var cb = findCallback(arguments);2830 this._jsonWireCall({2831 method: 'POST'2832 , relPath: '/appium/device/open_notifications'2833 , cb: simpleCallback(cb, this)2834 });2835};2836/**2837 * settings(cb) -> cb(err, settingsObject)2838 *2839 * @jsonWire GET /session/:sessionId/appium/settings2840 */2841commands.settings = function() {2842 var cb = findCallback(arguments);2843 this._jsonWireCall({2844 method: 'GET'2845 , relPath: '/appium/settings'2846 , cb: callbackWithData(cb, this)2847 });2848};2849/**2850 * updateSettings(settingsObject, cb) -> cb(err)2851 *2852 * @jsonWire POST /session/:sessionId/appium/settings2853 */2854commands.updateSettings = function() {2855 var fargs = utils.varargs(arguments);2856 var cb = fargs.callback;2857 this._jsonWireCall({2858 method: 'POST'2859 , relPath: '/appium/settings'2860 , data: {settings: fargs.all[0]}2861 , cb: simpleCallback(cb, this)2862 });2863};2864/**2865 * availableIMEEngines(cb) -> cb(err, engines)2866 *2867 * @jsonWire GET /session/:sessionId/ime/available_engines2868 */2869commands.availableIMEEngines = function() {2870 var cb = findCallback(arguments);2871 this._jsonWireCall({2872 method: 'GET'2873 , relPath: '/ime/available_engines'2874 , cb: callbackWithData(cb, this)2875 });2876};2877/**2878 * activateIMEEngine(cb, engine) -> cb(err)2879 *2880 * @jsonWire POST /session/:sessionId/ime/activate2881 */2882commands.activateIMEEngine = function(engine) {2883 var cb = findCallback(arguments);2884 this._jsonWireCall({2885 method: 'POST'2886 , relPath: '/ime/activate'2887 , data: { engine: engine }2888 , cb: simpleCallback(cb, this)2889 });2890};2891/**2892 * deactivateIMEEngine(cb) -> cb(err)2893 *2894 * @jsonWire POST /session/:sessionId/ime/deactivate2895 */2896commands.deactivateIMEEngine = function() {2897 var cb = findCallback(arguments);2898 this._jsonWireCall({2899 method: 'POST'2900 , relPath: '/ime/deactivate'2901 , cb: simpleCallback(cb, this)2902 });2903};2904/**2905 * activatedIMEEngine(cb) -> cb(err, active)2906 *2907 * @jsonWire GET /session/:sessionId/ime/activated2908 */2909commands.isIMEActive = function() {2910 var cb = findCallback(arguments);2911 this._jsonWireCall({2912 method: 'GET'2913 , relPath: '/ime/activated'2914 , cb: callbackWithData(cb, this)2915 });2916};2917/**2918 * activeIMEEngine(cb) -> cb(err, activeEngine)2919 *2920 * @jsonWire GET /session/:sessionId/ime/active_engine2921 */2922commands.activeIMEEngine = function () {2923 var cb = findCallback(arguments);2924 this._jsonWireCall({2925 method: 'GET'2926 , relPath: '/ime/active_engine'2927 , cb: callbackWithData(cb, this)2928 });2929};2930/**2931 * getDeviceTime(cb) -> cb(err, deviceTime)2932 *2933 * @jsonWire GET /session/:sessionId/appium/device/system_time2934 */2935commands.getDeviceTime = function () {2936 var cb = findCallback(arguments);2937 this._jsonWireCall({2938 method: 'GET'2939 , relPath: '/appium/device/system_time'2940 , cb: callbackWithData(cb, this)2941 });2942};2943commands.touch = function () {2944 var cb = findCallback(arguments);2945 var fargs = utils.varargs(arguments);2946 var cb = fargs.callback,2947 code = fargs.all[0],2948 args = fargs.all[1] || {},2949 actions = [];2950 if (Array.isArray(code)) {2951 for (var i = 0, len = code.length; i < len; i++) {2952 if (i > 0) {2953 var curr = code[i];2954 var prev = code[i-1];2955 if (!curr.type) {2956 curr.type = prev.type;2957 }2958 }2959 actions[i] = code[i];2960 }2961 } else if (typeof code === 'string') {2962 args['type'] = code;2963 actions = [args];2964 } else {2965 cb(new Error('Touch function only accept a action name or a list of actions.'))2966 }2967 this._jsonWireCall({2968 method: 'POST',2969 relPath: '/actions',2970 data: {actions: actions},2971 cb: simpleCallback(cb)2972 });2973};...

Full Screen

Full Screen

android-common.js

Source:android-common.js Github

copy

Full Screen

...872 }.bind(this));873 }874 async.series(series, function (err) {875 if (err) return ocb(err);876 return this.getNetworkConnection(ocb);877 }.bind(this));878};879androidCommon.isIMEActivated = function (cb) {880 // IME is always activated on Android devices881 cb(null, {882 status: status.codes.Success.code,883 value: true884 });885};886androidCommon.availableIMEEngines = function (cb) {887 logger.debug('Retrieving available IMEs');888 this.adb.availableIMEs(function (err, engines) {889 if (err) return cb(err);890 logger.debug('Engines: ' + JSON.stringify(engines));...

Full Screen

Full Screen

network.js

Source:network.js Github

copy

Full Screen

...36 // decode the input37 const shouldEnableAirplaneMode = (type & AIRPLANE_MODE_MASK) !== 0;38 const shouldEnableWifi = (type & WIFI_MASK) !== 0;39 const shouldEnableDataConnection = (type & DATA_MASK) !== 0;40 const currentState = await this.getNetworkConnection();41 const isAirplaneModeEnabled = (currentState & AIRPLANE_MODE_MASK) !== 0;42 const isWiFiEnabled = (currentState & WIFI_MASK) !== 0;43 const isDataEnabled = (currentState & DATA_MASK) !== 0;44 if (shouldEnableAirplaneMode !== isAirplaneModeEnabled) {45 await this.wrapBootstrapDisconnect(async () => {46 await this.adb.setAirplaneMode(shouldEnableAirplaneMode);47 });48 await this.wrapBootstrapDisconnect(async () => {49 await this.adb.broadcastAirplaneMode(shouldEnableAirplaneMode);50 });51 } else {52 log.info(`Not changing airplane mode, since it is already ` +53 `${shouldEnableAirplaneMode ? 'enabled' : 'disabled'}`);54 }55 if (shouldEnableWifi === isWiFiEnabled && shouldEnableDataConnection === isDataEnabled) {56 log.info('Not changing data connection/Wi-Fi states, since they are already set to expected values');57 if (await this.adb.isAirplaneModeOn()) {58 return AIRPLANE_MODE_MASK | currentState;59 }60 return ~AIRPLANE_MODE_MASK & currentState;61 }62 await this.wrapBootstrapDisconnect(async () => {63 if (shouldEnableWifi !== isWiFiEnabled) {64 await this.setWifiState(shouldEnableWifi);65 } else {66 log.info(`Not changing Wi-Fi state, since it is already ` +67 `${shouldEnableWifi ? 'enabled' : 'disabled'}`);68 }69 if (shouldEnableAirplaneMode) {70 log.info('Not changing data connection state, because airplane mode is enabled');71 } else if (shouldEnableDataConnection === isDataEnabled) {72 log.info(`Not changing data connection state, since it is already ` +73 `${shouldEnableDataConnection ? 'enabled' : 'disabled'}`);74 } else {75 await this.adb.setDataState(shouldEnableDataConnection, this.isEmulator());76 }77 });78 return await this.getNetworkConnection();79};80/**81 * decoupling to override behaviour in other drivers like UiAutomator2.82 */83commands.setWifiState = async function setWifiState (wifi) {84 await this.adb.setWifiState(wifi, this.isEmulator());85};86commands.toggleData = async function toggleData () {87 let data = !(await this.adb.isDataOn());88 log.info(`Turning network data ${data ? 'on' : 'off'}`);89 await this.wrapBootstrapDisconnect(async () => {90 await this.adb.setWifiAndData({data}, this.isEmulator());91 });92};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var networkConnection = driver.getNetworkConnection();2driver.setNetworkConnection(networkConnection);3var networkConnection = driver.getNetworkConnection();4driver.setNetworkConnection(networkConnection);5var networkConnection = driver.getNetworkConnection();6driver.setNetworkConnection(networkConnection);7var networkConnection = driver.getNetworkConnection();8driver.setNetworkConnection(networkConnection);9var networkConnection = driver.getNetworkConnection();10driver.setNetworkConnection(networkConnection);11var networkConnection = driver.getNetworkConnection();12driver.setNetworkConnection(networkConnection);13var networkConnection = driver.getNetworkConnection();14driver.setNetworkConnection(networkConnection);15var networkConnection = driver.getNetworkConnection();16driver.setNetworkConnection(networkConnection);17var networkConnection = driver.getNetworkConnection();18driver.setNetworkConnection(networkConnection);19var networkConnection = driver.getNetworkConnection();20driver.setNetworkConnection(networkConnection

Full Screen

Using AI Code Generation

copy

Full Screen

1driver.getNetworkConnection().then(function(connection){2 console.log(connection);3});4driver.setNetworkConnection(6).then(function(connection){5 console.log(connection);6});7driver.quit();8{ '0': 1 }9{ '0': 6 }10Your name to display (optional):11Your name to display (optional):

Full Screen

Using AI Code Generation

copy

Full Screen

1var networkConnection = driver.getNetworkConnection();2console.log(networkConnection);3driver.setNetworkConnection(0);4driver.setNetworkConnection(1);5driver.setNetworkConnection(2);6driver.setNetworkConnection(4);7driver.setNetworkConnection(6);8driver.setNetworkConnection(10);9driver.setNetworkConnection(12);10driver.setNetworkConnection(14);11driver.setNetworkConnection(18);12driver.setNetworkConnection(20);13driver.setNetworkConnection(22);14driver.setNetworkConnection(26);15driver.setNetworkConnection(28);16driver.setNetworkConnection(30);17driver.setNetworkConnection(34);18driver.setNetworkConnection(36);19driver.setNetworkConnection(38);20driver.setNetworkConnection(42);21driver.setNetworkConnection(44);22driver.setNetworkConnection(46);23driver.setNetworkConnection(50);24driver.setNetworkConnection(52);

Full Screen

Using AI Code Generation

copy

Full Screen

1 .init(caps)2 .setImplicitWaitTimeout(5000)3 .getNetworkConnection()4 .then(function (connection) {5 console.log("Connection Type: " + connection);6 })7 .fin(function() { return driver.quit(); })8 .done();9Your name to display (optional):

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd')2 , assert = require('assert');3var desired = {4};5var driver = wd.promiseChainRemote('localhost', 4723);6 .init(desired)7 .getNetworkConnection()8 .then(function (result) {console.log(result);})9 .fin(function() { return driver.quit(); })10 .done();11{ [Error: An unknown server-side error occurred while processing the command. Original error: Error occured while starting App. Original error: Command failed: /bin/sh -c /Users/srinath/adt-bundle-mac-x86_64-20140702/sdk/platform-tools/adb -s emulator-5554 shell "am instrument -e main_activity 'com.example.test/com.example.test.MainActivity' -w com.example.test.test/android.test.InstrumentationTestRunner"12INSTRUMENTATION_STATUS: stack=java.lang.RuntimeException: Could not launch intent Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.test/.MainActivity }:13 at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1776)14 at android.app.Instrumentation.execStartActivity(Instrumentation.java:1495)15 at android.app.Activity.startActivityForResult(Activity.java:3721)16 at android.app.Activity.startActivityForResult(Activity

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var desiredCaps = {4};5var driver = wd.promiseChainRemote('localhost', 4723);6 .init(desiredCaps)7 .getNetworkConnection()8 .then(function (networkConnection) {9 console.log(networkConnection);10 })11 .fin(function () {12 return driver.quit();13 })14 .done();15var wd = require('wd');16var assert = require('assert');17var desiredCaps = {18};19var driver = wd.promiseChainRemote('localhost', 4723);20 .init(desiredCaps)21 .getNetworkConnection()22 .then(function (networkConnection) {23 console.log(network

Full Screen

Using AI Code Generation

copy

Full Screen

1driver.getNetworkConnection().then(function (networkConnection) {2 console.log(networkConnection);3});4driver.setNetworkConnection(2).then(function () {5 console.log("Network connection type set to Airplane mode");6});7driver.setNetworkConnection(4).then(function () {8 console.log("Network connection type set to Wifi");9});10driver.setNetworkConnection(6).then(function () {11 console.log("Network connection type set to Data");12});13driver.setNetworkConnection(1).then(function () {14 console.log("Network connection type set to All network on");15});16driver.setNetworkConnection(0).then(function () {17 console.log("Network connection type set to All network off");18});19driver.setNetworkConnection(5).then(function () {20 console.log("Network connection type set to Wifi and Data");21});22driver.setNetworkConnection(7).then(function () {23 console.log("Network connection type set to All network on");24});25driver.setNetworkConnection(8).then(function () {26 console.log("Network connection type set to All network off");27});28driver.setNetworkConnection(9).then(function () {29 console.log("Network connection type set to All network on");30});31driver.setNetworkConnection(10).then(function () {32 console.log("Network connection type set to All network off");33});34driver.setNetworkConnection(11).then(function () {35 console.log("Network connection type set to All network on");36});37driver.setNetworkConnection(12).then(function () {38 console.log("Network connection type set to

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