How to use this.click method in Appium Android Driver

Best JavaScript code snippet using appium-android-driver

Run Appium Android Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

default_handlers.js

Source: default_handlers.js Github

copy
1/* ***** BEGIN LICENSE BLOCK *****
2 * Distributed under the BSD license:
3 *
4 * Copyright (c) 2010, Ajax.org B.V.
5 * All rights reserved.
6 * 
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *     * Redistributions of source code must retain the above copyright
10 *       notice, this list of conditions and the following disclaimer.
11 *     * Redistributions in binary form must reproduce the above copyright
12 *       notice, this list of conditions and the following disclaimer in the
13 *       documentation and/or other materials provided with the distribution.
14 *     * Neither the name of Ajax.org B.V. nor the
15 *       names of its contributors may be used to endorse or promote products
16 *       derived from this software without specific prior written permission.
17 * 
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * ***** END LICENSE BLOCK ***** */
30
31define(function(require, exports, module) {
32"use strict";
33
34var dom = require("../lib/dom");
35var useragent = require("../lib/useragent");
36
37var DRAG_OFFSET = 0; // pixels
38
39function DefaultHandlers(mouseHandler) {
40    mouseHandler.$clickSelection = null;
41
42    var editor = mouseHandler.editor;
43    editor.setDefaultHandler("mousedown", this.onMouseDown.bind(mouseHandler));
44    editor.setDefaultHandler("dblclick", this.onDoubleClick.bind(mouseHandler));
45    editor.setDefaultHandler("tripleclick", this.onTripleClick.bind(mouseHandler));
46    editor.setDefaultHandler("quadclick", this.onQuadClick.bind(mouseHandler));
47    editor.setDefaultHandler("mousewheel", this.onMouseWheel.bind(mouseHandler));
48
49    var exports = ["select", "startSelect", "drag", "dragEnd", "dragWait",
50        "dragWaitEnd", "startDrag", "focusWait"];
51
52    exports.forEach(function(x) {
53        mouseHandler[x] = this[x];
54    }, this);
55
56    mouseHandler.selectByLines = this.extendSelectionBy.bind(mouseHandler, "getLineRange");
57    mouseHandler.selectByWords = this.extendSelectionBy.bind(mouseHandler, "getWordRange");
58}
59
60(function() {
61
62    this.onMouseDown = function(ev) {
63        var inSelection = ev.inSelection();
64        var pos = ev.getDocumentPosition();
65        this.mousedownEvent = ev;
66        var editor = this.editor;
67
68        var button = ev.getButton();
69        if (button !== 0) {
70            var selectionRange = editor.getSelectionRange();
71            var selectionEmpty = selectionRange.isEmpty();
72
73            if (selectionEmpty) {
74                editor.moveCursorToPosition(pos);
75                editor.selection.clearSelection();
76            }
77
78            // 2: contextmenu, 1: linux paste
79            editor.textInput.onContextMenu(ev.domEvent);
80            return; // stopping event here breaks contextmenu on ff mac
81        }
82
83        // if this click caused the editor to be focused should not clear the
84        // selection
85        if (inSelection && !editor.isFocused()) {
86            editor.focus();
87            if (this.$focusTimout && !this.$clickSelection && !editor.inMultiSelectMode) {
88                this.setState("focusWait");
89                this.captureMouse(ev);
90                return ev.preventDefault();
91            }
92        }
93
94        if (!inSelection || this.$clickSelection || ev.getShiftKey() || editor.inMultiSelectMode) {
95            // Directly pick STATE_SELECT, since the user is not clicking inside
96            // a selection.
97            this.startSelect(pos);
98        } else if (inSelection) {
99            this.mousedownEvent.time = (new Date()).getTime();
100            this.setState("dragWait");
101        }
102
103        this.captureMouse(ev);
104        return ev.preventDefault();
105    };
106
107    this.startSelect = function(pos) {
108        pos = pos || this.editor.renderer.screenToTextCoordinates(this.x, this.y);
109        if (this.mousedownEvent.getShiftKey()) {
110            this.editor.selection.selectToPosition(pos);
111        }
112        else if (!this.$clickSelection) {
113            this.editor.moveCursorToPosition(pos);
114            this.editor.selection.clearSelection();
115        }
116        this.setState("select");
117    };
118
119    this.select = function() {
120        var anchor, editor = this.editor;
121        var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
122
123        if (this.$clickSelection) {
124            var cmp = this.$clickSelection.comparePoint(cursor);
125
126            if (cmp == -1) {
127                anchor = this.$clickSelection.end;
128            } else if (cmp == 1) {
129                anchor = this.$clickSelection.start;
130            } else {
131                var orientedRange = calcRangeOrientation(this.$clickSelection, cursor);
132                cursor = orientedRange.cursor;
133                anchor = orientedRange.anchor;
134            }
135            editor.selection.setSelectionAnchor(anchor.row, anchor.column);
136        }
137        editor.selection.selectToPosition(cursor);
138
139        editor.renderer.scrollCursorIntoView();
140    };
141
142    this.extendSelectionBy = function(unitName) {
143        var anchor, editor = this.editor;
144        var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
145        var range = editor.selection[unitName](cursor.row, cursor.column);
146
147        if (this.$clickSelection) {
148            var cmpStart = this.$clickSelection.comparePoint(range.start);
149            var cmpEnd = this.$clickSelection.comparePoint(range.end);
150
151            if (cmpStart == -1 && cmpEnd <= 0) {
152                anchor = this.$clickSelection.end;
153                if (range.end.row != cursor.row || range.end.column != cursor.column)
154                    cursor = range.start;
155            } else if (cmpEnd == 1 && cmpStart >= 0) {
156                anchor = this.$clickSelection.start;
157                if (range.start.row != cursor.row || range.start.column != cursor.column)
158                    cursor = range.end;
159            } else if (cmpStart == -1 && cmpEnd == 1) {
160                cursor = range.end;
161                anchor = range.start;
162            } else {
163                var orientedRange = calcRangeOrientation(this.$clickSelection, cursor);
164                cursor = orientedRange.cursor;
165                anchor = orientedRange.anchor;
166            }
167            editor.selection.setSelectionAnchor(anchor.row, anchor.column);
168        }
169        editor.selection.selectToPosition(cursor);
170
171        editor.renderer.scrollCursorIntoView();
172    };
173
174    this.startDrag = function() {
175        var editor = this.editor;
176        this.setState("drag");
177        this.dragRange = editor.getSelectionRange();
178        var style = editor.getSelectionStyle();
179        this.dragSelectionMarker = editor.session.addMarker(this.dragRange, "ace_selection", style);
180        editor.clearSelection();
181        dom.addCssClass(editor.container, "ace_dragging");
182        if (!this.$dragKeybinding) {
183            this.$dragKeybinding = {
184                handleKeyboard: function(data, hashId, keyString, keyCode) {
185                    if (keyString == "esc")
186                        return {command: this.command};
187                },
188                command: {
189                    exec: function(editor) {
190                        var self = editor.$mouseHandler;
191                        self.dragCursor = null;
192                        self.dragEnd();
193                        self.startSelect();
194                    }
195                }
196            }
197        }
198
199        editor.keyBinding.addKeyboardHandler(this.$dragKeybinding);
200    };
201
202    this.focusWait = function() {
203        var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
204        var time = (new Date()).getTime();
205
206        if (distance > DRAG_OFFSET || time - this.mousedownEvent.time > this.$focusTimout)
207            this.startSelect(this.mousedownEvent.getDocumentPosition());
208    };
209
210    this.dragWait = function(e) {
211        var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);
212        var time = (new Date()).getTime();
213        var editor = this.editor;
214
215        if (distance > DRAG_OFFSET) {
216            this.startSelect(this.mousedownEvent.getDocumentPosition());
217        } else if (time - this.mousedownEvent.time > editor.$mouseHandler.$dragDelay) {
218            this.startDrag();
219        }
220    };
221
222    this.dragWaitEnd = function(e) {
223        this.mousedownEvent.domEvent = e;
224        this.startSelect();
225    };
226
227    this.drag = function() {
228        var editor = this.editor;
229        this.dragCursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
230        editor.moveCursorToPosition(this.dragCursor);
231        editor.renderer.scrollCursorIntoView();
232    };
233
234    this.dragEnd = function(e) {
235        var editor = this.editor;
236        var dragCursor = this.dragCursor;
237        var dragRange = this.dragRange;
238        dom.removeCssClass(editor.container, "ace_dragging");
239        editor.session.removeMarker(this.dragSelectionMarker);
240        editor.keyBinding.removeKeyboardHandler(this.$dragKeybinding);
241
242        if (!dragCursor)
243            return;
244
245        editor.clearSelection();
246        if (e && (e.ctrlKey || e.altKey)) {
247            var session = editor.session;
248            var newRange = dragRange;
249            newRange.end = session.insert(dragCursor, session.getTextRange(dragRange));
250            newRange.start = dragCursor;
251        } else if (dragRange.contains(dragCursor.row, dragCursor.column)) {
252            return;
253        } else {
254            var newRange = editor.moveText(dragRange, dragCursor);
255        }
256
257        if (!newRange)
258            return;
259
260        editor.selection.setSelectionRange(newRange);
261    };
262
263    this.onDoubleClick = function(ev) {
264        var pos = ev.getDocumentPosition();
265        var editor = this.editor;
266        var session = editor.session;
267
268        var range = session.getBracketRange(pos);
269        if (range) {
270            if (range.isEmpty()) {
271                range.start.column--;
272                range.end.column++;
273            }
274            this.$clickSelection = range;
275            this.setState("select");
276            return;
277        }
278
279        this.$clickSelection = editor.selection.getWordRange(pos.row, pos.column);
280        this.setState("selectByWords");
281    };
282
283    this.onTripleClick = function(ev) {
284        var pos = ev.getDocumentPosition();
285        var editor = this.editor;
286
287        this.setState("selectByLines");
288        this.$clickSelection = editor.selection.getLineRange(pos.row);
289    };
290
291    this.onQuadClick = function(ev) {
292        var editor = this.editor;
293
294        editor.selectAll();
295        this.$clickSelection = editor.getSelectionRange();
296        this.setState("null");
297    };
298
299    this.onMouseWheel = function(ev) {
300        if (ev.getShiftKey() || ev.getAccelKey())
301            return;
302        var t = ev.domEvent.timeStamp;
303        var dt = t - (this.$lastScrollTime||0);
304        
305        var editor = this.editor;
306        var isScrolable = editor.renderer.isScrollableBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed);
307        if (isScrolable || dt < 200) {
308            this.$lastScrollTime = t;
309            editor.renderer.scrollBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed);
310            return ev.stop();
311        }
312    };
313
314}).call(DefaultHandlers.prototype);
315
316exports.DefaultHandlers = DefaultHandlers;
317
318function calcDistance(ax, ay, bx, by) {
319    return Math.sqrt(Math.pow(bx - ax, 2) + Math.pow(by - ay, 2));
320}
321
322function calcRangeOrientation(range, cursor) {
323    if (range.start.row == range.end.row)
324        var cmp = 2 * cursor.column - range.start.column - range.end.column;
325    else if (range.start.row == range.end.row - 1 && !range.start.column && !range.end.column)
326        var cmp = cursor.column - 4;
327    else
328        var cmp = 2 * cursor.row - range.start.row - range.end.row;
329
330    if (cmp < 0)
331        return {cursor: range.start, anchor: range.end};
332    else
333        return {cursor: range.end, anchor: range.start};
334}
335
336});
337
Full Screen

