Best JavaScript code snippet using appium-android-driver
pz_dialog.js
Source:pz_dialog.js
...146 this.mask.insertBefore(this.J_PZDialog).fadeIn(500);147 },148 setMaskCenter:function(){149 this.mask.css({150 width:this.getWindowSize().width+(/MSIE\s+6\.0/.test(window.navigator.userAgent)?document.documentElement.scrollLeft:0)+"px",151 height:this.getWindowSize().height+(/MSIE\s+6\.0/.test(window.navigator.userAgent)?document.documentElement.scrollTop:0)+"px"152 });153 },154 setDialogCenter:function(){//设置弹åºå±å±
䏿¾ç¤º155 var top=(this.getWindowSize().height-this.dialogHeight-10)/2<0?30:(this.getWindowSize().height-this.dialogHeight-20)/2;156 this.J_PZDialog.css({157 left:(this.getWindowSize().width-this.dialogWidth-10)/2+"px",158 top:top+"px"159 });160 },161 getWindowSize:function(){//è·åçªå£å¤§å°162 return {163 width:window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,164 height:window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight165 };166 },167 closeDialog:function(){168 var _this=this;169 //éèå¹¶å é¤å¯¹è¯æ¡170 this.J_PZDialog.fadeOut("fast",function(){171 _this.J_PZDialog.remove();172 });173 //éèå¹¶å é¤å¹å¸174 if(this.isMask){175 this.mask.fadeOut("fast",function(){176 _this.mask.remove();177 });178 };179 },180 addEvts:function(){//æ·»å ç¸å
³äºä»¶181 var _this=this;182 //ç»å
³éæé®æ·»å äºä»¶183 this.J_PZDialog_close.click(function(){184 _this.closeDialog();185 });186 //å½çªå£åçæ¹åçæ¶å宿¶è®¾ç½®å±
ä¸187 $(window).resize(function(){188 //ä¼ååå¤è°æ´çªå£å¤§å°å¸¦æ¥çé»å¡189 window.clearTimeout(t);190 var t=window.setTimeout(function(){191 _this.setDialogCenter() ;192 },300);193 //妿å¼èµ·å¹å¸ï¼å°±å®æ¶è°æ´å¤§å°194 if(_this.isMask){195 _this.setMaskCenter();196 };197 });198 //å
¼å®¹ie6199 if(/MSIE\s+6\.0/.test(window.navigator.userAgent)){200 $(window).scroll(function(){201 if(_this.isMask){202 _this.mask.height(_this.getWindowSize().height+document.documentElement.scrollTop+"px");203 };204 _this.J_PZDialog.css("top",(_this.getWindowSize().height-_this.dialogHeight-10)/2+document.documentElement.scrollTop-100+"px");205 });206 };207 },208 insertDialogDOM:function(){ //å建DOMç»æ209 this.J_PZDialog=$("<div class='J_PZDialog'></div>"),//å建弹åºå±æå¤å±DOM210 this.J_PZDialog_box=$("<div class='J_PZDialog_box'></div>"),//å建å
å±inner211 this.J_PZDialog_caption=$("<div class='popHd iw'></div>"),//å建弹åºå±å¤´212 this.J_PZDialog_close=$("<i class='icon_close'></i>"),//å建å
³éæé®213 this.J_PZDialog_caption_text=$("<span class='J_PZDialog_caption_text'></span>"),//åå»ºææ¬æç¤ºä¿¡æ¯214 this.J_PZDialog_content=$("<div class='popBd'></div>");//å建å
容åºå215 //æ¼æ¥DOMç»æ216 this.J_PZDialog.append(this.J_PZDialog_box);217 this.J_PZDialog_box.append(this.J_PZDialog_caption,this.J_PZDialog_content);218 this.J_PZDialog_caption.append(this.J_PZDialog_close,this.J_PZDialog_caption_text);219 //设置æç¤ºæ¡ææ¬220 this.J_PZDialog_caption_text.html(this.dialogText);221 //为äºå
¼å®¹IE8 ä¸ä¸ï¼è¿ééè¦æå®J_PZDialog_boxç宽度222 this.J_PZDialog_box.width(this.dialogWidth);223 //è®¾ç½®å¯¹è¯æ¡çæ´ä½å®½é«224 this.J_PZDialog.width(this.dialogWidth);225 this.J_PZDialog.height(this.dialogHeight);226 //è®¾ç½®å¯¹è¯æ¡å±
䏿¾ç¤º227 this.setDialogCenter();228 //ç»å®ç¸å
³äºä»¶229 this.addEvts();230 //æå
¥å°æåºé¨231 this.J_PZDialog.appendTo(document.body).fadeIn(500); 232 //妿å¼èµ·å¹å¸é®ç½©233 if(this.isMask){234 this.createMask();235 } 236 //妿Dialogç±»ååå¨237 if(this.dialogType=="alert"){238 //设置alertå
容239 this.setDialogAlert();240 }else if(this.dialogType=="confirm"){241 this.setDialogConfirm();242 }else if(this.dialogType=="tips"){243 this.setDialogTips();244 }else if(this.dialogType=="prompt"){245 this.setDialogPrompt();246 }else{247 this.setDialogDef();248 //妿æ¯ä¹äººå¼¹çª,å¹¶ä¸å¼èµ·äºæå¨ï¼å°±è¦é»æ¢å
³éæé®äºä»¶å泡249 if(this.dialogDrag){250 this.J_PZDialog_close.mousedown(function(e){e.stopPropagation();});251 };252 };253 //妿é
ç½®äºæå¨åæ°254 if(this.dialogDrag){255 this.J_PZDialog_caption.css("cursor","move");256 new PZ_DND({257 handle:this.J_PZDialog_caption,258 target:this.J_PZDialog259 });260 };261 }262};263//注åå°å
¨å±å¯¹è±¡264window["PZ_Dialog"]=PZ_Dialog;265/**266@åºäºjQueryææ¾å½æ°267@new PZ_DND({268 handle:this.J_PZDialog_caption, //æå®æå¨çææ269 target:this.J_PZDialog //æå®æå¨çç®æ å
ç´ 270 });271@æ¨æ°¸272@QQ:377746756273@call:18911082352274@çæ¬:1.0275*/276function PZ_DND(args){277 var _this_=this;278 //åå§ååæ°279 this.handle=args.handle;280 this.target=args.target;281 //ç»å®äºä»¶282 this.handle.mousedown(function(evt){283 //为äºè§£å³ieé¼ æ ç§»é¤æµè§å¨æ æ³ææ284 if(this.setCapture){this.setCapture();};285 evt.preventDefault();286 //è·åé¼ æ ç¸å¯¹äºæå¨ç®æ çåç§»287 var $this=this,288 layerX=_this_.getLayerPos(evt).x,289 layerY=_this_.getLayerPos(evt).y;290 //注ådocumentç§»å¨äºä»¶291 $(document).mousemove(function(evt){292 evt.preventDefault();293 _this_.move(evt,layerX,layerY);294 }).mouseup(function(){295 $(this).unbind("mousemove");296 $(this).unbind("mouseup");297 //åæ¶ieé¼ æ ç§»é¤æµè§å¨æ æ³ææ298 if(this.releaseCapture){this.releaseCapture();};299 _this_.target.css({300 opacity:1301 });302 });303 //é¼ æ æä¸æå¨æ¶çæ ·å¼304 _this_.target.css({305 opacity:0.8306 });307 });308};309PZ_DND.prototype={310 setTargetPos:function(left,top){311 //鲿¢å æ»å¨æ¡äº§ççè·ç¦»312 if(!/MSIE\s+6\.0/.test(window.navigator.userAgent)){//ie6ä¸éè¦å313 left=left-(document.documentElement.scrollLeft||document.body.scrollLeft);314 top=top-(document.documentElement.scrollTop||document.body.scrollTop);315 };316 top=top<0?0:top>(this.getWindowSize().height-this.target.get(0).offsetHeight)?this.getWindowSize().height-this.target.get(0).offsetHeight:top;317 left=left<0?0:left>(this.getWindowSize().width-this.target.get(0).offsetWidth)?this.getWindowSize().width-this.target.get(0).offsetWidth:left;318 this.target.css({319 left:left+"px",320 top:top+"px"321 });322 },323 move:function(evt,layerX,layerY){//é¼ æ å¨documentä¸ç§»å¨è¦æ§è¡ç彿°324 this.setTargetPos(evt.pageX-layerX,evt.pageY-layerY); 325 },326 getLayerPos:function(evt){//è·åé¼ æ ç¸å¯¹äºæå¨ç®æ çåç§»327 return {328 x:evt.pageX-this.target.offset().left,329 y:evt.pageY-this.target.offset().top330 };331 },...
dwz.scrollCenter.js
Source:dwz.scrollCenter.js
...15 // æ©å±åæ°16 var op = $.extend({ z: 1000000, mode:"WH"}, options);17 18 // 追å å° document.body 并设置å
¶æ ·å¼19 var windowSize = this.getWindowSize();20 return this.each(function(){21 var $this = $(this).css({22 'position': 'absolute',23 'z-index': op.z24 });25 26 // å½åä½ç½®åæ°27 var bodyScrollTop = $(document).scrollTop();28 var bodyScrollLeft = $(document).scrollLeft();29 var movedivTop = (windowSize.height - $this.height()) / 2 + bodyScrollTop;30 var movedivLeft = (windowSize.width - $this.width()) / 2 + bodyScrollLeft;31 32 if (op.mode == "W") {33 $this.appendTo(document.body).css({34 'left': movedivLeft + 'px'35 });36 } else if (op.model == "H"){37 $this.appendTo(document.body).css({38 'top': movedivTop + 'px'39 }); 40 } else {41 $this.appendTo(document.body).css({42 'top': (windowSize.height - $this.height()) / 2 + $(window).scrollTop() + 'px',43 'left': movedivLeft + 'px'44 });45 }46 47 // æ»å¨äºä»¶48 $(window).scroll(function(e){49 var windowSize = $this.getWindowSize();50 var tmpBodyScrollTop = $(document).scrollTop();51 var tmpBodyScrollLeft = $(document).scrollLeft();52 53 movedivTop += tmpBodyScrollTop - bodyScrollTop;54 movedivLeft += tmpBodyScrollLeft - bodyScrollLeft;55 bodyScrollTop = tmpBodyScrollTop;56 bodyScrollLeft = tmpBodyScrollLeft;57 // 以å¨ç»æ¹å¼è¿è¡ç§»å¨58 if (op.mode == "W") {59 $this.stop().animate({60 'left': movedivLeft + 'px'61 });62 } else if (op.mode == "H") {63 $this.stop().animate({64 'top': movedivTop + 'px'65 });66 } else {67 $this.stop().animate({68 'top': movedivTop + 'px',69 'left': movedivLeft + 'px'70 });71 }72 73 });74 75 // çªå£å¤§å°é设äºä»¶76 $(window).resize(function(){77 var windowSize = $this.getWindowSize();78 movedivTop = (windowSize.height - $this.height()) / 2 + $(document).scrollTop();79 movedivLeft = (windowSize.width - $this.width()) / 2 + $(document).scrollLeft();80 81 if (op.mode == "W") {82 $this.stop().animate({83 'left': movedivLeft + 'px'84 });85 } else if (op.mode == "H") {86 $this.stop().animate({87 'top': movedivTop + 'px'88 });89 } else {90 $this.stop().animate({91 'top': movedivTop + 'px',...
Renderer.js
Source:Renderer.js
...19 /**20 * Set the stores width and height on resize21 */22 setStore() {23 RendererStore.set('width', this.getWindowSize()[0]);24 RendererStore.set('height', this.getWindowSize()[1]);25 RendererStore.set('stageCenter', new PIXI.Point(this.getWindowSize()[0] / 2, this.getWindowSize()[1] / 2));26 }27 /**28 * Start the animation loop29 * @return {null}30 */31 start() {32 this.active = true;33 window.requestAnimationFrame(this.animate.bind(this));34 }35 /**36 * Stop the animation loop37 * @return {null}38 */39 stop() {40 this.active = false;41 }42 /**43 * Main animation loop, updates animation store44 * @return {null}45 */46 animate() {47 stats.begin();48 this.renderRenderables();49 if(this.active) {50 window.requestAnimationFrame(this.animate.bind(this));51 AnimationStore.emitChange();52 }53 stats.end();54 }55 /**56 * Sets's store and emits Change57 * @return {null}58 */59 resizeHandler() {60 this.resize(...this.getWindowSize());61 this.setStore();62 RendererStore.emitChange();63 }64 /**65 * Get the current window size66 * @return {null}67 */68 getWindowSize() {69 var width = window.innerWidth;70 var height = window.innerHeight;71 return [width, height];72 }73 /**74 * Add a renderable object to the animation loop...
MainNav.js
Source:MainNav.js
...13 mobile:false,14 }15 componentDidMount(){16 //mount get window size method17 this.getWindowSize()18 //bind this to VR DOM19 window.addEventListener("resize", this.getWindowSize.bind(this))20 }21 toggleMobileView = () =>{22 //toggle mobile state to true or false23 this.setState({mobile:!this.state.mobile}, () => '')24 }25 activeLink = (value) =>{26 // let target = document.querySelectorAll(['data-name=${value}']);27 // console.log(target)28 }29 getWindowSize = () => {30 const {mobile} = this.state31 //check if window size is greater than 700px and mobile state is true...
viewportMixin.js
Source:viewportMixin.js
...12 },13 mounted() {14 this.$nextTick(() => {15 window.addEventListener("resize", this.getWindowSize);16 this.getWindowSize();17 });18 },19 methods: {20 getWindowSize() {21 this.windowWidth = document.documentElement.clientWidth;22 this.windowHeight = document.documentElement.clientHeight;23 }24 },25 beforeDestroy() {26 window.removeEventListener("resize", this.getWindowSize);27 }...
resize.js
Source:resize.js
...6 }7 },8 created () {9 window.addEventListener('resize', this.getWindowSize)10 this.getWindowSize()11 },12 mounted () {13 this.getWindowSize()14 },15 beforeDestroy () {16 window.removeEventListener('resize', this.getWindowSize)17 },18 methods: {19 getWindowSize () {20 if (this.$el) {21 this.windowHeight = this.$el.clientHeight22 this.windowWidth = this.$el.clientWidth23 }24 }25 }...
window_size.js
Source:window_size.js
...6 }7 },8 created () {9 window.addEventListener('resize', this.getWindowSize)10 this.getWindowSize()11 },12 mounted () {13 this.getWindowSize()14 },15 beforeDestroy () {16 window.removeEventListener('resize', this.getWindowSize)17 },18 methods: {19 getWindowSize () {20 if (this.$el) {21 this.windowHeight = this.$el.clientHeight22 this.windowWidth = this.$el.clientWidth23 }24 }25 }...
Using AI Code Generation
1 withCapabilities({2 build();3driver.getWindowSize().then(function(size) {4 console.log("Width: " + size.width);5 console.log("Height: " + size.height);6});7driver.quit();
Using AI Code Generation
1var windowSize = driver.getWindowSize();2var windowWidth = windowSize.width;3var windowHeight = windowSize.height;4driver.takeScreenshot().then(function(image, err) {5 require('fs').writeFile('screenshot.png', image, 'base64', function(err) {6 console.log(err);7 });8});9driver.getWindowSize().then(function(size) {10 console.log(size);11});12driver.getWindowSize().then(function(size) {13 console.log(size.width);14 console.log(size.height);15});16driver.getWindowSize().then(function(size) {17 console.log(size);18});19driver.getWindowSize().then(function(size) {20 console.log(size.width);21 console.log(size.height);22});23driver.getWindowSize().then(function(size) {24 console.log(size);25});26driver.getWindowSize().then(function(size) {27 console.log(size.width);28 console.log(size.height);29});30driver.getWindowSize().then(function(size) {31 console.log(size);32});33driver.getWindowSize().then(function(size) {34 console.log(size.width);35 console.log(size.height);36});37driver.getWindowSize().then(function(size) {38 console.log(size);39});40driver.getWindowSize().then(function(size) {41 console.log(size.width);42 console.log(size.height);43});44driver.getWindowSize().then(function(size) {45 console.log(size);46});47driver.getWindowSize().then(function(size) {48 console.log(size.width);49 console.log(size.height);50});51driver.getWindowSize().then(function(size) {52 console.log(size);53});54driver.getWindowSize().then(function(size) {55 console.log(size.width);56 console.log(size.height);57});58driver.getWindowSize().then(function(size) {59 console.log(size);60});61driver.getWindowSize().then(function(size) {62 console.log(size.width);63 console.log(size.height);64});65driver.getWindowSize().then(function(size) {66 console.log(size);67});68driver.getWindowSize().then(function(size) {69 console.log(size.width);70 console.log(size.height);71});72driver.getWindowSize().then(function(size) {73 console.log(size);74});75driver.getWindowSize().then(function
Using AI Code Generation
1var webdriverio = require('webdriverio');2var options = {3desiredCapabilities: {4}5};6var client = webdriverio.remote(options);7.init()8.getWindowSize().then(function(size) {9console.log(size);10})11.end();12var wd = require('wd');13var driver = wd.remote('localhost', 4723);14driver.init({15}, function() {16driver.getWindowSize(function(err, size) {17console.log(size);18});19});20var webdriverio = require('webdriverio');21var options = {22desiredCapabilities: {23}24};25var client = webdriverio.remote(options);26.init()27.setWindowSize(400, 600)28.end();
Using AI Code Generation
1var wd = require('wd');2var driver = wd.promiseChainRemote('localhost', 4723);3var assert = require('assert');4var desiredCaps = {5};6driver.init(desiredCaps)7 .then(function () {8 return driver.getWindowSize();9 })10 .then(function (size) {11 console.log(size);12 })13 .catch(function (err) {14 console.log(err);15 });16var wd = require('wd');17var driver = wd.promiseChainRemote('localhost', 4723);18var assert = require('assert');19var desiredCaps = {20};21driver.init(desiredCaps)22 .then(function () {23 return driver.getWindowSize();24 })25 .then(function (size) {26 console.log(size);27 })28 .catch(function (err) {29 console.log(err);30 });31var wd = require('wd');32var driver = wd.promiseChainRemote('localhost', 4723);33var assert = require('assert');34var desiredCaps = {35};36driver.init(desiredCaps)37 .then(function () {38 return driver.getWindowSize();39 })40 .then(function (size) {41 console.log(size);42 })43 .catch(function (err) {44 console.log(err);45 });46var wd = require('wd');47var driver = wd.promiseChainRemote('localhost', 4723);48var assert = require('assert');49var desiredCaps = {50};51driver.init(desiredCaps)52 .then(function () {
Using AI Code Generation
1var driver = appium.getDriver();2var size = driver.getWindowSize();3console.log("Window size is " + size.width + "x" + size.height);4var driver = appium.getDriver();5var orientation = driver.getOrientation();6console.log("Orientation is " + orientation);7var driver = appium.getDriver();8driver.rotate("LANDSCAPE");9var driver = appium.getDriver();10var networkConnection = driver.getNetworkConnection();11console.log("Network Connection is " + networkConnection);12var driver = appium.getDriver();13driver.setNetworkConnection(1);14var driver = appium.getDriver();15var deviceTime = driver.getDeviceTime();16console.log("Device Time is " + deviceTime);17var driver = appium.getDriver();18var performanceData = driver.getPerformanceData("com.android.chrome", "memoryinfo", 1000);19console.log("Performance Data is " + performanceData);20var driver = appium.getDriver();21var performanceDataTypes = driver.getPerformanceDataTypes();22console.log("Performance Data Types are " + performanceDataTypes);23var driver = appium.getDriver();24var performanceDataTypes = driver.getPerformanceDataTypes();25console.log("Performance Data Types are " + performanceDataTypes);26var driver = appium.getDriver();27var performanceDataTypes = driver.getPerformanceDataTypes();28console.log("Performance Data Types are " + performanceDataTypes);29var driver = appium.getDriver();
Using AI Code Generation
1var driver = wd.remote({browserName:'chrome'});2driver.init({browserName:'chrome'}, function(){3 driver.getWindowSize(function(err, size){4 console.log('Size of the window is ' + JSON.stringify(size));5 });6});7Size of the window is {"width":360,"height":640}
Using AI Code Generation
1var driver = new AndroidDriver();2var windowSize = driver.getWindowSize();3AndroidDriver.prototype.getWindowSize = function (windowHandle, cb) {4 var cmd = 'getWindowSize';5 if (windowHandle) {6 cmd += ' ' + windowHandle;7 }8 this.proxy(cmd, cb);9};10AndroidDriver.prototype.proxy = function (command, cb) {11 var self = this;12 var args = _.toArray(arguments);13 command = args.shift();14 cb = args.pop();15 args.unshift(this.proxyReq.bind(this));16 args.push(function (err, res) {17 if (err) {18 return cb(err);19 }20 if (res.status !== 0) {21 return cb(new Error("Proxy error: " + JSON.stringify(res)));22 }23 cb(null, res.value);24 });25 async.waterfall(args);26};27AndroidDriver.prototype.proxyReq = function (command, cb) {28 var self = this;29 var args = _.toArray(arguments);30 command = args.shift();31 cb = args.pop();32 args.unshift(self.proxyReqRes.bind(self));33 args.push(function (err, res) {34 if (err) {35 return cb(err);36 }37 if (res.statusCode !== 200) {38 return cb(new Error("Proxy error: " + res.body));39 }40 cb(null, JSON.parse(res.body));41 });42 async.waterfall(args);43};44AndroidDriver.prototype.proxyReqRes = function (command, cb) {45 var self = this;46 var args = _.toArray(arguments);47 command = args.shift();48 cb = args.pop();49 args.unshift(self.proxyReqResBind.bind(self));50 args.push(function (err, res) {51 if (err) {52 return cb(err);53 }54 cb(null, res);55 });56 async.waterfall(args);57};58AndroidDriver.prototype.proxyReqResBind = function (command, cb) {59 var self = this;60 var args = _.toArray(arguments);
Check out the latest blogs from LambdaTest on this topic:
The automation backend architecture of Appium has undergone significant development along with the release of numerous new capabilities. With the advent of Appium, test engineers can cover mobile apps, desktop apps, Flutter apps, and more.
JUnit is one of the most popular unit testing frameworks in the Java ecosystem. The JUnit 5 version (also known as Jupiter) contains many exciting innovations, including support for new features in Java 8 and above. However, many developers still prefer to use the JUnit 4 framework since certain features like parallel execution with JUnit 5 are still in the experimental phase.
Automation frameworks enable automation testers by simplifying the test development and execution activities. A typical automation framework provides an environment for executing test plans and generating repeatable output. They are specialized tools that assist you in your everyday test automation tasks. Whether it is a test runner, an action recording tool, or a web testing tool, it is there to remove all the hard work from building test scripts and leave you with more time to do quality checks. Test Automation is a proven, cost-effective approach to improving software development. Therefore, choosing the best test automation framework can prove crucial to your test results and QA timeframes.
A good User Interface (UI) is essential to the quality of software or application. A well-designed, sleek, and modern UI goes a long way towards providing a high-quality product for your customers − something that will turn them on.
With new-age project development methodologies like Agile and DevOps slowly replacing the old-age waterfall model, the demand for testing is increasing in the industry. Testers are now working together with the developers and automation testing is vastly replacing manual testing in many ways. If you are new to the domain of automation testing, the organization that just hired you, will expect you to be fast, think out of the box, and able to detect bugs or deliver solutions which no one thought of. But with just basic knowledge of testing, how can you be that successful test automation engineer who is different from their predecessors? What are the skills to become a successful automation tester in 2019? Let’s find out.
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!!