Best JavaScript code snippet using appium
Ngn.js
Source:Ngn.js
...249 if (!$defined(eParent)) eParent = element.getParent();250 if (!offset) offset = {};251 offset = Object.merge({x: 0, y: 0}, offset);252 element.setStyles({253 'top': Math.round(eParent.getSize().y/2 - element.getSize().y/2 + offset.y),254 'left': Math.round(eParent.getSize().x/2 - element.getSize().x/2 + offset.x)255 });256};257Ngn.setToCenterHor = function(element, eParent) {258 if (!$defined(eParent)) eParent = element.getParent();259 element.setStyles({260 'left': Math.round(eParent.getSize().x/2 - element.getSize().x/2)261 });262};263Ngn.setToCenterRelVer = function(element, eParent) {264 if (!$defined(eParent)) eParent = element.getParent();265 element.setStyles({266 'margin-top': Math.round(eParent.getSize().y/2 - element.getSize().y/2) + 'px'267 });268};269Ngn.setToCenterRelHor = function(element, eParent) {270 if (!$defined(eParent)) eParent = element.getParent();271 element.setStyles({272 'margin-left': Math.round(eParent.getSize().x/2 - element.getSize().x/2) + 'px'273 });274};275Ngn.setToTopRight = function(element, eParent, margin) {276 if (!$defined(eParent)) eParent = element.getParent();277 if (!$defined(margin)) margin = [0, 0];278 element.setStyles({279 'top': margin[1],280 'left': eParent.getSize().x - element.getSize().x - margin[0]281 });282};283Ngn.setToBottomRight = function(element, eParent, margin) {284 if (!$defined(eParent)) eParent = element.getParent();285 if (!$defined(margin)) margin = [0, 0];286 element.setStyles({287 'top': eParent.getSize().y - margin[1],288 'left': eParent.getSize().x - element.getSize().x - margin[0]289 });290};291Ngn.setToCenterRight = function(element, eParent, margin) {292 if (!$defined(eParent)) eParent = element.getParent();293 if (!$defined(margin)) margin = [0, 0];294 element.setStyles({295 'top': Math.round(eParent.getSize().y/2 - element.getSize().y/2) - margin[1],296 'left': eParent.getSize().x - element.getSize().x - margin[0]297 });298};299Ngn.setToCenterLeft = function(element, eParent, margin) {300 if (!$defined(eParent)) eParent = element.getParent();301 if (!$defined(margin)) margin = [0, 0];302 element.setStyles({303 'top': Math.round(eParent.getSize().y/2 - element.getSize().y/2) - margin[1],304 'left': margin[0]305 });306};307Ngn.setToCenterBlock = function(element, eWidth) {308 element.setStyles({309 'margin-left': Math.round(eWidth.getSize().x/2 - element.getSize().x/2)310 });311};312MooTools.lang.set('ru-RU', 'FancyUpload', {313 'fileName': '{name}',314 'cancel': 'ÐÑмена',315 'cancelTitle': 'ÐликниÑе, ÑÑо Ð±Ñ Ð¾ÑмениÑÑ Ð·Ð°Ð³ÑÑÐ·ÐºÑ Ð¸ ÑдалиÑÑ Ð·Ð°Ð¿Ð¸ÑÑ',316 'validationErrors': {317 'duplicate': 'Файл <em>{name}</em> Ñжа добавлен, дÑбликаÑÑ Ð½Ðµ допÑÑкаÑÑÑÑ.',318 'sizeLimitMin': 'Файл <em>{name}</em> (<em>{size}</em>) ÑлиÑком маленÑкий, минималÑнÑй ÑÐ°Ð·Ð¼ÐµÑ <em>{fileSizeMin}</em>.',319 'sizeLimitMax': 'Файл <em>{name}</em> (<em>{size}</em>) ÑлиÑком болÑÑой, макÑималÑнÑй ÑÐ°Ð·Ð¼ÐµÑ <em>{fileSizeMax}</em>.',320 'fileListMax': 'Файл <em>{name}</em> не Ð¼Ð¾Ð¶ÐµÑ Ð±ÑÑÑ Ð´Ð¾Ð±Ð°Ð²Ð»ÐµÐ½, макÑималÑное колиÑеÑÑво Ñайлов <em>{fileListMax}.',321 'fileListSizeMax': 'Файл <em>{name}</em> (<em>{size}</em>) ÑлиÑком болÑÑой, макÑималÑнÑй ÑÑммаÑнÑй ÑÐ°Ð·Ð¼ÐµÑ Ð²ÑеÑ
Ñайлов <em>{fileListSizeMax}</em>.'322 },323 'errors': {...
Ngn.common.js
Source:Ngn.common.js
...233 if (!eParent != undefined) eParent = element.getParent();234 if (!offset) offset = {};235 offset = Object.merge({x: 0, y: 0}, offset);236 element.setStyles({237 'top': Math.round(eParent.getSize().y / 2 - element.getSize().y / 2 + offset.y),238 'left': Math.round(eParent.getSize().x / 2 - element.getSize().x / 2 + offset.x)239 });240};241Ngn.setToCenterHor = function(element, eParent) {242 if (!eParent != undefined) eParent = element.getParent();243 element.setStyles({244 'left': Math.round(eParent.getSize().x / 2 - element.getSize().x / 2)245 });246};247Ngn.setToCenterRelVer = function(element, eParent) {248 if (!eParent != undefined) eParent = element.getParent();249 element.setStyles({250 'margin-top': Math.round(eParent.getSize().y / 2 - element.getSize().y / 2) + 'px'251 });252};253Ngn.setToCenterRelHor = function(element, eParent) {254 if (!eParent != undefined) eParent = element.getParent();255 element.setStyles({256 'margin-left': Math.round(eParent.getSize().x / 2 - element.getSize().x / 2) + 'px'257 });258};259Ngn.setToTopRight = function(element, eParent, margin) {260 if (!eParent != undefined) eParent = element.getParent();261 if (!margin != undefined) margin = [0, 0];262 element.setStyles({263 'top': margin[1],264 'left': eParent.getSize().x - element.getSize().x - margin[0]265 });266};267Ngn.setToBottomRight = function(element, eParent, margin) {268 if (!eParent != undefined) eParent = element.getParent();269 if (!margin != undefined) margin = [0, 0];270 element.setStyles({271 'top': eParent.getSize().y - margin[1],272 'left': eParent.getSize().x - element.getSize().x - margin[0]273 });274};275Ngn.setToCenterRight = function(element, eParent, margin) {276 if (!eParent != undefined) eParent = element.getParent();277 if (!margin != undefined) margin = [0, 0];278 element.setStyles({279 'top': Math.round(eParent.getSize().y / 2 - element.getSize().y / 2) - margin[1],280 'left': eParent.getSize().x - element.getSize().x - margin[0]281 });282};283Ngn.setToCenterLeft = function(element, eParent, margin) {284 if (!eParent != undefined) eParent = element.getParent();285 if (!margin != undefined) margin = [0, 0];286 element.setStyles({287 'top': Math.round(eParent.getSize().y / 2 - element.getSize().y / 2) - margin[1],288 'left': margin[0]289 });290};291Ngn.setToCenterBlock = function(element, eWidth) {292 element.setStyles({293 'margin-left': Math.round(eWidth.getSize().x / 2 - element.getSize().x / 2)294 });295};296Ngn.tpl = function(tpl, data) {297 return tpl.replace(/\{(\w+)\}/g, function(str, name) {298 return data[name] ? data[name] : '';299 });300};301Ngn.initSubmit = function(eForm) {302 var btnSubmit = eForm.getElement('input[type=submit]');303 if (!btnSubmit) return;304 var submiting = false;305 btnSubmit.addEvent('click', function(e) {306 e.preventDefault();307 if (submiting) return;...
jsSlideShow.class.js
Source:jsSlideShow.class.js
...247 }).fade('out');248 }],249 */250 ['pushLeft', function(previous, next, duration, instance){251 var distance = instance.element.getSize().x;252 next.setStyle('left', distance);253 new Fx.Elements([previous,next],{duration: duration}).start({254 0: { left: [-distance] },255 1: { left: [0] }256 });257 return this;258 }],259 ['pushRight', function(p,n,d,i){260 var distance = i.element.getSize().x;261 n.setStyle('left', -distance);262 new Fx.Elements([p,n],{duration: d}).start({263 0: { left: [distance] },264 1: { left: [0] }265 });266 return this;267 }],268 ['pushUp', function(p,n,d,i){269 var distance = i.element.getSize().y;270 n.setStyle('top', distance);271 new Fx.Elements([p,n],{duration: d}).start({272 0: { top: [-distance] },273 1: { top: [0] }274 });275 return this;276 }],277 ['pushDown', function(p,n,d,i){278 var distance = i.element.getSize().y;279 n.setStyle('top', -distance);280 new Fx.Elements([p,n],{duration: d}).start({281 0: { top: [distance] },282 1: { top: [0] }283 });284 return this;285 }],286 ['blindRight', function(p,n,d,i){287 var distance = i.element.getSize().x;288 n.setStyles({289 left: -distance,290 'z-index': 2291 }).set('tween',{duration: d}).tween('left',0);292 return this;293 }],294 ['blindLeft', function(p,n,d,i){295 var distance = i.element.getSize().x;296 n.setStyles({297 left: distance,298 'z-index': 2299 }).set('tween',{duration: d}).tween('left',0);300 return this;301 }],302 ['blindUp', function(p,n,d,i){303 var distance = i.element.getSize().y;304 n.setStyles({305 top: distance,306 'z-index': 2307 }).set('tween',{duration: d}).tween('top',0);308 return this;309 }],310 ['blindDown', function(p,n,d,i){311 var distance = i.element.getSize().y;312 n.setStyles({313 top: -distance,314 'z-index': 2315 }).set('tween',{duration: d}).tween('top',0);316 return this;317 }],318 ['blindDownFade', function(p,n,d,i){319 this.blindDown(p,n,d,i).fade(p,n,d,i);320 }],321 ['blindUpFade', function(p,n,d,i){322 this.blindUp(p,n,d,i).fade(p,n,d,i);323 }],324 ['blindLeftFade', function(p,n,d,i){325 this.blindLeft(p,n,d,i).fade(p,n,d,i);...
SlideShow.js
Source:SlideShow.js
...237 }).fade('out');238 }],239 240 ['pushLeft', function(previous, next, duration, instance){241 var distance = instance.element.getSize().x;242 next.setStyle('left', distance);243 new Fx.Elements([previous,next],{duration: duration}).start({244 0: { left: [-distance] },245 1: { left: [0] }246 });247 return this;248 }],249 ['pushRight', function(p,n,d,i){250 var distance = i.element.getSize().x;251 n.setStyle('left', -distance);252 new Fx.Elements([p,n],{duration: d}).start({253 0: { left: [distance] },254 1: { left: [0] }255 });256 return this;257 }],258 ['pushUp', function(p,n,d,i){259 var distance = i.element.getSize().y;260 n.setStyle('top', distance);261 new Fx.Elements([p,n],{duration: d}).start({262 0: { top: [-distance] },263 1: { top: [0] }264 });265 return this;266 }],267 ['pushDown', function(p,n,d,i){268 var distance = i.element.getSize().y;269 n.setStyle('top', -distance);270 new Fx.Elements([p,n],{duration: d}).start({271 0: { top: [distance] },272 1: { top: [0] }273 });274 return this;275 }],276 ['blindRight', function(p,n,d,i){277 var distance = i.element.getSize().x;278 n.setStyles({279 left: -distance,280 'z-index': 2281 }).set('tween',{duration: d}).tween('left',0);282 return this;283 }],284 ['blindLeft', function(p,n,d,i){285 var distance = i.element.getSize().x;286 n.setStyles({287 left: distance,288 'z-index': 2289 }).set('tween',{duration: d}).tween('left',0);290 return this;291 }],292 ['blindUp', function(p,n,d,i){293 var distance = i.element.getSize().y;294 n.setStyles({295 top: distance,296 'z-index': 2297 }).set('tween',{duration: d}).tween('top',0);298 return this;299 }],300 ['blindDown', function(p,n,d,i){301 var distance = i.element.getSize().y;302 n.setStyles({303 top: -distance,304 'z-index': 2305 }).set('tween',{duration: d}).tween('top',0);306 return this;307 }],308 ['blindDownFade', function(p,n,d,i){309 this.blindDown(p,n,d,i).fade(p,n,d,i);310 }],311 ['blindUpFade', function(p,n,d,i){312 this.blindUp(p,n,d,i).fade(p,n,d,i);313 }],314 ['blindLeftFade', function(p,n,d,i){315 this.blindLeft(p,n,d,i).fade(p,n,d,i);...
TrailNav.js
Source:TrailNav.js
...25 x.parentNav = this;26 }.bind( this ) );27 28 // scroll the parent element - it has the scroll bar29 var scroll = this.element.getSize().scrollSize;30 if( scroll.x - 400 > 0 ) this.element.getParent().scrollTo( scroll.x - 400, 0 );31 var br = this.element.appendChild(new Element('br'));32 br.className = 'clear';33 34 this.hideLoader();35 36 // add the two left and right control37 //this.createNavControls();38 },39 40 /*41 Show the loader.42 */43 showLoader : function()44 {45 this.loader = new Element( 'div', {46 'class' : 'TrailLoader'47 });48 this.loader.injectInside( document.body );49 this.loader.setStyle( 'bottom', '50' );50 },51 /*52 Remove the loader53 */54 hideLoader : function()55 {56 this.loader.remove();57 },58 59 /*60 Add a shift to the end of the nav61 */62 addShift : function( json )63 {64 // make sure there are no <br> elements65 this.element.getElements( 'br' ).each( function(x) { x.remove(); } );66 var newShift = new TrailNavPage( json );67 68 newShift.element.injectInside( this.element );69 newShift.parentNav = this;70 71 // update data72 this.pages.push( newShift );73 this.dict[newShift.id] = newShift;74 75 // modify the width of the element when a shift is added76 var width = this.element.getSize().size.x;77 this.element.setStyle( 'width', width + 185 );78 },79 80 /*81 Show the shift.82 */83 showShift : function( id )84 {85 this.dict[id].show();86 // modify the width of the element when a shift is added87 var width = this.element.getSize().size.x;88 var newWidth = width + 185;89 90 this.element.setStyle( 'width', newWidth );91 },92 93 /*94 Hide a shift.95 */96 hideShift : function( id )97 {98 // modify the width of the nav area99 var width = this.element.getSize().size.x;100 var newWidth = width - 185;101 102 // make sure the width of the scrollable area is not less than that of the window103 if( newWidth >= window.getWidth()+400 )104 {105 this.element.setStyle( 'width', width - 185 );106 }107 },108 109 /*110 Start the scrolling timer.111 */112 startScrollLeft : function()113 {...
Resizable.js
Source:Resizable.js
...30 if(this.options.mode == 'horizontal'){31 this.isHorizontal = true;32 this.options.modifiers.y = false;33 this.firstProperty = 'width';34 this.handleSize = this.element.getSize().x;35 if(this.options.invert){36 this.first = this.element.getNext();37 this.second = this.element.getPrevious();38 this.secondProperty = 'right';39 this.options.modifiers.x = 'right';40 } else {41 this.first = this.element.getPrevious();42 this.second = this.element.getNext();43 this.secondProperty = 'left';44 this.options.modifiers.x = 'left';45 }46 } else {47 this.isHorizontal = false;48 this.options.modifiers.x = false;49 this.firstProperty = 'height';50 this.handleSize = this.element.getSize().y;51 if(this.options.invert){52 this.first = this.element.getNext();53 this.second = this.element.getPrevious();54 this.secondProperty = 'bottom';55 this.options.modifiers.y = 'bottom';56 } else {57 this.first = this.element.getPrevious();58 this.second = this.element.getNext();59 this.secondProperty = 'top';60 this.options.modifiers.y = 'top';61 }62 }63 64 if(this.options.addToResizableLimits){...
crossfade.js
Source:crossfade.js
...48 styles: {49 position: 'absolute',50 top: 0,51 left: 0,52 width: this.element.getSize().x,53 height: this.element.getSize().y,54 'background-image': 'url("' + this.imageOver + '")',55 'background-color': this.options.backgroundColor,56 opacity: 0,57 'z-index': this.element.getStyle('z-index').toInt() + 158 }59 });6061 if(this.element.get('tag') == 'div')62 {63 this.cover.inject(this.element);64 if(this.element.getStyle('position'))65 this.element.setStyle('position', 'relative');66 }67 else if(this.element.get('tag') == 'img')68 {69 $(document.body).adopt(this.cover);70 }7172 this.fx = new Fx.Tween(this.cover, this.options.fx);7374 this.element.addEvent('mouseenter', function(){75 this.fireEvent('startShow');76 this.show();77 this.fireEvent('show');78 }.bind(this));7980 if(this.element.get('tag') == 'div')81 {82 this.element.addEvent('mouseleave', function(){83 this.fireEvent('startHide');84 this.hide();85 this.fireEvent('hide');86 }.bind(this));87 }88 else if(this.element.get('tag') == 'img')89 {90 this.element.addEvents({91 load: function(){92 this.cover.setPosition({93 x: this.element.getPosition($(document.body)).x,94 y: this.element.getPosition($(document.body)).y95 });9697 this.cover.setStyles({98 width: this.element.getSize().x,99 height: this.element.getSize().y100 });101102 }.bind(this),103 mouseleave: function(){104 if(this.cover.getStyle('opacity') == 0)105 this.cover.fireEvent('mouseleave');106 }.bind(this)107 });108109 this.cover.addEvent('mouseleave', function(){110 this.fireEvent('startHide');111 this.hide();112 this.fireEvent('hide');113 }.bind(this));
...
dialog_definition.js
Source:dialog_definition.js
1CKEDITOR.on(2 'dialogDefinition',3 function(event) {4 if (event.editor === ckEditor) {5 var dialogDefinition = event.data.definition;6 var onShow = dialogDefinition.onShow;7 dialogDefinition.onShow = function() {8 if (typeof onShow === 'function') {9 onShow.apply(this, arguments);10 }11 if (window.top != window.self) {12 var editorElement = this.getParentEditor().container;13 var documentPosition = editorElement.getDocumentPosition();14 var dialogSize = this.getSize();15 var x = documentPosition.x + ((editorElement.getSize('width', true) - dialogSize.width) / 2);16 var y = documentPosition.y + ((editorElement.getSize('height', true) - dialogSize.height) / 2);17 this.move(x, y, false);18 }19 };20 }21 }...
Using AI Code Generation
1var size = element.getSize();2console.log(size.width);3console.log(size.height);4var location = element.getLocation();5console.log(location.x);6console.log(location.y);7var text = element.getText();8console.log(text);9var attribute = element.getAttribute("attributeName");10console.log(attribute);11var cssValue = element.getCssValue("cssPropertyName");12console.log(cssValue);13var isDisplayed = element.isDisplayed();14console.log(isDisplayed);15var isEnabled = element.isEnabled();16console.log(isEnabled);17var isSelected = element.isSelected();18console.log(isSelected);19element.submit();20element.clear();21element.click();22element.sendKeys("text");23element.touch("tap", { x: 10, y: 10 });24element.touch("swipe", { start: { x: 10, y: 10 }, end: { x: 20, y: 20 } });25element.touch("pinch", { scale: 2 });26element.touch("zoom", { scale: 2 });
Using AI Code Generation
1var size = element.getSize();2console.log(size.width);3console.log(size.height);4var location = element.getLocation();5console.log(location.x);6console.log(location.y);7var text = element.getText();8console.log(text);9var attribute = element.getAttribute();10console.log(attribute);11var isDisplayed = element.isDisplayed();12console.log(isDisplayed);13var isEnabled = element.isEnabled();14console.log(isEnabled);15var isSelected = element.isSelected();16console.log(isSelected);17element.click();18element.sendKeys();19element.clear();20element.submit();21var isDisplayed = element.isDisplayed();22console.log(isDisplayed);23var isEnabled = element.isEnabled();24console.log(isEnabled);25var isSelected = element.isSelected();26console.log(isSelected);27element.click();28element.sendKeys();29element.clear();30element.submit();31var isDisplayed = element.isDisplayed();32console.log(isDisplayed);33var isEnabled = element.isEnabled();34console.log(isEnabled);35var isSelected = element.isSelected();36console.log(isSelected);37element.click();38element.sendKeys();39element.clear();40element.submit();41var isDisplayed = element.isDisplayed();42console.log(isDisplayed);
Using AI Code Generation
1var size = driver.findElement(By.id('com.example.myapp:id/my_element')).getSize();2console.log(size.width);3console.log(size.height);4var location = driver.findElement(By.id('com.example.myapp:id/my_element')).getLocation();5console.log(location.x);6console.log(location.y);7driver.findElement(By.id('com.example.myapp:id/my_element')).getText().then(function(text) {8 console.log(text);9});10driver.findElement(By.id('com.example.myapp:id/my_element')).getAttribute('content-desc').then(function(text) {11 console.log(text);12});13driver.findElement(By.id('com.example.myapp:id/my_element')).isEnabled().then(function(isEnabled) {14 console.log(isEnabled);15});16driver.findElement(By.id('com.example.myapp:id/my_element')).isSelected().then(function(isSelected) {17 console.log(isSelected);18});19driver.findElement(By.id('com.example.myapp:id/my_element')).isDisplayed().then(function(isDisplayed) {20 console.log(isDisplayed);21});22driver.findElement(By.id('com.example.myapp:id/my_element')).clear();23driver.findElement(By.id('com.example.myapp:id/my_element')).sendKeys('Hello World');24driver.findElement(By.id('com.example.myapp:id/my_element')).submit();25driver.findElement(By.id('com.example.myapp:id/my_element')).click();26driver.findElement(By.id('com.example.myapp:id/my_element')).getTagName().then(function(tagName) {27 console.log(tagName);28});29driver.findElement(By.id('
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!!