pagetree.js

Source: pagetree.js Github

copy
1var PageTree = Class.create();
2PageTree.prototype = {
3	initialize: function(element,page,title,actionFrame,queryClassName,actionPage) {
4		Ajax.Tree.Invoice = Ajax.Tree.create({
5				types: {
6					pageTreeSite: {
7						page: page,
8						insertion: function(el,data){
9							var node = Builder.node('dl',{className:'treeDl'},
10							[
11								Builder.node('dt',{className:'treeDt'},[data.name]),
12							]);
13							el.appendChild(node);
14
15							this.element.setAttribute("left",data.left);
16							this.element.setAttribute("right",data.right);
17							this.element.setAttribute("depth",data.depth);
18							this.element.setAttribute("treeName",data.name);
19							
20							var separator = actionPage.indexOf("?") == -1 ? "?" : "&";
21							dojo.debug("separator : " + separator);
22							
23							if(actionPage){
24								if(data.depth!=0){
25									this.clickExpense = function(evt){
26										dojo.debug(actionPage + separator + "ajax_entity_value="+data.thisEntity);
27										window.parent[actionFrame].location.replace(actionPage + separator + "ajax_entity_value="+data.thisEntity);
28									}.bind(this);
29									Event.observe(this.span,'click',this.clickExpense);
30								}else{
31									this.clickExpense = function(evt){
32										dojo.debug(actionPage + separator + "ajax_entity_value=boot");
33										window.parent[actionFrame].location.replace(actionPage + separator + "ajax_entity_value=boot");
34									}.bind(this);
35									Event.observe(this.span,'click',this.clickExpense);
36								}
37							}else{
38								if(data.actionPage){
39									this.clickExpense = function(evt){
40										window.parent[actionFrame].location.replace(data.actionPage);
41									}.bind(this);
42									Event.observe(this.span,'click',this.clickExpense);
43								}else{
44									this.clickExpense = function(evt){
45										this.onClick();
46									}.bind(this);
47									Event.observe(this.span,'click',this.clickExpense);
48								}
49							}
50						},
51						callback:{
52							call:function(node,id){
53								var left=node.element.getAttribute("left");
54								var right=node.element.getAttribute("right");
55								var depth=node.element.getAttribute("depth");
56								
57								var dependFields;
58								
59//								var dependFields = queryBox.options.dependFields;
60								
61								var depend="";
62								
63								if(dependFields != null && dependFields != "" && dependFields.length != 0){
64									for(var i=0;i<dependFields.length;i++){
65										if(i!=0){
66											depend += ",";
67										}
68										depend += parent.document.getElementById(dependFields[i]).value;
69									}
70								}else{
71									depend="";
72								}
73															
74								return "left=" + left + "&" + "right=" + right + "&" + "depth=" + depth + 
75								"&" + "queryClassName=" + queryClassName + "&" + "dependFields=" + depend;
76							}
77						}
78					}
79				},
80				createNodes: function(nodes){
81					if(!nodes.length){ return; }
82					this.showChildren();
83					this.loaded = true;
84					for(var i=0; i < nodes.length; i++){
85//						if((nodes[i].data.right - nodes[i].data.left) == 1){
86//							this.options.leafNode = true;
87//						}else{
88							this.options.leafNode = false;
89//						}
90						var newNode = new this.constructor(this.element,nodes[i].id,nodes[i].type,nodes[i]);
91					}
92					if(this.options.sortable){ this.createSortable(); }
93				}
94			});
95			this.treeObj = new Ajax.Tree.Invoice(element,'root','pageTreeSite',{data:{name:title,left:-1,right:-1,depth:0}});
96	}
97}
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Appium Android Driver on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)