Best JavaScript code snippet using appium
actions.js
Source:actions.js
...121 var _this = this;122 this._pushAction(this.click, function mouseDown() {123 return _this._findElement(element)124 .then(function(element) {125 return _this._driver.moveTo(element);126 })127 .then(function() {128 return _this._driver.click(button);129 });130 });131 return this;132 },133 doubleClick: function(element, button) {134 if (isInvalidMouseButton(button)) {135 throw new TypeError('Mouse button should be 0 (left), 1 (right) or 2 (middle)');136 }137 if (isInvalidElement(element)) {138 throw new TypeError('.doubleClick() must receive valid element or CSS selector');139 }140 var _this = this;141 this._pushAction(this.doubleClick, function() {142 return _this._findElement(element)143 .then(function() {144 return _this._driver.moveTo(element);145 })146 .then(function() {147 return _this._driver.doubleClick(element, button);148 });149 });150 return this;151 },152 dragAndDrop: function(element, dragTo) {153 if (isInvalidElement(element)) {154 throw new TypeError('.dragAndDrop() "element" argument should be valid element or CSS selector');155 }156 if (isInvalidElement(element)) {157 throw new TypeError('.dragAndDrop() "dragTo" argument should be valid element or CSS selector');158 }159 return this.mouseDown(element)160 .mouseMove(dragTo)161 .mouseUp();162 },163 mouseDown: function(element, button) {164 if (isInvalidMouseButton(button)) {165 throw new TypeError('Mouse button should be 0 (left), 1 (right) or 2 (middle)');166 }167 if (isInvalidElement(element)) {168 throw new TypeError('.mouseDown() must receive valid element or CSS selector');169 }170 var _this = this;171 this._pushAction(this.mouseDown, function mouseDown() {172 return _this._findElement(element)173 .then(function(element) {174 return _this._driver.moveTo(element);175 })176 .then(function() {177 return _this._driver.buttonDown(button);178 });179 });180 return this;181 },182 mouseUp: function(element, button) {183 if (isInvalidMouseButton(button)) {184 throw new TypeError('Mouse button should be 0 (left), 1 (right) or 2 (middle)');185 }186 if (isInvalidElement(element)) {187 throw new TypeError('.mouseUp() must receive valid element or CSS selector');188 }189 var _this = this;190 this._pushAction(this.mouseUp, function mouseDown() {191 return _this._findElement(element)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') {211 throw new TypeError('offset.y should be a number');212 }213 }214 this._pushAction(this.mouseMove, function mouseMove() {215 return _this._findElement(element).then(function(element) {216 if (offset) {217 return _this._driver.moveTo(element, offset.x, offset.y);218 }219 return _this._driver.moveTo(element);220 });221 });222 return this;223 },224 sendKeys: function(element, keys) {225 var _this = this,226 action;227 if (typeof keys === 'undefined' || keys === null) {228 keys = element;229 action = function sendKeys() {230 return _this._driver.keys(keys);231 };232 } else {233 if (isInvalidElement(element)) {...
automaticInteraction2.js
Source:automaticInteraction2.js
1/*2 This object provides a mechanism to simulate user interactions in a sequential way.3 It is inteded to be used on idle time (when user hasn't interacted with the app for a while)4 so that it shows the different features and contents and tries to drag attention.5 It can be useful mostly in public venues such as interactive kiosks in expos, receptions, etc...6*/7var autoDriver = {8 isOn: false,9 init: function() {10 autoDriver.isOn = true;11 autoDriver.stepIndex = 0;12 var cursor = autoDriver.cursor = $("#fakeCursor");13 cursor.css("display", "block");14 autoDriver.steps = [15 // Make sure collapsable menus are visible16 function() {17 pool.toggleList['courses'] = true;18 pool.toggleList['units'] = true;19 pool.toggleList['les'] = true;20 autoDriver.runNextStep();21 },22 function() {23 unSelectObject();24 setTimeout(function() {25 autoDriver.runNextStep();26 }, 200);27 },28 // Tabs showcase29 function() {30 autoDriver.movetoAndClick($("#tabItem_mentalities"), false, null, 1000, 1000);31 },32 function() {33 autoDriver.movetoAndClick($("#tabItem_ecologies"), false, null, 1000, 300);34 },35 function() {36 autoDriver.movetoAndClick($("#tabItem_threads"), false, null, 1000, 300);37 },38 function() {39 autoDriver.movetoAndClick($("#tabItem_grades"), false, null, 1000, 300);40 },41 function() {42 autoDriver.movetoAndClick($("#tabItem_domains"), true, null, 1000, 300);43 },44 function() {45 autoDriver.scrollDown();46 },47 // Drill down hyerarchy to LE48 function() {49 autoDriver.movetoAndClick($('a[db-id="d_1"]'), true);50 }, // Choose Domain Petal 'Cultural History'51 function() {52 autoDriver.movetoAndClick($("a[href='#/course/c_50']"), true);53 }, // Choose COURSE54 function() {55 autoDriver.movetoAndClick($("a[href='#/unit/u_306']"), true);56 }, // Choose UNIT 57 function() {58 autoDriver.movetoAndClick($($(".panelField_les ul li a").get(3)), true);59 }, // move to LE, wait and click 60 // Move mouse canvas, emulate click nowhere61 function() {62 setTimeout(function() {63 cursor.animate({64 left: cW - 400,65 top: 50066 }, 1000, autoDriver.runNextStep)67 }, 1000);68 },69 // wait and unselect70 function() {71 unSelectObject();72 setTimeout(function() {73 autoDriver.runNextStep()74 }, 1000);75 },76 function() {77 autoDriver.movetoAndClick($("#tabItem_threads"), true);78 }, // Threads tab79 function() {80 autoDriver.movetoAndClick($("a[href='#/thread/t_10']"), true);81 }, // Choose Sustainability thread82 function() {83 autoDriver.movetoAndClick($($("a[href='#/le/2096']").get(0)));84 }, // move to first LE, wait and click85 // move to right arrow wait and click86 function() {87 autoDriver.movetoAndClick($("#threadNavArrowRight"));88 },89 function() {90 autoDriver.movetoAndClick($("#threadNavArrowRight"), false, 0, 3000);91 },92 function() {93 autoDriver.movetoAndClick($("#threadNavArrowRight"), false, 0, 3000);94 },95 function() {96 autoDriver.movetoAndClick($("#threadNavArrowRight"), false, 0, 3000);97 },98 function() {99 autoDriver.movetoAndClick($("#threadNavArrowRight"), false, 0, 3000);100 },101 function() {102 autoDriver.movetoAndClick($("#threadNavArrowRight"), false, 0, 3000);103 },104 function() {105 cursor.animate({106 top: "10px",107 left: "10px"108 }, 1000, autoDriver.runNextStep)109 },110 ];111 autoDriver.runNextStep();112 },113 movetoAndClick: function(selector, afterScroll, timeToClick, timeToNext, animationTime) {114 console.log("[AutoPilot]", selector, afterScroll, timeToClick, timeToNext, animationTime);115 if (timeToClick == null) timeToClick = 100;116 if (timeToNext == null) timeToNext = 500;117 if (animationTime == null) animationTime = 1000;118 var el = $(selector);119 var el_pos = el.offset();120 autoDriver.cursor.animate({121 top: el_pos.top + 10,122 left: el_pos.left + 30123 }, animationTime, function() {124 setTimeout(function() {125 el.click();126 setTimeout(function() {127 if (afterScroll)128 autoDriver.scrollDown();129 else130 autoDriver.runNextStep();131 }, timeToNext);132 }, timeToClick);133 });134 },135 scrollDown: function(animationTime) {136 if (animationTime == null) animationTime = 1000;137 //setTimeout( function(){138 $("#panelContainer").animate({139 scrollTop: 300140 }, animationTime, autoDriver.runNextStep);141 //}, 0 );142 },143 runNextStep: function() {144 if (autoDriver.stepIndex >= autoDriver.steps.length) {145 console.log("done auto");146 autoDriver.isOn = false;147 return null; // finished148 }149 var nextFunction = autoDriver.steps[autoDriver.stepIndex];150 autoDriver.stepIndex++;151 nextFunction();152 }...
gesture-specs.js
Source:gesture-specs.js
...129 });130 it('should be able to click on arbitrary x-y elements', async function () {131 let axIdExt = env.IOS8 || env.IOS9 ? "" : ", AAPLButtonViewController";132 let el1 = await driver.findElement('accessibility id', `Buttons${axIdExt}`);133 await driver.moveTo(el1, 10, 10);134 await driver.clickCurrent();135 let el2 = await driver.findElement('xpath', "//UIAElement['SYSTEM (CONTACT ADD)']");136 el2.should.exist;137 });138 });...
automaticInteraction.js
Source:automaticInteraction.js
1/*2 This object provides a mechanism to simulate user interactions in a sequential way.3 It is inteded to be used on idle time (when user hasn't interacted with the app for a while)4 so that it shows the different features and contents and tries to drag attention.5 It can be useful mostly in public venues such as interactive kiosks in expos, receptions, etc...6*/7var autoDriver = 8{9 isOn: false,10 init: function()11 {12 autoDriver.isOn = true;13 autoDriver.stepIndex = 0;14 var cursor = autoDriver.cursor = $("#fakeCursor");15 cursor.css( "display", "block" );16 autoDriver.steps = [17 // Make sure collapsable menus are visible18 function(){ 19 pool.toggleList['courses'] = true;20 pool.toggleList['units'] = true;21 pool.toggleList['les'] = true;22 autoDriver.runNextStep(); 23 }, 24 function(){ 25 unSelectObject();26 setTimeout( function(){27 autoDriver.runNextStep();28 }, 200 ); 29 }, 30 // Tabs showcase31 function(){ autoDriver.movetoAndClick( $("#tabItem_mentalities" ), false, null, 1000, 1000 ); }, 32 function(){ autoDriver.movetoAndClick( $("#tabItem_ecologies" ), false, null, 1000, 300 ); }, 33 function(){ autoDriver.movetoAndClick( $("#tabItem_threads" ), false, null, 1000, 300 ); }, 34 function(){ autoDriver.movetoAndClick( $("#tabItem_grades" ), false, null, 1000, 300 ); }, 35 function(){ autoDriver.movetoAndClick( $("#tabItem_domains" ), true, null, 1000, 300 ); }, 36 function(){ autoDriver.scrollDown( ); },37 38 // Drill down hyerarchy to LE39 function(){ autoDriver.movetoAndClick( $('a[db-id="d_1"]'), true ); }, // Choose Domain Petal 'Cultural History'40 function(){ autoDriver.movetoAndClick( $("a[href='#/course/c_50']"), true ); }, // Choose COURSE41 function(){ autoDriver.movetoAndClick( $("a[href='#/unit/u_306']"), true ); }, // Choose UNIT 42 function(){ autoDriver.movetoAndClick( $( $(".panelField_les ul li a").get(3) ), true ); }, // move to LE, wait and click 43 44 // Move mouse canvas, emulate click nowhere45 function(){46 setTimeout( function(){47 cursor.animate( {left:cW-400, top:500}, 1000, autoDriver.runNextStep )48 }, 1000 );49 }, 50 // wait and unselect51 function(){52 unSelectObject();53 setTimeout( function(){54 autoDriver.runNextStep()55 }, 1000 );56 }, 57 function(){ autoDriver.movetoAndClick( $("#tabItem_threads" ), true ); }, // Threads tab58 function(){ autoDriver.movetoAndClick( $("a[href='#/thread/t_10']"), true ); }, // Choose Sustainability thread59 function(){ autoDriver.movetoAndClick( $( $("a[href='#/le/2096']").get(0) ) ); }, // move to first LE, wait and click60 61 // move to right arrow wait and click62 function(){ autoDriver.movetoAndClick( $("#threadNavArrowRight") ); },63 function(){ autoDriver.movetoAndClick( $("#threadNavArrowRight"), false, 0, 3000 ); },64 function(){ autoDriver.movetoAndClick( $("#threadNavArrowRight"), false, 0, 3000 ); },65 function(){ autoDriver.movetoAndClick( $("#threadNavArrowRight"), false, 0, 3000 ); },66 function(){ autoDriver.movetoAndClick( $("#threadNavArrowRight"), false, 0, 3000 ); },67 function(){ autoDriver.movetoAndClick( $("#threadNavArrowRight"), false, 0, 3000 ); }, 68 69 function(){ cursor.animate( {top:"10px", left:"10px"}, 1000, autoDriver.runNextStep ) },70 ];71 autoDriver.runNextStep();72 }, 73 movetoAndClick: function( selector, afterScroll, timeToClick, timeToNext, animationTime ){74 console.log( "[AutoPilot]", selector, afterScroll, timeToClick, timeToNext, animationTime );75 if( timeToClick == null ) timeToClick = 100;76 if( timeToNext == null ) timeToNext = 500;77 if( animationTime == null ) animationTime = 1000;78 var el = $( selector );79 var el_pos = el.offset();80 autoDriver.cursor.animate( {top:el_pos.top+10, left:el_pos.left+30}, animationTime, function(){81 setTimeout( function(){82 el.click();83 setTimeout( function(){84 if( afterScroll )85 autoDriver.scrollDown();86 else87 autoDriver.runNextStep();88 }, timeToNext );89 }, timeToClick );90 });91 }, 92 scrollDown: function( animationTime ){93 if( animationTime == null ) animationTime = 1000;94 //setTimeout( function(){95 $("#panelContainer").animate( { scrollTop:300 }, animationTime, autoDriver.runNextStep );96 //}, 0 );97 },98 runNextStep: function(){99 if( autoDriver.stepIndex >= autoDriver.steps.length ){100 console.log( "done auto" );101 autoDriver.isOn = false;102 return null; // finished103 }104 var nextFunction = autoDriver.steps[ autoDriver.stepIndex ];105 autoDriver.stepIndex++;106 nextFunction();107 }...
selenium.vows.js
Source:selenium.vows.js
...25 });26 }27 function dragOverElement(driver, elementId, cb){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 = {...
SignatureBezierPath.js
Source:SignatureBezierPath.js
1//@flow2import { lineAverage, lineCreate, linesPerpendicularToLine } from './Perpendicular';3type DrawDriver = {4 moveTo: (x: Float, y: Float) => any,5 lineTo: (x: Float, y: Float) => any,6 quadraticCurveTo: (cpX: Float, cpY: Float, toX: Float, toY: Float) => any,7 bezierCurveTo: (cpX: Float, cpY: Float, cpX2: Float, cpY2: Float, toX: Float, toY: Float) => any,8 arc: (9 cx: Float,10 cy: Float,11 radius: Float,12 startAngle: Float,13 endAngle: Float,14 anticlockwise: Bool15 ) => any,16 closePath: () => any,17};18export class BezierPath {19 static dot(points, graphics: DrawDriver) {20 const { point, weight } = points[0];21 graphics.arc(point[0], point[1], weight, 0, Math.PI * 2, true);22 }23 static line(points, graphics: DrawDriver) {24 const { first, second } = linesPerpendicularToLine(points[0], points[1]);25 graphics.moveTo(first[0][0], first[0][1]);26 graphics.lineTo(second[0][0], second[0][1]);27 graphics.lineTo(second[1][0], second[1][1]);28 graphics.lineTo(first[0][0], first[0][1]);29 graphics.closePath();30 }31 static quadCurve(points, graphics: DrawDriver) {32 const linesAB = linesPerpendicularToLine(points[0], points[1]);33 const linesBC = linesPerpendicularToLine(points[1], points[2]);34 const lineA = linesAB.first;35 const lineB = lineAverage(lineCreate(), linesAB.second, linesBC.first);36 const lineC = linesBC.second;37 graphics.moveTo(lineA[0][0], lineA[0][1]);38 graphics.quadraticCurveTo(lineB[0][0], lineB[0][1], lineC[0][0], lineC[0][1]);39 graphics.lineTo(lineC[1][0], lineC[1][1]);40 graphics.quadraticCurveTo(lineB[1][0], lineB[1][1], lineA[1][0], lineA[1][1]);41 graphics.closePath();42 }43 static bezierCurve(points, graphics: DrawDriver) {44 const linesAB = linesPerpendicularToLine(points[0], points[1]);45 const linesBC = linesPerpendicularToLine(points[1], points[2]);46 const linesCD = linesPerpendicularToLine(points[2], points[3]);47 const lineA = linesAB.first;48 const lineB = lineAverage(lineCreate(), linesAB.second, linesBC.first);49 const lineC = lineAverage(lineCreate(), linesBC.second, linesCD.first);50 const lineD = linesCD.second;51 graphics.moveTo(lineA[0][0], lineA[0][1]);52 graphics.bezierCurveTo(53 lineB[0][0],54 lineB[0][1],55 lineC[0][0],56 lineC[0][1],57 lineD[0][0],58 lineD[0][1]59 );60 graphics.lineTo(lineD[1][0], lineD[1][1]);61 graphics.bezierCurveTo(62 lineC[1][0],63 lineC[1][1],64 lineB[1][0],65 lineB[1][1],66 lineA[1][0],67 lineA[1][1]68 );69 graphics.closePath();70 }71}...
index.js
Source:index.js
1const createDeferred = require('p-defer-es5');2const click = require('./click');3const clickAt = require('./clickAt');4const done = require('./done');5const error = require('./error');6const getLogs = require('./getLogs');7const hover = require('./hover');8const moveTo = require('./moveTo');9const pressAndHold = require('./pressAndHold');10const ready = require('./ready');11const sendAccessKey = require('./sendAccessKey');12const sendDevToolsCommand = require('./sendDevToolsCommand');13const sendKeys = require('./sendKeys');14const sendShiftTab = require('./sendShiftTab');15const sendTab = require('./sendTab');16const snapshot = require('./snapshot');17const upload = require('./upload');18const windowSize = require('./windowSize');19/** RPC object on the Jest side. */20module.exports = function createHost(webDriver) {21 const doneDeferred = createDeferred();22 const readyDeferred = createDeferred();23 // Modifying this map will also requires modifying the corresponding RPC dummy at /src/browser/proxies/host.js24 return {25 click: click(),26 clickAt: clickAt(webDriver),27 done: done(webDriver, doneDeferred.resolve),28 donePromise: doneDeferred.promise,29 error: error(doneDeferred.reject),30 getLogs: getLogs(webDriver),31 hover: hover(webDriver),32 moveTo: moveTo(webDriver),33 pressAndHold: pressAndHold(webDriver),34 ready: ready(readyDeferred.resolve),35 readyPromise: readyDeferred.promise,36 sendAccessKey: sendAccessKey(webDriver),37 sendDevToolsCommand: sendDevToolsCommand(webDriver),38 sendKeys: sendKeys(webDriver),39 sendShiftTab: sendShiftTab(webDriver),40 sendTab: sendTab(webDriver),41 snapshot: snapshot(webDriver),42 upload: upload(webDriver),43 windowSize: windowSize(webDriver)44 };...
move-to-e2e-specs.js
Source:move-to-e2e-specs.js
...19 let el = await driver.elementByAccessibilityId('Views');20 await el.click();21 let moveToEl = await driver.elementByAccessibilityId('Expandable Lists');22 await driver.elementByAccessibilityId('ImageView').should.eventually.be.rejectedWith(/Could not find element/);23 await driver.moveTo(moveToEl);24 await driver.elementByAccessibilityId('ImageView').should.eventually.exist;25 });...
Using AI Code Generation
1driver.moveTo(1, 2, 3, 4);2driver.tap(1, 2, 3, 4);3driver.swipe(1, 2, 3, 4, 5);4driver.touchPerform(1, 2, 3, 4);5driver.multiTouchPerform(1, 2, 3, 4);6driver.execute(1, 2, 3, 4);7driver.executeAsync(1, 2, 3, 4);8driver.executeScript(1, 2, 3, 4);9driver.executeAsyncScript(1, 2, 3, 4);10driver.executeSql(1, 2, 3, 4);11driver.executeSqlAsync(1, 2, 3, 4);12driver.getOrientation(1, 2, 3, 4);13driver.setOrientation(1, 2, 3, 4);14driver.getGeoLocation(1, 2, 3, 4);15driver.setGeoLocation(1, 2, 3, 4);16driver.getNetworkConnection(1, 2, 3, 4);17driver.setNetworkConnection(1, 2, 3, 4);
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!!