Best JavaScript code snippet using appium
wd.js
Source:wd.js
1/*jshint node:true */2define([3 'dojo/node!wd',4 'dojo/node!wd/lib/webdriver',5 'dojo/node!wd/lib/element',6 'dojo/node!wd/lib/utils',7 'dojo/node!path',8 'dojo/when',9 'dojo/Deferred',10 'dojo/topic',11 './util'12], function (wd, WebDriver, Element, wdUtils, pathUtils, when, Deferred, topic, util) {13 if (!wd) {14 throw new Error('wd cannot be loaded in a browser environment');15 }16 // wd APIs are pretty awful17 if (Element.element) {18 Element = Element.element;19 }20 // Simplify moving mouse to an element21 if (!Element.prototype.moveTo) {22 Element.prototype.moveTo = function (offsetX, offsetY, cb) {23 this.browser.moveTo(this, offsetX, offsetY, cb);24 };25 }26 var stringify = (function (value) {27 function escapeString(/*string*/ str) {28 return ('"' + str.replace(/(["\\])/g, '\\$1') + '"')29 .replace(/[\f]/g, '\\f')30 .replace(/[\b]/g, '\\b')31 .replace(/[\n]/g, '\\n')32 .replace(/[\t]/g, '\\t')33 .replace(/[\r]/g, '\\r'); // string34 }35 function serialize(value, key) {36 /*jshint maxcomplexity:16 */37 if (value === null) {38 return 'null';39 }40 switch (typeof value) {41 case 'number':42 return isFinite(value) ? '' + value : 'null';43 case 'boolean':44 return '' + value;45 case 'string':46 return escapeString(value);47 case 'function':48 case 'undefined':49 return undefined;50 }51 if (typeof value.toJSON === 'function') {52 return serialize(value.toJSON(key), key);53 }54 if (value instanceof Date) {55 return '"{FullYear}-{Month+}-{Date}T{Hours}:{Minutes}:{Seconds}Z"'.replace(/\{(\w+)(\+)?\}/g, function ($, datePart, needsOffset) {56 var part = value['getUTC' + datePart]() + (needsOffset ? 1 : 0);57 return part < 10 ? '0' + part : part;58 });59 }60 // wrapped primitive?61 if (value !== value.valueOf()) {62 return serialize(value.valueOf(), key);63 }64 var result = [],65 item;66 if (value instanceof Array) {67 var length = value.length;68 for (key = 0; key < length; ++key) {69 item = serialize(value[key], key);70 if (typeof item !== 'string') {71 item = 'null';72 }73 result.push(item);74 }75 return '[' + result.join(',') + ']';76 }77 for (key in value) {78 if (Object.prototype.hasOwnProperty.call(value, key)) {79 item = serialize(value[key], key);80 // skip non-serializable values81 if (typeof item !== 'string') {82 continue;83 }84 result.push(escapeString(key) + ':' + item);85 }86 }87 return '{' + result.join(',') + '}'; // string88 }89 return serialize(value, '');90 }).toString();91 /**92 * A hash map of names of methods that accept an element as the first argument.93 */94 var elementArgumentMethods = {95 clickElement: true,96 submit: true,97 text: true,98 getTagName: true,99 clear: true,100 isSelected: true,101 getAttribute: true,102 getValue: true,103 isDisplayed: true,104 getLocation: true,105 getSize: true,106 getComputedCss: true,107 moveTo: true,108 flick: true,109 isVisible: true,110 // `type` must be used with element context or else this happens in Safari:111 // https://code.google.com/p/selenium/issues/detail?id=4996112 type: true113 };114 /**115 * A hash map of names of methods that operate using an element as the context. Only methods that do not have an116 * entry in `elementArgumentMethods` of the same name are listed here, since they are just proxies back to those117 * master methods.118 */119 var elementContextMethods = {120 click: true,121 textPresent: true,122 equals: true123 };124 wdUtils.elementFuncTypes.forEach(function (type) {125 type = wdUtils.elFuncSuffix(type);126 [ 'element_',127 'element_OrNull',128 'element_IfExists',129 'waitForElement_',130 'waitForVisible_',131 'elements_'132 ].forEach(function (wrapper) {133 var name = wrapper.replace('_', type);134 elementContextMethods[name] = true;135 });136 });137 /**138 * A WebDriver instance with Promises/A interface methods instead of Node.js callback-style methods.139 *140 * @property {string} sessionId The session ID of the current remote session. Undefined until the session is141 * successfully initialised using {@link init}.142 *143 * @property {function(desiredCapabilities:Object):PromisedWebDriver -> string} init144 * Creates a new remote session with the desired capabilities. The first argument is a capabilities object.145 * Resolves to the session ID of the new session. This method should never be called directly by testing code.146 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session147 *148 * @property {function():PromisedWebDriver -> Object} status149 * Retrieves the status of the server. Resolves to an object with information on the server status.150 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/status151 *152 * @property {function():PromisedWebDriver -> Array.<Object>} sessions153 * Retrieves a list of active sessions on the current server. Resolves to an array of objects containing the154 * ID and map of capabilities for each session.155 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/sessions156 *157 * @property {function():PromisedWebDriver -> Object} sessionCapabilities158 * Retrieves the list of capabilities defined for the current session. Resolves to a hash map of the capabilities159 * of the current session.160 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId161 *162 * @property {function(url:string, name:string=):PromisedWebDriver} newWindow163 * Opens a new window (using `window.open`) with the given URL and optionally a name for the new window.164 * The window can later be accessed by name with the {@link window} method, or by getting the last handle165 * returned by the {@link windowHandles} method.166 *167 * @property {function():PromisedWebDriver} close168 * Closes the currently focused window.169 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#DELETE_/session/:sessionId/window170 *171 * @property {function(name:string):PromisedWebDriver} window172 * Changes focus to the window with the given name.173 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/window174 *175 * @property {function(id:(string|number|Element)):PromisedWebDriver} frame176 * Changes focus to the frame (like `window.frames`) with the given name, index, or explicit element reference.177 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/frame178 *179 * @property {function():PromisedWebDriver -> string} windowName180 * Retrieves the name of the currently focused window.181 *182 * @property {function():PromisedWebDriver -> string} windowHandle183 * Retrieves the current window handle.184 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/window_handle185 *186 * @property {function():PromisedWebDriver -> Array.<string>} windowHandles187 * Retrieves all window handles currently available within the session.188 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/window_handles189 *190 * @property {function():PromisedWebDriver} quit191 * Destroys the current session. This method should never be called by testing code.192 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#DELETE_/session/:sessionId193 *194 * @property {function(code:string):PromisedWebDriver -> *} eval195 * Evaluates the given code using the `eval` function of the remote browser. Resolves to the value of the196 * evaluated expression. It is recommended that `execute` be used instead of this function when possible.197 *198 * @property {function(code:string|Function):PromisedWebDriver -> *} execute199 * Executes the given code or function within the remote browser. Resolves to the return value of the function.200 * When a string is passed, it is invoked as with `new Function`. If a function is passed, it is serialised and201 * passed to the remote browser, so when executed does not have access to anything from the original lexical scope.202 * If the resolved value of an `execute` method is an Element, the element will be set as the current context for203 * element-specific methods.204 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/execute205 *206 * @property {function(code:string|Function, args:Array=):PromisedWebDriver -> *} executeAsync207 * Executes the given code or function within the remote browser, expecting that the code will invoke the callback208 * that gets passed as the final argument to the function. For example:209 *210 * <pre>211 * remote.executeAsync(function (timeout, callback) {212 * setTimeout(function () {213 * callback('returnValue');214 * }, timeout);215 * }, [ 1000 ]);216 * </pre>217 *218 * Note that `executeAsync` may not be supported by all Selenium drivers.219 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/execute_async220 *221 * @property {function(url:string):PromisedWebDriver} get222 * Navigates the currently focused window to the given URL. Resolves when the browser `window.onload` event223 * fires.224 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/url225 *226 * @property {function():PromisedWebDriver} refresh227 * Refreshes the currently focused window.228 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/refresh229 *230 * @property {function(handle:string):PromisedWebDriver} maximize231 * Maximises the window specified by `handle` if not already maximised. The special handle value "current" may be232 * used to maximise the currently focused window.233 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/window/:windowHandle/maximize234 *235 * @property {function(handle:string=):PromisedWebDriver -> { width:number, height:number }} getWindowSize236 * Gets the size of the window specified by `handle`. If no handle is specified, the size of the currently focused237 * window is retrieved.238 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/window/:windowHandle/size239 *240 * @property {function(width:number, height:number, handle:string=):PromisedWebDriver} setWindowSize241 * Sets the size of the window specified by `handle`. If no handle is specified, the size of the currently focused242 * window is set.243 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/window/:windowHandle/size244 *245 * @property {function(handle:string=):PromisedWebDriver -> { x: number, y: number }} getWindowPosition246 * Gets the position of the window specified by `handle`, relative to the top-left corner of the screen. If no247 * handle is specified, the position of the currently focused window is retrieved.248 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/window/:windowHandle/position249 *250 * @property {function(x:number, y:number, handle:string=):PromisedWebDriver} setWindowPosition251 * Sets the position of the window specified by `handle`, relative to the top-left corner of the screen. If no252 * handle is specified, the position of the currently focused window is set.253 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/window/:windowHandle/position254 *255 * @property {function():PromisedWebDriver} forward256 * Navigates forward in the browser history.257 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/forward258 *259 * @property {function():PromisedWebDriver} back260 * Navigates backwards in the browser history.261 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/back262 *263 * @property {function(milliseconds:number):PromisedWebDriver} setImplicitWaitTimeout264 * Sets the maximum amount of time the remote driver should poll for elements before giving up, in milliseconds.265 * Defaults to 0ms (give up immediately).266 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/timeouts/implicit_wait267 *268 * @property {function(milliseconds:number):PromisedWebDriver} setAsyncScriptTimeout269 * Sets the maximum amount of time the remote driver should wait for an asynchronous script to execute its callback270 * before giving up, in milliseconds.271 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/timeouts/async_script272 *273 * @property {function(milliseconds:number):PromisedWebDriver} setPageLoadTimeout274 * Sets the maximum amount of time the remote driver should wait for a page to finish loading before giving up,275 * in milliseconds.276 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/timeouts277 *278 * @property {function():PromisedWebDriver -> string} takeScreenshot279 * Takes a screenshot of the current page. Resolves to a base64-encoded PNG of the current page.280 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/screenshot281 *282 * @property {function(className:string):PromisedWebDriver -> Element} elementByClassName283 * Retrieves the first element matching the given CSS class. If no such element exists, an error is raised.284 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/element285 *286 * @property {function(className:string):PromisedWebDriver -> Element} elementByClassNameIfExists287 * Retrieves the first element matching the given CSS class, or `undefined` if no such element exists.288 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/element289 *290 * @property {function(className:string, timeout:number):PromisedWebDriver} waitForVisibleByClassName291 * Waits until the first element matching the given CSS class becomes visible. If the element does not become292 * visible before the timeout (in milliseconds), an error is raised.293 *294 * @property {function(className:string):PromisedWebDriver -> Array.<Element>} elementsByClassName295 * Retrieves all elements matching the given CSS class.296 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/elements297 *298 * @property {function(selector:string):PromisedWebDriver -> Element} elementByCssSelector299 * Retrieves the first element matching the given CSS selector. If no such element exists, an error is raised.300 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/element301 *302 * @property {function(selector:string):PromisedWebDriver -> Element} elementByCssSelectorIfExists303 * Retrieves the first element matching the given CSS selector, or `undefined` if no such element exists.304 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/element305 *306 * @property {function(selector:string, timeout:number):PromisedWebDriver} waitForVisibleByCssSelector307 * Waits until the first element matching the given CSS selector becomes visible. If the element does not become308 * visible before the timeout (in milliseconds), an error is raised.309 *310 * @property {function(selector:string):PromisedWebDriver -> Array.<Element>} elementsByCssSelector311 * Retrieves all elements matching the given CSS selector.312 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/elements313 *314 * @property {function(id:string):PromisedWebDriver -> Element} elementById315 * Retrieves the first element matching the given ID. If no such element exists, an error is raised.316 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/element317 *318 * @property {function(id:string):PromisedWebDriver -> Element} elementByIdIfExists319 * Retrieves the first element matching the given ID, or `undefined` if no such element exists.320 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/element321 *322 * @property {function(id:string, timeout:number):PromisedWebDriver} waitForVisibleById323 * Waits until the first element matching the given ID becomes visible. If the element does not become324 * visible before the timeout (in milliseconds), an error is raised.325 *326 * @property {function(id:string):PromisedWebDriver -> Array.<Element>} elementsById327 * Retrieves all elements matching the given ID.328 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/elements329 *330 * @property {function(name:string):PromisedWebDriver -> Element} elementByName331 * Retrieves the first element matching the given HTML name attribute. If no such element exists, an error is332 * raised.333 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/element334 *335 * @property {function(name:string):PromisedWebDriver -> Element} elementByNameIfExists336 * Retrieves the first element matching the given HTML name attribute, or `undefined` if no such element exists.337 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/element338 *339 * @property {function(name:string, timeout:number):PromisedWebDriver} waitForVisibleByName340 * Waits until the first element matching the given HTML name attribute becomes visible. If the element does not341 * become visible before the timeout (in milliseconds), an error is raised.342 *343 * @property {function(name:string):PromisedWebDriver -> Array.<Element>} elementsByName344 * Retrieves all elements matching the given HTML name attribute.345 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/elements346 *347 * @property {function(linkText:string):PromisedWebDriver -> Element} elementByLinkText348 * Retrieves the first link element (`<a>`) whose text contents exactly match the given text. If no such element349 * exists, an error is raised.350 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/element351 *352 * @property {function(linkText:string):PromisedWebDriver -> Element} elementByLinkTextIfExists353 * Retrieves the first link element (`<a>`) whose text contents exactly match the given text, or `undefined` if no354 * such element exists.355 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/element356 *357 * @property {function(linkText:string, timeout:number):PromisedWebDriver} waitForVisibleByLinkText358 * Waits until the first link element (`<a>`) whose text contents exactly match the given text becomes visible. If359 * the element does not become visible before the timeout (in milliseconds), an error is raised.360 *361 * @property {function(linkText:string):PromisedWebDriver -> Array.<Element>} elementsByLinkText362 * Retrieves all link elements (`<a>`) whose text contents exactly match the given text.363 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/elements364 *365 * @property {function(linkText:string):PromisedWebDriver -> Element} elementByPartialLinkText366 * Retrieves the first link element (`<a>`) whose text contents contain the given text. If no such element367 * exists, an error is raised.368 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/element369 *370 * @property {function(linkText:string):PromisedWebDriver -> Element} elementByPartialLinkTextIfExists371 * Retrieves the first link element (`<a>`) whose text contents contain the given text, or `undefined` if no372 * such element exists.373 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/element374 *375 * @property {function(linkText:string, timeout:number):PromisedWebDriver} waitForVisibleByPartialLinkText376 * Waits until the first link element (`<a>`) whose text contents contain the given text becomes visible. If the377 * element does not become visible before the timeout (in milliseconds), an error is raised.378 *379 * @property {function(linkText:string):PromisedWebDriver -> Array.<Element>} elementsByPartialLinkText380 * Retrieves all link elements (`<a>`) whose text contents contain the given text.381 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/elements382 *383 * @property {function(tagName:string):PromisedWebDriver -> Element} elementByTagName384 * Retrieves the first element with the given tag name. If no such element exists, an error is raised.385 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/element386 *387 * @property {function(tagName:string):PromisedWebDriver -> Element} elementByTagNameIfExists388 * Retrieves the first element with the given tag name, or `undefined` if no such element exists.389 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/element390 *391 * @property {function(tagName:string, timeout:number):PromisedWebDriver} waitForVisibleByTagName392 * Waits until the first element matching the given tag name becomes visible. If the element does not become393 * visible before the timeout (in milliseconds), an error is raised.394 *395 * @property {function(tagName:string):PromisedWebDriver -> Array.<Element>} elementsByTagName396 * Retrieves all elements with the given tag name.397 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/elements398 *399 * @property {function(selector:string):PromisedWebDriver -> Element} elementByXPath400 * Retrieves the first element matching the given XPath selector. If no such element exists, an error is raised.401 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/element402 *403 * @property {function(selector:string):PromisedWebDriver -> Element} elementByXPathIfExists404 * Retrieves the first element matching the given XPath selector, or `undefined` if no such element exists.405 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/element406 *407 * @property {function(selector:string, timeout:number):PromisedWebDriver} waitForVisibleByXPath408 * Waits until the first element matching the given XPath selector becomes visible. If the element does not become409 * visible before the timeout (in milliseconds), an error is raised.410 *411 * @property {function(selector:string):PromisedWebDriver -> Array.<Element>} elementsByXPath412 * Retrieves all elements matching the given XPath selector.413 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/elements414 *415 * @property {function(element:Element=):PromisedWebDriver -> string} getTagName416 * Retrieves the tag name of the given element. If no element is provided explicitly, the last stored context417 * element will be used.418 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/element/:id/name419 *420 * @property {function(element:Element=, name:string):PromisedWebDriver -> ?string} getAttribute421 * Retrieves the value of the given attribute. If no element is provided explicitly, the last stored context422 * element will be used.423 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/element/:id/attribute/:name424 *425 * @property {function(element:Element=):PromisedWebDriver -> boolean} isDisplayed426 * Determines if an element is currently being displayed. If no element is provided explicitly, the last stored427 * context element will be used.428 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/element/:id/displayed429 *430 * @property {function(element:Element=):PromisedWebDriver -> boolean} isEnabled431 * Determines if an element is currently enabled. If no element is provided explicitly, the last stored context432 * element will be used.433 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/element/:id/enabled434 *435 * @property {function(element:Element=):PromisedWebDriver} clickElement436 * Moves the pointer to an element and clicks on it. If no element is provided explicitly, the last stored context437 * element will be used.438 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/element/:id/click439 *440 * @property {function(element:Element=, ):PromisedWebDriver} click441 * Moves the pointer to an element and clicks on it. If no element is provided explicitly, the last stored context442 * element will be used.443 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/element/:id/click444 *445 * @property {function(element:Element=, propertyName:string):PromisedWebDriver -> string} getComputedCss446 * Retrieves the value of the CSS property given in `propertyName`. Note that `propertyName` should be specified447 * using the CSS-style property name, not the JavaScript-style property name (e.g. `background-color` instead of448 * `backgroundColor`). If no element is provided explicitly, the last stored context element will be used.449 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/element/:id/css/:propertyName450 *451 * @property {function(element:Element=, otherElement:Element):PromisedWebDriver -> boolean} equalsElement452 * Determines whether or not the two elements refer to the same DOM node. If no element is provided explicitly,453 * the last stored context element will be used.454 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/element/:id/equals/:other455 *456 * @property {function(element:Element=, otherElement:Element):PromisedWebDriver -> boolean} equals457 * Determines whether or not the two elements refer to the same DOM node. If no element is provided explicitly,458 * the last stored context element will be used.459 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/element/:id/equals/:other460 *461 * @property {function(xspeed:number, yspeed:number):PromisedWebDriver} flick462 * Performs a touch flick gesture at the given initial speed in pixels per second.463 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#session/:sessionId/touch/flick464 *465 * @property {function(element:Element=, xoffset:number, yoffset:number, speed:number):PromisedWebDriver} flick466 * Performs a touch flick gesture starting at the given element and moving to the point at `xoffset,yoffset`467 * relative to the centre of the given element at `speed` pixels per second. If no element is provided explicitly,468 * the last stored context element will be used.469 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#session/:sessionId/touch/flick470 *471 * @property {function(element:Element=, xoffset:number=, yoffset:number=):PromisedWebDriver} moveTo472 * Moves the pointer to the centre of the given element. If `xoffset` and `yoffset` are provided, move to that473 * point relative to the top-left corner of the given element instead. If no element is provided explicitly,474 * the last stored context element will be used.475 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/moveto476 *477 * @property {function(button:number=):PromisedWebDriver} buttonDown478 * Press and hold a pointer button (i.e. mouse button). This method uses magic numbers for the button argument:479 *480 * * 0 corresponds to left button481 * * 1 corresponds to middle button482 * * 2 corresponds to right button483 *484 * If a button is not specified, it defaults to the left button.485 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/buttondown486 *487 * @property {function(button:number=):PromisedWebDriver} buttonUp488 * Release a held pointer button (i.e. mouse button). This method uses magic numbers for the button argument:489 *490 * * 0 corresponds to left button491 * * 1 corresponds to middle button492 * * 2 corresponds to right button493 *494 * If a button is not specified, it defaults to the left button.495 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/buttonup496 *497 * @property {function():PromisedWebDriver} doubleclick498 * Performs a double-click at the pointer's current position.499 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/doubleclick500 *501 * @property {function(element:Element=, keys:string):PromisedWebDriver} type502 * Send a series of keystrokes to the given element. Non-text keys can be typed by using special Unicode PUA503 * values; see the protocol documentation for more information. When using `type`, the entire operation is atomic,504 * and any modifier keys set by the command string are implicitly released. If no element is provided explicitly,505 * the last stored context element will be used.506 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/element/:id/value507 *508 * @property {function(keys:string):PromisedWebDriver} keys509 * Send a series of keystrokes to the browser. Non-text keys can be typed by using special Unicode PUA values;510 * see the protocol documentation for more information. When using `keys`, modifier keys set and not released511 * will persist beyond the end of the command to enable testing of e.g. mouse actions while holding down modifier512 * keys.513 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/keys514 *515 * @property {function(element:Element=):PromisedWebDriver} submit516 * Submits the given form element. If no element is provided explicitly, the last stored context element will be517 * used.518 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/element/:id/submit519 *520 * @property {function(element:Element=):PromisedWebDriver} clear521 * Clears the content of a given `<textarea>` or `<input type="text">` element. If no element is provided522 * explicitly, the last stored context element will be used.523 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/element/:id/clear524 *525 * @property {function():PromisedWebDriver -> string} title526 * Retrieves the current title of the page.527 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/title528 *529 * @property {function():PromisedWebDriver -> string} source530 * Retrieves the HTML source for the currently loaded page.531 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/source532 *533 * @property {function(element:Element=):PromisedWebDriver -> string} text534 * Retrieves the currently visible text within the element. If no element is provided explicitly, the last stored535 * context element will be used.536 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/element/:id/text537 *538 * @property {function():PromisedWebDriver -> string} alertText539 * Retrieves the text of the currently displayed JavaScript alert, confirm, or prompt dialog. If no dialog exists540 * at the time this method is called, an error is raised.541 * Note that `alertText` may not be supported by all Selenium drivers.542 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/alert_text543 *544 * @property {function(element:Element=, keys:string):PromisedWebDriver} alertKeys545 * Send a series of keystrokes to an open prompt dialog. If no dialog exists at the time this method is called,546 * an error is raised. See {@link keys} for information on valid keys arguments.547 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/alert_text548 *549 * @property {function():PromisedWebDriver} acceptAlert550 * Accepts the currently displayed dialog. Usually equivalent to clicking the 'OK' button. If no dialog exists551 * at the time this method is called, an error is raised.552 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/accept_alert553 *554 * @property {function():PromisedWebDriver} dismissAlert555 * Dismisses the currently displayed dialog. Equivalent to clicking the 'Cancel' button on confirm and prompt556 * dialogs, and the 'OK' button on alert dialogs. If no dialog exists at the time this method is called, an error557 * is raised.558 *559 * @property {function():PromisedWebDriver -> Element} active560 * Retrieves the currently focused element.561 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/element/active562 *563 * @property {function():PromisedWebDriver -> string} url564 * Retrieves the current browser URL.565 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/url566 *567 * @property {function():PromisedWebDriver -> Array.<{ name:string, value:string, =path:string, =domain:string, =secure:string, =expiry:string }>} allCookies568 * Retrieves all cookies set on the current page.569 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/cookie570 *571 * @property {function(cookie:{ name:string, value:string, =path:string, =domain:string, =secure:string, =expiry:string }):PromisedWebDriver} setCookie572 * Sets a cookie for the current page.573 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/cookie574 *575 * @property {function():PromisedWebDriver} deleteAllCookies576 * Deletes all cookies set on the current page.577 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#DELETE_/session/:sessionId/cookie578 *579 * @property {function(name:string):PromisedWebDriver} deleteCookie580 * Deletes a cookie with the given name from the current page.581 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#DELETE_/session/:sessionId/cookie/:name582 *583 * @property {function():PromisedWebDriver -> string} getOrientation584 * Retrieves the current device orientation. One of 'LANDSCAPE', 'PORTRAIT'.585 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/orientation586 *587 * @property {function(orientation:string):PromisedWebDriver} setOrientation588 * Sets the current device orientation. One of 'LANDSCAPE', 'PORTRAIT'.589 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/orientation590 *591 * @property {function(key:string, value:string):PromisedWebDriver} setLocalStorageKey592 * Sets an item in local storage.593 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/local_storage594 *595 * @property {function(key:string):PromisedWebDriver -> string} getLocalStorageKey596 * Retrieves an item from local storage.597 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/local_storage/key/:key598 *599 * @property {function(key:string):PromisedWebDriver} removeLocalStorageKey600 * Removes an item from local storage.601 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#DELETE_/session/:sessionId/local_storage/key/:key602 *603 * @property {function():PromisedWebDriver} clearLocalStorage604 * Removes all data from local storage for the current page.605 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#DELETE_/session/:sessionId/local_storage606 *607 * @property {function(element:Element=):PromisedWebDriver -> { x:number, y:number }} getLocation608 * Gets the position of an element on the page. If no element is provided explicitly, the last stored context609 * element will be used.610 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/element/:id/location611 *612 * @property {function(element:Element=):PromisedWebDriver -> { width:number, height:number }} getSize613 * Gets the dimensions of an element on the page. If no element is provided explicitly, the last stored context614 * element will be used.615 * http://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/element/:id/size616 *617 * @property {function():PromisedWebDriver} end618 * Removes the last element from the stack of stored context elements, just like jQuery's `end` method.619 * For example:620 *621 * <pre>622 * remote.elementById('foo')623 * .elementById('bar')624 * // this will click on the element `bar`625 * .click()626 * // this will stop future methods from interacting on `bar`627 * .end()628 * // this will click on the element `foo`629 * .click()630 * // this will stop future methods from interacting on `foo`631 * .end();632 * </pre>633 *634 * @property {function(milliseconds:number)} wait635 * Waits for the given period of time, in milliseconds, before executing the next command.636 *637 * @property {function(function(value), function(error:Error)):PromisedWebDriver} then638 * Standard Promises/A `then` callback registration method. Call this immediately after a method that normally639 * returns a value to retrieve and interact with the value returned by that call. For example:640 *641 * <pre>642 * remote.elementById('foo')643 * .text()644 * .then(function (text) {645 * // `text` contains the text from the element `foo`646 * });647 * </pre>648 *649 * For more information on promises, please see http://dojotoolkit.org/documentation/tutorials/1.9/promises/.650 *651 * Note that as of Intern 1.1, attempting to add new commands to the current remote instance from within a `then`652 * callback will result in a deadlock. This will be addressed in a future version of Intern.653 *654 * @property {function(function(error:Error)):PromisedWebDriver} otherwise655 * Convenience function equivalent to calling `remote.then(null, callback)`.656 *657 * @property {function(function(=error:Error)):PromisedWebDriver} always658 * Convenience function equivalent to calling `remote.then(callback, callback)`.659 *660 * @property {function()} cancel661 * Cancels all outstanding remote requests and rejects the current promise chain.662 *663 * @property {function(code:string, timeout:number, =pollFrequency:number):PromisedWebDriver} waitForCondition664 * Polls the remote browser using `eval` until the code provided in `code` returns a truthy value. If the code does665 * not evaluate positively within `timeout` milliseconds (default: 1000), an error is raised. An optional666 * frequency for polling may also be provided (default: 100).667 *668 * `waitForConditionInBrowser` should be preferred as long as all browsers under test support the `executeAsync`669 * method.670 *671 * @property {function(code:string, timeout:number, =pollFrequency:number):PromisedWebDriver} waitForConditionInBrowser672 * Tells the remote browser to poll using `executeAsync` until the code provided in `code` returns a truthy value.673 * If the code does not evaluate positively within `timeout` milliseconds (default: 1000), an error is raised. An674 * optional frequency for polling may also be provided (default: 100).675 *676 * Note that `executeAsync` may not be supported by all Selenium drivers, in which case `waitForCondition` should677 * be used instead.678 *679 * @property haltChain680 * Do not use this method. It is not relevant to PromisedWebDriver.681 * @property pauseChain682 * Do not use this method. It is not relevant to PromisedWebDriver.683 * @property chain684 * Do not use this method. It is not relevant to PromisedWebDriver.685 * @property next686 * Do not use this method. It is not relevant to PromisedWebDriver.687 * @property queueAdd688 * Do not use this method. It is not relevant to PromisedWebDriver.689 * @property safeEval690 * Do not use this method. Use `eval` instead.691 * @property safeExecute692 * Do not use this method. Use `execute` instead.693 * @property safeExecuteAsync694 * Do not use this method. Use `executeAsync` instead.695 * @property windowSize696 * Do not use this method. Use `setWindowSize` instead.697 * @property altSessionCapabilities698 * Do not use this method. Use `sessionCapabilities` instead.699 * @property setHTTPInactivityTimeout700 * Do not use this method. It is not documented. (It is a timeout for the underlying HTTP request code.)701 * @property setWaitTimeout702 * Do not use this method. Use `setImplicitWaitTimeout` instead.703 * @property element704 * Do not use this method. Use the more specific `elementBy*` methods instead.705 * @property elementOrNull706 * Do not use this method. Use the more specific `elementBy*IfExists` methods instead.707 * @property elementIfExists708 * Do not use this method. Use the more specific `elementBy*IfExists` methods instead.709 * @property elements710 * Do not use this method. Use the more specific `elementsBy*` methods instead.711 * @property hasElement712 * Do not use this method. Use the `elementBy*IfExists` methods instead.713 * @property waitForElement714 * Do not use this method. Set `setImplicitWaitTimeout` and use the `elementBy*` methods instead.715 * @property waitForVisible716 * Do not use this method. Use the more specific `waitForVisibleBy*` methods instead.717 * @property *OrNull718 * Do not use these methods. Use `elementBy*IfExists` instead.719 * @property hasElement*720 * Do not use these methods. Set `setImplicitWaitTimeout` and use the `elementBy*` methods instead.721 * @property waitForElement*722 * Do not use these methods. Set `setImplicitWaitTimeout` and use the `elementBy*` methods instead.723 * @property *ByCss724 * Do not use these methods. Use the `*ByCssSelector` methods instead.725 * @property displayed726 * Do not use this method. Use `isDisplayed` instead.727 * @property enabled728 * Do not use this method. Use `isEnabled` instead.729 * @property getValue730 * Do not use this method. Use `getAttribute('value')` instead.731 * @property getComputedCSS732 * Do not use this method. Use `getComputedCss` instead.733 * @property textPresent734 * Do not use this method. Use `text` instead.735 * @property isVisible736 * Do not use this method. Use `isDisplayed` instead.737 * @property getPageIndex738 * Do not use this method. It is not documented.739 */740 function PromisedWebDriver(config, desiredEnvironment) {741 this._wd = wd.remote(config);742 this._desiredEnvironment = desiredEnvironment;743 this._context = [];744 }745 // WebDriver.prototype exposes all method names, including element methods, except for the 'equals' element746 // method747 // TODO: Do not expose methods that are marked as "Do not use" in the documentation above, then remove the748 // documentation.749 Object.keys(WebDriver.prototype).concat([ 'equals' ]).forEach(function (key) {750 // The original object is indirectly extended by adapting individual methods in order to ensure that any751 // calls by the original WebDriver object to its own methods are not broken by an unexpectedly different752 // interface753 var wrappedFunction = util.adapt(WebDriver.prototype[key], '_wd');754 // Upgrade init so that it can be called with no arguments and use desired environment data provided by755 // the constructor756 if (key === 'init') {757 wrappedFunction = (function (wrappedFunction) {758 return function (desiredEnvironment) {759 return wrappedFunction.call(this, desiredEnvironment || this._desiredEnvironment);760 };761 })(wrappedFunction);762 }763 // Always retrieve code coverage data before navigating to a new URL764 else if (key === 'get' || key === 'quit') {765 wrappedFunction = (function (wrappedFunction) {766 return function () {767 var self = this,768 args = Array.prototype.slice.call(arguments, 0);769 // If someone uses require.toUrl with a functional test, the path will be an absolute filesystem770 // path to the file, but it needs to be a URL to the proxy to work on the remote system771 if (key === 'get' && !/^https?:/.test(args[0])) {772 // oh also by the way baseUrl might not be normalized ha ha ha ha.773 args[0] = this.proxyUrl + args[0].slice(pathUtils.normalize(global.require.baseUrl).length);774 }775 var dfd = new Deferred();776 // Since we are in the middle of a chained call, we must do a low-level call to the wd object;777 // if we try to just call PromisedWebDriver methods directly, the chain will be stalled permanently778 // waiting for the `get` call to complete because the PWD methods cannot run until `get` completes779 // but `get` will not be able to complete without the subsequent PWD methods780 this._wd.execute('return typeof __internCoverage !== "undefined" && (' + stringify + ')(__internCoverage)', function (error, returnValue) {781 if (error) {782 dfd.reject(error);783 return;784 }785 // returnValue might be falsy on a page with no coverage data, so don't try to publish coverage786 // results to prevent things from breaking787 returnValue && topic.publish('/coverage', self.sessionId, JSON.parse(returnValue));788 wrappedFunction.apply(self, args).then(dfd.resolve.bind(dfd), dfd.reject.bind(dfd));789 });790 return dfd.promise;791 };792 })(wrappedFunction);793 }794 // Allow real functions to be passed directly to execute795 else if (key === 'execute' || key === 'safeExecute') {796 wrappedFunction = (function (wrappedFunction) {797 return function () {798 var args = Array.prototype.slice.call(arguments, 0);799 if (typeof args[0] === 'function') {800 args[0] = 'return (' + args[0] + ').apply(this, arguments);';801 }802 return wrappedFunction.apply(this, args);803 };804 })(wrappedFunction);805 }806 if (/* not a private interface */ key.charAt(0) !== '_') {807 PromisedWebDriver.prototype[key] = function () {808 var self = this,809 args = Array.prototype.slice.call(arguments, 0);810 this._lastPromise = when(this._lastPromise).then(function () {811 // Methods that might interact on elements should be modified to use the current context element812 // as the context object813 if (elementContextMethods[key] && self._context.length) {814 self = self._context[self._context.length - 1];815 wrappedFunction = util.adapt(self[key]);816 }817 // Methods that might accept an element argument should be modified to use the current context818 // element as the argument819 else if (elementArgumentMethods[key] && self._context.length) {820 args.unshift(self._context[self._context.length - 1]);821 }822 return wrappedFunction.apply(self, args);823 });824 this._lastPromise = this._lastPromise.then(function (lastReturnValue) {825 // Methods that get elements need to provide the element as context for the next call to the fluid826 // interface, so users can type e.g. `remote.elementById('foo').clickElement()` and it works as827 // expected.828 if (lastReturnValue instanceof Element) {829 self._context.push(lastReturnValue);830 }831 // We should also check to see if a DOM element is returned from remote execution, e.g. `execute`832 // or `safeExecute`. If this is the case, we should use this element as the context for the next833 // call to maintain the fluid interface described above.834 else if (lastReturnValue && lastReturnValue.ELEMENT) {835 lastReturnValue = new Element(lastReturnValue.ELEMENT, self._wd);836 self._context.push(lastReturnValue);837 }838 return lastReturnValue;839 });840 return this;841 };842 }843 });844 /**845 * Ends a context chain.846 * @param {=number} numContextsToPop The number of element contexts to pop. Defaults to 1.847 */848 PromisedWebDriver.prototype.end = function (numContextsToPop) {849 var self = this;850 this._lastPromise = when(this._lastPromise).then(function (value) {851 numContextsToPop = numContextsToPop || 1;852 while (numContextsToPop-- && self._context.length) {853 self._context.pop();854 }855 return value;856 });857 return this;858 };859 /**860 * Waits milliseconds before performing the next command.861 * @param {number} waitMs Milliseconds to wait.862 */863 PromisedWebDriver.prototype.wait = function (waitMs) {864 this._lastPromise = when(this._lastPromise).then(function () {865 var dfd = new Deferred();866 setTimeout(function () {867 dfd.resolve();868 }, waitMs);869 return dfd.promise;870 });871 return this;872 };873 PromisedWebDriver.prototype.then = function (callback, errback) {874 var self = this,875 dfd = new Deferred();876 function fixCallback(callback) {877 if (typeof callback !== 'function') {878 return callback;879 }880 return function () {881 self._lastPromise = undefined;882 try {883 var returnValue = callback.apply(this, arguments);884 when(self._lastPromise || returnValue).then(function () {885 dfd.resolve(returnValue);886 }, function (error) {887 dfd.reject(error);888 });889 }890 catch (error) {891 dfd.reject(error);892 }893 return dfd.promise;894 };895 }896 this._lastPromise = this._lastPromise.then(fixCallback(callback), fixCallback(errback));897 return this;898 };899 PromisedWebDriver.prototype.otherwise = function (errback) {900 return this.then(null, errback);901 };902 PromisedWebDriver.prototype.always = function (callback) {903 return this.then(callback, callback);904 };905 /**906 * Cancels the execution of the remaining chain of commands for this driver.907 */908 PromisedWebDriver.prototype.cancel = function () {909 this._lastPromise && this._lastPromise.cancel.apply(this._lastPromise, arguments);910 return this;911 };912 /**913 * Cancels the execution of the remaining chain of commands for this driver and dereferences the old promise chain.914 */915 PromisedWebDriver.prototype.reset = function () {916 this.cancel();917 this._lastPromise = undefined;918 this._context = [];919 return this;920 };921 /**922 * Sends a no-op command to the remote server on an interval to prevent.923 *924 * @param delay925 * Amount of time to wait between heartbeats.926 */927 PromisedWebDriver.prototype.setHeartbeatInterval = function (/**number*/ delay) {928 this._heartbeatIntervalHandle && this._heartbeatIntervalHandle.remove();929 if (delay) {930 // A heartbeat command is sent immediately when the interval is set because it is unknown how long ago931 // the last command was sent and it simplifies the implementation by requiring only one call to932 // `setTimeout`933 var self = this;934 (function sendHeartbeat() {935 var timeoutId,936 cancelled = false,937 startTime = Date.now();938 self._heartbeatIntervalHandle = {939 remove: function () {940 cancelled = true;941 clearTimeout(timeoutId);942 }943 };944 // The underlying `wd` object is accessed directly to bypass pending commands on the promise chain.945 // `url` is used because some more appropriate meta-commands like `status` do not prevent Sauce Labs946 // from timing out947 self._wd.url(function () {948 if (!cancelled) {949 timeoutId = setTimeout(sendHeartbeat, delay - (Date.now() - startTime));950 }951 });952 })();953 }954 };955 /**956 * This interface provides a mechanism for creating a remote WebDriver instance that uses Promises/A instead of957 * Node.js callbacks to provide more expressive tests.958 */959 return {960 /**961 * Creates a new Promises/A-based remote WebDriver instance.962 *963 * @param {{ host: string, port: number, username: ?string, accessKey: ?string }} config964 * Configuration for connection to the remote WebDriver server. The username and accessKey keys are used965 * for integration with Sauce Labs.966 * @returns {PromisedWebDriver}967 */968 remote: function (config, desiredEnvironment) {969 return new PromisedWebDriver(config, desiredEnvironment);970 }971 };...
Appium JS commands.js
Source:Appium JS commands.js
...386// webdriver.io example387driver.moveTo(element);388driver.buttonDown();389driver.moveTo(element, 10, 10);390driver.buttonUp();391// wd example392await driver.moveTo(element);393await driver.buttonDown();394await driver.moveTo(element, 10, 10);395await driver.buttonUp();396//Perform a chain or multiple chains of keyboard and pointer (touch, mouse, stylus) actions397// webdriver.io example398// Example: expressing a 1-second pinch-and-zoom399// with a 500ms wait after the fingers first touch:400driver.performActions([{401 "type": "pointer",402 "id": "finger1",403 "parameters": {"pointerType": "touch"},404 "actions": [405 {"type": "pointerMove", "duration": 0, "x": 100, "y": 100},406 {"type": "pointerDown", "button": 0},407 {"type": "pause", "duration": 500},408 {"type": "pointerMove", "duration": 1000, "origin": "pointer", "x": -50, "y": 0},409 {"type": "pointerUp", "button": 0}...
actions.js
Source:actions.js
...192 .then(function(element) {193 return _this._driver.moveTo(element);194 })195 .then(function() {196 return _this._driver.buttonUp(button);197 });198 });199 return this;200 },201 mouseMove: function(element, offset) {202 if (isInvalidElement(element)) {203 throw new TypeError('.mouseMove() must receive valid element or CSS selector');204 }205 var _this = this;206 if (offset) {207 if ('x' in offset && typeof offset.x !== 'number') {208 throw new TypeError('offset.x should be a number');209 }210 if ('y' in offset && typeof offset.y !== 'number') {...
selenium.vows.js
Source:selenium.vows.js
...28 driver.elementByIdOrNull(elementId, function(err, element){29 driver.moveTo(element, 300, 300, function(err){30 driver.buttonDown(function(){31 driver.moveTo(element, 10, 10, function(err){32 driver.buttonUp(function(err){33 driver.eval('$("#'+ elementId +'").data("kinetic-settings").velocity', function(err, velocity){34 cb(driver, err, velocity);35 });36 // driver.waitForConditionInBrowser('$("#wrapper").data("kinetic-settings").velocity === 0', 10000, function(err, stopped){37 // console.log(arguments);38 // });39 });40 });41 });42 });43 });44 }45 var allTests = {46 'page has correct title': {...
Using AI Code Generation
1const wdio = require("webdriverio");2const assert = require("assert");3const opts = {4 capabilities: {5 },6};7const client = wdio.remote(opts);8 .init()9 .then(() => {10 .element("~buttonTest")11 .then((element) => {12 return element.click();13 })14 .then(() => {15 return client.pause(1000);16 })17 .then(() => {18 return client.element("~buttonTest");19 })20 .then((element) => {21 return element.click();22 })23 .then(() => {24 return client.pause(1000);25 })26 .then(() => {27 return client.element("~buttonTest");28 })29 .then((element) => {30 return element.click();31 })32 .then(() => {33 return client.pause(1000);34 })35 .then(() => {36 return client.element("~buttonTest");37 })38 .then((element) => {39 return element.click();40 })41 .then(() => {42 return client.pause(1000);43 })44 .then(() => {45 return client.element("~buttonTest");46 })47 .then((element) => {48 return element.click();49 })50 .then(() => {51 return client.pause(1000);52 })53 .then(() => {54 return client.element("~buttonTest");55 })56 .then((element) => {57 return element.click();58 })59 .then(() => {60 return client.pause(1000);61 })62 .then(() => {63 return client.element("~buttonTest");64 })65 .then((element) => {66 return element.click();67 })68 .then(() => {69 return client.pause(1000);70 })71 .then(() => {72 return client.element("~buttonTest");73 })74 .then((element) => {75 return element.click();76 })77 .then(() => {78 return client.pause(1000);
Using AI Code Generation
1var wd = require('wd');2driver.init({3}).then(function(){4 driver.elementById("buttonTestCD").click();5 driver.sleep(5000);6 driver.buttonUp(0);7 driver.sleep(5000);8 driver.quit();9});10driver.quit();11[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:click","params":{"elementId":"4"}}12[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"4"}}13[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"value":true,"status":0}14[debug] Responding to client with success: {"status":0,"value":true,"sessionId":"3d6b2a6b-0f3d-4f8a-8b6d-0f7c3e1d3c06"}15[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"shutdown"}16[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"value":"OK, shutting down
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var appium = require('appium');3var chai = require('chai');4var chaiAsPromised = require('chai-as-promised');5var chromedriver = require('appium-chromedriver');6var doctor = require('appium-doctor');7var selendroid = require('appium-selendroid-driver');8var xcuitest = require('appium-xcuitest-driver');9var driver = new webdriver.Builder()10 .withCapabilities(webdriver.Capabilities.android())11 .build();12 driver.buttonUp('keycode');
Using AI Code Generation
1driver.buttonUp("left", sessionId, function(err, res) {2 if (err) {3 console.log(err);4 } else {5 console.log(res);6 }7});8driver.buttonUp("right", sessionId, function(err, res) {9 if (err) {10 console.log(err);11 } else {12 console.log(res);13 }14});15driver.buttonUp("up", sessionId, function(err, res) {16 if (err) {17 console.log(err);18 } else {19 console.log(res);20 }21});22driver.buttonUp("down", sessionId, function(err, res) {23 if (err) {24 console.log(err);25 } else {26 console.log(res);27 }28});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!