How to use element.getRect method in Appium

Best JavaScript code snippet using appium

intro.js

Source:intro.js Github

copy

Full Screen

...297                        contactWithOtherMovableElement = true;298                        maxTemperatureDifference = Math.max(Math.abs(element.getTemperature() - otherElement.getTemperature()), maxTemperatureDifference);299                    }300                }301                if (this.beaker.getThermalContactArea().getBounds().contains(element.getRect())) {302                    // This model element is immersed in the beaker.303                    immersedInBeaker = true;304                }305                // Exchange energy and energy chunks with the air if appropriate306                //   conditions met.307                if (!contactWithOtherMovableElement || (308                        !immersedInBeaker && (309                            maxTemperatureDifference < IntroSimulation.MIN_TEMPERATURE_DIFF_FOR_MULTI_BODY_AIR_ENERGY_EXCHANGE ||310                            element.getEnergyBeyondMaxTemperature() > 0311                        )312                    )313                ) {314                    this.air.exchangeEnergyWith(element, deltaTime);315                    if (element.getEnergyChunkBalance() > 0) {316                        var pointAbove = this._pointAbove.set(317                            Math.random() * element.getRect().w + element.getRect().left(),318                            element.getRect().top()319                        );320                        chunk = element.extractClosestEnergyChunk(pointAbove);321                        if (chunk) {322                            //console.log('(' + element.cid + ') giving chunk to air');323                            var initialMotionConstraints = null;324                            if (element instanceof Beaker) {325                                // Constrain the energy chunk's motion so that it326                                // doesn't go through the edges of the beaker.327                                // There is a bit of a fudge factor in here to328                                // make sure that the sides of the energy chunk,329                                // and not just the center, stay in bounds.330                                var energyChunkWidth = 0.01;331                                initialMotionConstraints = this._initialMotionConstraints.set( 332                                    element.getRect().x + energyChunkWidth / 2,333                                    element.getRect().y,334                                    element.getRect().w - energyChunkWidth,335                                    element.getRect().h 336                                );337                            }338                            this.air.addEnergyChunk(chunk, initialMotionConstraints);339                        }340                    }341                    else if (element.getEnergyChunkBalance() < 0 && element.getTemperature() < this.air.getTemperature()) {342                        element.addEnergyChunk(this.air.requestEnergyChunk(element.getCenterPoint()));343                    }344                }345            }346            // Exchange energy chunks between the air and the burners.347            for (i = 0; i < this.burners.length; i++) {348                burner = this.burners[i];349                var energyChunkCountForAir = burner.getEnergyChunkCountForAir();350                if (energyChunkCountForAir > 0)351                    this.air.addEnergyChunk(burner.extractClosestEnergyChunk(burner.getCenterPoint()), null);352                else if (energyChunkCountForAir < 0)353                    burner.addEnergyChunk(this.air.requestEnergyChunk(burner.getCenterPoint()));354            }355        },356        /**357         * Validate the position being proposed for the given model element.  This358         * evaluates whether the proposed position would cause the model element359         * to move through another solid element, or the side of the beaker, or360         * something that would look weird to the user and, if so, prevent the odd361         * behavior from happening by returning a location that works better.362         *363         * @param element         Element whose position is being validated.364         * @param proposedPosition Proposed new position for element365         * @return The original proposed position if valid, or alternative position366         *         if not.367         */368        validatePosition: function(element, proposedPosition) {369            // Compensate for the element's center X position370            var translation = this._translation371                .set(proposedPosition)372                .sub(element.get('position'));373            // Figure out how far the block's right edge appears to protrude to374            //   the side due to perspective.375            var blockPerspectiveExtension = Block.SURFACE_WIDTH * Constants.BlockView.PERSPECTIVE_EDGE_PROPORTION * Math.cos(Constants.BlockView.PERSPECTIVE_ANGLE) / 2;376            // Validate against burner boundaries.  Treat the burners as one big377            //   blocking rectangle so that the user can't drag things between378            //   them.  Also, compensate for perspective so that we can avoid379            //   difficult z-order issues.380            var standPerspectiveExtension = this.leftBurner.getOutlineRect().h * Burner.EDGE_TO_HEIGHT_RATIO * Math.cos(Constants.BurnerStandView.PERSPECTIVE_ANGLE) / 2;381            var burnerRectX = this.leftBurner.getOutlineRect().x - standPerspectiveExtension - (element !== this.beaker ? blockPerspectiveExtension : 0);382            var burnerBlockingRect = this._burnerBlockingRect.set( 383                burnerRectX,384                this.leftBurner.getOutlineRect().y,385                this.rightBurner.getOutlineRect().right() - burnerRectX,386                this.leftBurner.getOutlineRect().h387            );388            translation = this.determineAllowedTranslation(element.getRect(), burnerBlockingRect, translation, false);389            // Validate against the sides of the beaker.390            if (element !== this.beaker) {391                // Create three rectangles to represent the two sides and the top392                //   of the beaker.393                var testRectThickness = 1E-3; // 1 mm thick walls.394                var beakerRect = this.beaker.getRect();395                var beakerLeftSide = this._beakerLeftSide.set(396                    beakerRect.left() - blockPerspectiveExtension,397                    this.beaker.getRect().bottom(),398                    testRectThickness + blockPerspectiveExtension * 2,399                    this.beaker.getRect().h + blockPerspectiveExtension400                );401                var beakerRightSide = this._beakerRightSide.set(402                    this.beaker.getRect().right() - testRectThickness - blockPerspectiveExtension,403                    this.beaker.getRect().bottom(),404                    testRectThickness + blockPerspectiveExtension * 2,405                    this.beaker.getRect().h + blockPerspectiveExtension406                );407                var beakerBottom = this._beakerBottom.set(408                    this.beaker.getRect().left(), 409                    this.beaker.getRect().bottom(), 410                    this.beaker.getRect().w, 411                    testRectThickness412                );413                // Do not restrict the model element's motion in positive Y414                //   direction if the beaker is sitting on top of the model 415                //   element - the beaker will simply be lifted up.416                var restrictPositiveY = !this.beaker.isStackedUpon(element);417                // Clamp the translation based on the beaker position.418                translation = this.determineAllowedTranslation(element.getRect(), beakerLeftSide,  translation, restrictPositiveY);419                translation = this.determineAllowedTranslation(element.getRect(), beakerRightSide, translation, restrictPositiveY);420                translation = this.determineAllowedTranslation(element.getRect(), beakerBottom,    translation, restrictPositiveY);421            }422            // Now check the model element's motion against each of the blocks.423            for (var i = 0; i < this.blocks.length; i++) {424                var block = this.blocks[i];425                if (element === block)426                    continue;427                // Do not restrict the model element's motion in positive Y428                //   direction if the tested block is sitting on top of the model429                //   element - the block will simply be lifted up.430                var restrictPositiveY = !block.isStackedUpon(element);431                var testRect = this._testRect.set(element.getRect());432                if (element === this.beaker) {433                    // Special handling for the beaker - block it at the outer434                    // edge of the block instead of the center in order to435                    // simplify z-order handling.436                    testRect.set( 437                        testRect.x - blockPerspectiveExtension,438                        testRect.y,439                        testRect.w + blockPerspectiveExtension * 2,440                        testRect.h441                    );442                }443                // Clamp the translation based on the test block's position, but444                //   handle the case where the block is immersed in the beaker.445                if (element !== this.beaker || !this.beaker.getRect().contains(block.getRect())) {...

Full Screen

Full Screen

13d743f89c3c204a952c3519fbe6f7df32ead764.js

Source:13d743f89c3c204a952c3519fbe6f7df32ead764.js Github

copy

Full Screen

...51        Body.element.add(this.element.el, 0);52        colorPicker.onOpen((function(_this) {53          return function() {54            var _rect;55            if (!(_this.element.updateRect() && (_rect = _this.element.getRect()))) {56              return;57            }58            _this.width = _rect.width;59            return _this.height = _rect.height;60          };61        })(this));62        setTimeout((function(_this) {63          return function() {64            var Hue, Saturation, _elementHeight, _elementWidth;65            Saturation = _this;66            Hue = colorPicker.getExtension('Hue');67            _elementWidth = _this.element.getWidth();68            _elementHeight = _this.element.getHeight();69            _this.canvas = {70              el: (function() {71                var _el;72                _el = document.createElement('canvas');73                _el.width = _elementWidth;74                _el.height = _elementHeight;75                _el.classList.add("" + Saturation.element.el.className + "-canvas");76                return _el;77              })(),78              context: null,79              getContext: function() {80                return this.context || (this.context = this.el.getContext('2d'));81              },82              getColorAtPosition: function(x, y) {83                return colorPicker.SmartColor.HSVArray([Hue.getHue(), x / Saturation.element.getWidth() * 100, 100 - (y / Saturation.element.getHeight() * 100)]);84              },85              render: function(smartColor) {86                var _context, _gradient, _hslArray;87                _hslArray = ((function() {88                  if (!smartColor) {89                    return colorPicker.SmartColor.HEX('#f00');90                  } else {91                    return smartColor;92                  }93                })()).toHSLArray();94                _context = this.getContext();95                _context.clearRect(0, 0, _elementWidth, _elementHeight);96                _gradient = _context.createLinearGradient(0, 0, _elementWidth, 1);97                _gradient.addColorStop(.01, 'hsl(0, 100%, 100%)');98                _gradient.addColorStop(.99, "hsl(" + _hslArray[0] + ", 100%, 50%)");99                _context.fillStyle = _gradient;100                _context.fillRect(0, 0, _elementWidth, _elementHeight);101                _gradient = _context.createLinearGradient(0, 0, 1, _elementHeight);102                _gradient.addColorStop(.01, 'rgba(0, 0, 0, 0)');103                _gradient.addColorStop(.99, 'rgba(0, 0, 0, 1)');104                _context.fillStyle = _gradient;105                _context.fillRect(0, 0, _elementWidth, _elementHeight);106              }107            };108            Hue.onColorChanged(function(smartColor) {109              return _this.canvas.render(smartColor);110            });111            _this.canvas.render();112            return _this.element.add(_this.canvas.el);113          };114        })(this));115        setTimeout((function(_this) {116          return function() {117            var Hue, Saturation, hasChild;118            hasChild = function(element, child) {119              var _parent;120              if (child && (_parent = child.parentNode)) {121                if (child === element) {122                  return true;123                } else {124                  return hasChild(element, _parent);125                }126              }127              return false;128            };129            Saturation = _this;130            Hue = colorPicker.getExtension('Hue');131            _this.control = {132              el: (function() {133                var _el;134                _el = document.createElement('div');135                _el.classList.add("" + Saturation.element.el.className + "-control");136                return _el;137              })(),138              isGrabbing: false,139              selection: {140                x: null,141                y: 0,142                color: null143              },144              setSelection: function(e, saturation, key) {145                var _position, _rect, _x, _y;146                if (saturation == null) {147                  saturation = null;148                }149                if (key == null) {150                  key = null;151                }152                if (!(Saturation.canvas && (_rect = Saturation.element.getRect()))) {153                  return;154                }155                if (e) {156                  _x = e.pageX - _rect.left;157                  _y = e.pageY - _rect.top;158                } else if ((typeof saturation === 'number') && (typeof key === 'number')) {159                  _x = _rect.width * saturation;160                  _y = _rect.height * key;161                } else {162                  if (typeof this.selection.x !== 'number') {163                    this.selection.x = _rect.width;164                  }165                  _x = this.selection.x;166                  _y = this.selection.y;...

Full Screen

Full Screen

ffd9ebd2e4ac903abd5645e1c2bf6c8d50e0ec4f.js

Source:ffd9ebd2e4ac903abd5645e1c2bf6c8d50e0ec4f.js Github

copy

Full Screen

...58        Body.element.add(this.element.el, 2);59        colorPicker.onOpen((function(_this) {60          return function() {61            var _rect;62            if (!(_this.element.updateRect() && (_rect = _this.element.getRect()))) {63              return;64            }65            _this.width = _rect.width;66            return _this.height = _rect.height;67          };68        })(this));69        setTimeout((function(_this) {70          return function() {71            var Hue, _context, _elementHeight, _elementWidth, _gradient, _hex, _hexes, _i, _j, _len, _step;72            Hue = _this;73            _elementWidth = _this.element.getWidth();74            _elementHeight = _this.element.getHeight();75            _hexes = ['#f00', '#ff0', '#0f0', '#0ff', '#00f', '#f0f', '#f00'];76            _this.canvas = {77              el: (function() {78                var _el;79                _el = document.createElement('canvas');80                _el.width = _elementWidth;81                _el.height = _elementHeight;82                _el.classList.add("" + Hue.element.el.className + "-canvas");83                return _el;84              })(),85              context: null,86              getContext: function() {87                return this.context || (this.context = this.el.getContext('2d'));88              },89              getColorAtPosition: function(y) {90                return colorPicker.SmartColor.HSVArray([y / Hue.element.getHeight() * 360, 100, 100]);91              }92            };93            _context = _this.canvas.getContext();94            _step = 1 / (_hexes.length - 1);95            _gradient = _context.createLinearGradient(0, 0, 1, _elementHeight);96            for (_i = _j = 0, _len = _hexes.length; _j < _len; _i = ++_j) {97              _hex = _hexes[_i];98              _gradient.addColorStop(_step * _i, _hex);99            }100            _context.fillStyle = _gradient;101            _context.fillRect(0, 0, _elementWidth, _elementHeight);102            return _this.element.add(_this.canvas.el);103          };104        })(this));105        setTimeout((function(_this) {106          return function() {107            var Hue, hasChild;108            hasChild = function(element, child) {109              var _parent;110              if (child && (_parent = child.parentNode)) {111                if (child === element) {112                  return true;113                } else {114                  return hasChild(element, _parent);115                }116              }117              return false;118            };119            Hue = _this;120            _this.control = {121              el: (function() {122                var _el;123                _el = document.createElement('div');124                _el.classList.add("" + Hue.element.el.className + "-control");125                return _el;126              })(),127              isGrabbing: false,128              selection: {129                y: 0,130                color: null131              },132              setSelection: function(e, y, offset) {133                var _position, _rect, _y;134                if (y == null) {135                  y = null;136                }137                if (offset == null) {138                  offset = null;139                }140                if (!(Hue.canvas && (_rect = Hue.element.getRect()))) {141                  return;142                }143                if (e) {144                  _y = e.pageY - _rect.top;145                } else if (typeof y === 'number') {146                  _y = y;147                } else if (typeof offset === 'number') {148                  _y = this.selection.y + offset;149                } else {150                  _y = this.selection.y;151                }152                _y = this.selection.y = Math.max(0, Math.min(_rect.height, _y));153                this.selection.color = Hue.canvas.getColorAtPosition(_y);154                _position = {...

Full Screen

Full Screen

5_chessboard_interaction.js

Source:5_chessboard_interaction.js Github

copy

Full Screen

...29	});30	function itCheckClickSquare(itemIndex, label, targets) {31		itCustom(browserContext, '07_chessboard_click_squares', itemIndex, label, async function(element) {32			let actions = browserContext.driver.actions({ async: true });33			let area = await element.getRect();34			for (let i = 0; i < targets.length; ++i) {35				let target = targets[i];36				await actions.move({ x: area.x + target.x, y: area.y + target.y }).click().perform();37				await compareSandbox(browserContext, target.expectedText);38			}39		});40	}41	itCheckClickSquare(0, 'default', [42		{ x: 225, y: 75, expectedText: 'square clicked: e7' },43		{ x: 25, y: 375, expectedText: 'square clicked: a1' },44		{ x: 325, y: 175, expectedText: 'square clicked: g5' },45	]);46	itCheckClickSquare(1, 'with flip', [47		{ x: 325, y: 175, expectedText: 'square clicked: b4' },48	]);49	itCheckClickSquare(2, 'over annotations', [50		{ x: 25, y: 25, expectedText: 'square clicked: a8' },51		{ x: 75, y: 125, expectedText: 'square clicked: b6' },52		{ x: 175, y: 125, expectedText: 'square clicked: d6' },53		{ x: 75, y: 225, expectedText: 'square clicked: b4' },54	]);55	function itCheckMovePiece(itemIndex, label, xFrom, yFrom, xTo, yTo, imageBaseName, expectedText) {56		itCustom(browserContext, '08_chessboard_move_pieces', itemIndex, label, async function(element) {57			let actions = browserContext.driver.actions({ async: true });58			let area = await element.getRect();59			await actions.move({ x: area.x + xFrom, y: area.y + yFrom }).press().move({ x: area.x + xTo, y: area.y + yTo }).perform();60			await takeScreenshot(browserContext, imageBaseName, element);61			await actions.release().perform();62			await compareScreenshot(browserContext, imageBaseName);63			await compareSandbox(browserContext, expectedText);64		});65	}66	itCheckMovePiece(0, 'over empty', 275, 385, 225, 175, 'over_empty', 'piece moved: f1 -> e5');67	itCheckMovePiece(0, 'over non-empty 1', 280, 365, 75, 75, 'over_non_empty_1', 'piece moved: f1 -> b7');68	itCheckMovePiece(0, 'over non-empty 2', 130, 75, 225, 375, 'over_non_empty_2', 'piece moved: c7 -> e1');69	itCheckMovePiece(1, 'over square marker', 10, 325, 275, 175, 'over_square_marker', 'piece moved: h7 -> c4');70	itCheckMovePiece(1, 'over text marker', 225, 25, 10, 135, 'over_text_marker', 'piece moved: d1 -> h3');71	itCheckMovePiece(1, 'over arrow marker', 325, 25, 315, 260, 'over_arrow_marker', 'piece moved: b1 -> b6');72	itCheckMovePiece(2, 'after move', 225, 225, 75, 260, 'after_move', 'piece moved: e4 -> b3');73	function itCheckNonMovePiece(itemIndex, label, xFrom, yFrom, xTo, yTo, imageBaseName) {74		itCustom(browserContext, '08_chessboard_move_pieces', itemIndex, label, async function(element) {75			await setSandbox(browserContext, imageBaseName); // can be any value as long as it is unique among other test-cases76			let actions = browserContext.driver.actions({ async: true });77			let area = await element.getRect();78			await actions.move({ x: area.x + xFrom, y: area.y + yFrom }).press().move({ x: area.x + xTo, y: area.y + yTo }).perform();79			await takeScreenshot(browserContext, imageBaseName, element);80			await actions.release().perform();81			await compareScreenshot(browserContext, imageBaseName);82			await compareSandbox(browserContext, imageBaseName);83		});84	}85	itCheckNonMovePiece(0, 'move empty square', 175, 225, 275, 75, 'empty_square');86	itCheckNonMovePiece(0, 'from == to', 75, 375, 80, 360, 'null_vector');87	itCheckNonMovePiece(0, 'out of board', 175, 25, 500, 210, 'out_of_board');88	function itCheckEditArrow(itemIndex, label, xFrom, yFrom, xTo, yTo, imageBaseName, expectedText) {89		itCustom(browserContext, '09_chessboard_edit_arrows', itemIndex, label, async function(element) {90			let actions = browserContext.driver.actions({ async: true });91			let area = await element.getRect();92			await actions.move({ x: area.x + xFrom, y: area.y + yFrom }).press().move({ x: area.x + xTo, y: area.y + yTo }).perform();93			await takeScreenshot(browserContext, imageBaseName, element);94			await actions.release().perform();95			await compareScreenshot(browserContext, imageBaseName);96			await compareSandbox(browserContext, expectedText);97		});98	}99	itCheckEditArrow(0, 'base 1', 325, 275, 110, 140, 'base_1', 'arrow edited: g3 -> c6');100	itCheckEditArrow(0, 'base 2', 260, 10, 175, 375, 'base_2', 'arrow edited: f8 -> d1');101	itCheckEditArrow(1, 'over square marker', 275, 125, 275, 230, 'over_square_marker', 'arrow edited: c3 -> c5');102	itCheckEditArrow(1, 'over arrow marker', 40, 110, 125, 290, 'over_arrow_marker', 'arrow edited: h3 -> f6');103	function itCheckNonEditArrow(itemIndex, label, xFrom, yFrom, xTo, yTo, imageBaseName) {104		itCustom(browserContext, '09_chessboard_edit_arrows', itemIndex, label, async function(element) {105			await setSandbox(browserContext, imageBaseName); // can be any value as long as it is unique among other test-cases106			let actions = browserContext.driver.actions({ async: true });107			let area = await element.getRect();108			await actions.move({ x: area.x + xFrom, y: area.y + yFrom }).press().move({ x: area.x + xTo, y: area.y + yTo }).perform();109			await takeScreenshot(browserContext, imageBaseName, element);110			await actions.release().perform();111			await compareScreenshot(browserContext, imageBaseName);112			await compareSandbox(browserContext, imageBaseName);113		});114	}115	itCheckNonEditArrow(2, 'edit color not set', 125, 175, 325, 225, 'edit_color_not_set');116	itCheckNonEditArrow(0, 'from == to', 275, 225, 290, 210, 'null_vector');117	itCheckNonEditArrow(0, 'out of board', 175, 225, 500, 280, 'out_of_board');...

Full Screen

Full Screen

6_chessboard_play_moves.js

Source:6_chessboard_play_moves.js Github

copy

Full Screen

...29	});30	function itCheckPlayMove(itemIndex, label, xFrom, yFrom, xTo, yTo, imageBaseName, expectedText) {31		itCustom(browserContext, '10_chessboard_play_moves', itemIndex, label, async function(element) {32			let actions = browserContext.driver.actions({ async: true });33			let area = await element.getRect();34			await actions.move({ x: area.x + xFrom, y: area.y + yFrom }).press().move({ x: area.x + xTo, y: area.y + yTo }).perform();35			await takeScreenshot(browserContext, imageBaseName, element);36			await actions.release().perform();37			await compareScreenshot(browserContext, imageBaseName);38			await compareSandbox(browserContext, expectedText);39		});40	}41	itCheckPlayMove(0, 'regular move 1', 225, 335, 220, 225, 'regular_move_1', 'move played: e4');42	itCheckPlayMove(1, 'regular move 2', 275, 225, 135, 85, 'regular_move_2', 'move played: Bxf2+');43	itCheckPlayMove(1, 'castling move', 175, 375, 75, 375, 'castling_move', 'move played: O-O');44	itCheckPlayMove(3, 'chess960 castling move 1', 275, 375, 75, 375, 'chess960_castling_move_1', 'move played: O-O-O');45	itCheckPlayMove(3, 'chess960 castling move 2', 275, 375, 375, 375, 'chess960_castling_move_2', 'move played: O-O');46	itCheckPlayMove(3, 'chess960 ambiguous king move', 275, 375, 320, 375, 'chess960_ambiguous_king_move', 'move played: Kg1');47	function itCheckNonPlayMove(itemIndex, label, xFrom, yFrom, xTo, yTo, imageBaseName) {48		itCustom(browserContext, '10_chessboard_play_moves', itemIndex, label, async function(element) {49			await setSandbox(browserContext, imageBaseName); // can be any value as long as it is unique among other test-cases50			let actions = browserContext.driver.actions({ async: true });51			let area = await element.getRect();52			await actions.move({ x: area.x + xFrom, y: area.y + yFrom }).press().move({ x: area.x + xTo, y: area.y + yTo }).perform();53			await takeScreenshot(browserContext, imageBaseName, element);54			await actions.release().perform();55			await compareScreenshot(browserContext, imageBaseName);56			await compareSandbox(browserContext, imageBaseName);57		});58	}59	itCheckNonPlayMove(2, 'illegal position', 225, 325, 225, 225, 'illegal_position');60	itCheckNonPlayMove(0, 'wrong color moved', 75, 25, 125, 125, 'wrong_color');61	itCheckNonPlayMove(0, 'illegal move', 75, 375, 125, 225, 'illegal_move');62	itCheckNonPlayMove(0, 'from == to', 75, 375, 85, 365, 'null_vector');63	itCheckNonPlayMove(0, 'out of board', 325, 375, 450, 285, 'out_of_board');64	itCheckNonPlayMove(3, 'chess960 non-KxR castling', 275, 375, 130, 375, 'chess960_non_kxr_castling');65	function itCheckPlayPromotion(itemIndex, label, xFrom, yFrom, xTo, yTo, xPromo, yPromo, imageBaseName, expectedText) {66		itCustom(browserContext, '11_chessboard_play_promotions', itemIndex, label, async function(element) {67			let actions = browserContext.driver.actions({ async: true });68			let area = await element.getRect();69			await actions.move({ x: area.x + xFrom, y: area.y + yFrom }).press().move({ x: area.x + xTo, y: area.y + yTo }).release().perform();70			await takeScreenshot(browserContext, imageBaseName, element);71			await actions.move({ x: area.x + xPromo, y: area.y + yPromo }).click().perform();72			await compareScreenshot(browserContext, imageBaseName);73			await compareSandbox(browserContext, expectedText);74		});75	}76	itCheckPlayPromotion(0, 'regular promotion 1', 75, 75, 75, 25, 60, 10, 'regular_promotion_1', 'promotion move played: b8=Q');77	itCheckPlayPromotion(1, 'regular promotion 2', 75, 325, 25, 375, 15, 280, 'regular_promotion_2', 'promotion move played: bxa1=B');78	itCheckPlayPromotion(2, 'antichess promotion', 325, 325, 325, 375, 325, 175, 'antichess_promotion', 'promotion move played: b8=K');79	function itCheckNonPlayPromotion(itemIndex, label, xFrom, yFrom, xTo, yTo, xPromo, yPromo, imageBaseName) {80		itCustom(browserContext, '11_chessboard_play_promotions', itemIndex, label, async function(element) {81			await setSandbox(browserContext, imageBaseName); // can be any value as long as it is unique among other test-cases82			let actions = browserContext.driver.actions({ async: true });83			let area = await element.getRect();84			await actions.move({ x: area.x + xFrom, y: area.y + yFrom }).press().move({ x: area.x + xTo, y: area.y + yTo }).release().perform();85			await takeScreenshot(browserContext, imageBaseName, element);86			await actions.move({ x: area.x + xPromo, y: area.y + yPromo }).click().perform();87			await compareScreenshot(browserContext, imageBaseName);88			await compareSandbox(browserContext, imageBaseName);89		});90	}91	itCheckNonPlayPromotion(1, 'cancel promotion', 75, 325, 75, 375, 190, 220, 'cancel_promotion');...

Full Screen

Full Screen

HtmlDom.js

Source:HtmlDom.js Github

copy

Full Screen

1var HtmlDomElement = function(Name,Parent)2{3	this.Name = Name;4	this.Control = null;5	this.Children = [];6	this.Parent = Parent;7	this.OverrideRect = null;8	9	//	made this a func in case it because dynamic/auto from HTML dom later10	this.GetRect = function()11	{12		if ( this.OverrideRect )13			return this.OverrideRect;14		if ( !this.Parent )15			throw "No override rect, and no parent. Don't know element size";16		let ThisRect = this.Parent.GetChildRect(this);17		return ThisRect;18	}19	20	this.GetChildRect = function(ChildElement)21	{22		//	get our rect, then calc the childrects23		let ThisRect = this.GetRect();24		let ChildRects = this.Control.GetChildRects( ThisRect, this.Children.length );25		let ChildIndex = this.Children.indexOf( ChildElement );26		return ChildRects[ChildIndex];27	}28}29//	bridge document to a Pop dom interface30Pop.HtmlDom = function(RootElementId)31{32	this.RootElement = null;33	34	this.GetRootRect = function()35	{36		let RootDocumentElement = document.getElementById(RootElementId);37		let Bounds = RootDocumentElement.getBoundingClientRect();38		/*39		let x = 0;40		let y = 0;41		let w = document.documentElement.offsetWidth;42		let h = document.documentElement.offsetHeight;43		*/44		let x = Bounds.left;45		let y = Bounds.top;46		let w = Bounds.width;47		let h = Bounds.height;48		return new Math.Rect( x, y, w, h );49	}50	51	this.CreateElement = function(Name,Parent)52	{53		if ( !Parent )54			Parent = this.RootElement;55		56		let Element = new HtmlDomElement(Name,Parent);57		if ( Parent )58		{59			Parent.Children.push( Element );60		}61		else62		{63			this.RootElement = Element;64			this.RootElement.GetRect = this.GetRootRect;65		}66		67		return Element;68	}69	70	this.GetElement = function(Name)71	{72		//	traverse tree73		let MatchElements = [];74		let CompareElement = function(Element)75		{76			if ( Element.Name == Name )77				MatchElements.push( Element );78			Element.Children.forEach( CompareElement );79		}80		CompareElement( this.RootElement );81		82		if ( MatchElements.length > 1 )83			throw "Multiple elements matching the name " + Name;84		if ( MatchElements.length == 0 )85			throw "No elements name " + Name;86		return MatchElements[0];87	}88	89	//	OnMouseDown90	//	OnMouseMove91	//	OnScroll92	//	RenderTree (getting render commands)93	this.GetRenderCommands = function()94	{95		let RenderCommands = [];96		let GetElementRenderCommands = function(Element)97		{98			let Rect = Element.GetRect();99			let Cmds = Element.Control.GetRenderCommands.call( Element.Control, Rect, Element );100			RenderCommands.pushArray( Cmds );101			102			//	recurse103			Element.Children.forEach( GetElementRenderCommands );104		}105		GetElementRenderCommands( this.RootElement );106	107		//	iterate dom and get new commands108		return RenderCommands;109	}110	...

Full Screen

Full Screen

Screenshot.js

Source:Screenshot.js Github

copy

Full Screen

...14        return new Screenshot(PNG.sync.read(Buffer.from(base64str, 'base64')));15    }16    static async fromWebElement(driver, element) {17        // rect: {height: number, width: number, x: number, y: number};18        var rect = await element.getRect();19        var cropped = new PNG({width: rect.width, height: rect.height});20        var yOffset = await driver.executeScript(function() {21            // eslint-disable-next-line no-undef22            return window.pageYOffset;23        });24        var pageImg = await Screenshot.fromPage(driver);25        PNG.bitblt(pageImg.png, cropped, rect.x, rect.y - yOffset, rect.width, rect.height, 0, 0);26        return new Screenshot(cropped);27    }28    static async fromPage(driver) {29        return Screenshot.fromBase64(await driver.takeScreenshot());30    }31}32module.exports = Screenshot;

Full Screen

Full Screen

javascriptExecuter.js

Source:javascriptExecuter.js Github

copy

Full Screen

...9    // // for(var i = 0; i<5; i++){10    // //     await driver.executeScript("window.scrollBy(0,1000)")  11    // // }12    // var element = await driver.findElement(By.xpath("//a[text() = 'TALK TO OUR EXPERTS']"))13    // var position = await element.getRect()14    // console.log(position);15    // console.log(typeof(position.x));16    // await driver.executeScript(`window.scrollBy(${position.x}, ${position.y})`)17    //enteringvalue to textfield without using dendkeys()18    // await driver.get("https://opensource-demo.orangehrmlive.com/")19    // await driver.executeScript("document.getElementById('txtUsername').value = 'Admin' ")20}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var By = webdriver.By;3var until = webdriver.until;4var driver = new webdriver.Builder()5    .forBrowser('chrome')6    .build();7driver.findElement(By.name('q')).sendKeys('webdriver');8driver.findElement(By.name('btnG')).click();9driver.wait(until.titleIs('webdriver - Google Search'), 1000);10driver.findElement(By.tagName('body')).getRect().then(function(rect){11    console.log(rect);12});13driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var assert = require('assert');3var driver = new webdriver.Builder()4    .withCapabilities({5    })6    .build();7    .elementByAccessibilityId('test')8    .getRect()9    .then(function(rect) {10        console.log('rect: ' + JSON.stringify(rect));11        assert.equal(rect.width, 100, 'width');12        assert.equal(rect.height, 100, 'height');13    })14    .fin(function() { return driver.quit(); })15    .done();

Full Screen

Using AI Code Generation

copy

Full Screen

1var rect = element.getRect();2console.log(rect.width);3console.log(rect.height);4If you want to use element.getRect() method in Appium Java, then you can use the following code:5Rectangle rect = element.getRect();6System.out.println(rect.width);7System.out.println(rect.height);8If you want to use element.getRect() method in Appium Python, then you can use the following code:9rect = element.getRect()10print(rect['width'])11print(rect['height'])12If you want to use element.getRect() method in Appium Ruby, then you can use the following code:13If you want to use element.getRect() method in Appium PHP, then you can use the following code:14$rect = $element->getRect();15echo $rect['width'];16echo $rect['height'];17If you want to use element.getRect() method in Appium C#, then you can use the following code:18var rect = element.GetRect();19Console.WriteLine(rect.Width);20Console.WriteLine(rect.Height);21If you want to use element.getRect() method in Appium Perl, then you can use the following code:22my $rect = $element->getRect();23print $rect->{'width'};24print $rect->{'height'};25If you want to use element.getRect() method in Appium Groovy, then you can use the following code:26def rect = element.getRect()27If you want to use element.getRect() method in Appium Scala, then you can use the following code:28println(rect.width)29println(rect.height)30If you want to use element.getRect()

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful