Best JavaScript code snippet using appium-xcuitest-driver
util.js
Source:util.js
1/**2 * è¿åä¸ä¸é¡µ3 */4function back(){5 window.history.back();6}7function refresh(){8 window.location.reload();9}10$(document).ready(function() {11 if(window.history.length<2){12 $(".back").remove();13 }14});15/**16 * æ¹éæ¾ç¤ºæéè对象(ædisplayå±æ§çhtmlå
ç´ é½å¯ä½¿ç¨)17 * @param objs åæ°ï¼id-none/block,å¤ä¸ªç¨|åé18 * @param displayValue å¯ä¸ä¼ å¼19 * è°ç¨ç¤ºä¾ï¼20 * 1ãdisplaySet('mortgageDiv-none|mortgageTypeDiv-block')21 * 2ãdisplaySet('mortgageDiv|mortgageTypeDiv','none')22 */23function displaySet(objs,displayValue){24 displayValue = displayValue || 0;25 var objAry = objs.split('|');26 for(var i=0;i<objAry.length;i++){27 var obj = objAry[i].split('-');28 if(displayValue==0){29 $('#'+obj[0]+'').css('display',obj[1]);30 }else{31 $('#'+obj[0]+'').css('display',displayValue);32 }33 }34}35/**36 * æ¹é设置对象å±æ§å¼37 * @param objs åæ°:id-attrName-attrValue æè
id-attrValue38 * @param attrName å±æ§å称,å¯ä¸ä¼ å¼39 * 40 * è°ç¨ç¤ºä¾:41 * 1ã设置åä¸å±æ§çå¼ attrSet('guarantyOrganization-Require|pledgeSel-|creditSel-','dataType');42 * 2ãåç¬æå®æ¯ä¸ªå¯¹è±¡çå±æ§å¼ attrSet('guarantyOrganization-msg-ä¸è½ä¸ºç©º|guarantyOrganization-dataType-Require|creditSel-dataType-');43 */44function attrSet(objs,attrName){45 attrName = attrName || 0;46 var objAry = objs.split('|');47 for(var i=0;i<objAry.length;i++){48 var obj = objAry[i].split('-');49 if(attrName==0){50 $('#'+obj[0]+'').attr(obj[1],obj[2]);51 }else{52 $('#'+obj[0]+'').attr(attrName,obj[1]);53 }54 }55}56/**57 * æ¸
é¤é¦å°¾ç©ºæ ¼58 * @param obj 59 */60function forbidBlank(obj){61 obj.value = obj.value.replace(/(^\s*)|(\s*$)/g,"");62}63/**64 * å è½½éªè¯ç 65 * @param id66 * @param path67 */68function loadRandCodeImg(id,path){69 document.getElementById(id).src=path+'/random.jsp?'+Math.random();70}71function loadRandCodeImg1(id,path){72 document.getElementById(id).src=path+'/random.jsp?'+Math.random();73}74/**75 * å è½½å表(åæ°ä¾æ¬¡æ¯ï¼é¡µç ï¼æ¼æ¥é¡µç åçurl,ç¹å»çæé®idï¼å è½½å°ç大å表çid)76 */77function getFirstListData(version,realPath,urlStr,clickElementId,toElementId){78 var _load = layer.load('æ°æ®å è½½ä¸..');79 $.ajax({80 url : urlStr+"/1",81 type : 'post',82 dataType : 'text',83 success : function(data){84 layer.close(_load);85 if(data==null||$.trim(data)==''){86 $('#'+toElementId).append("<div class='mx-none'><p><i class='iconfont'></i></p><span>ææ æ°æ®</span></div><div style='height:4rem;'></div>");87 }else{88 $('#'+toElementId).append(data);89 $('#'+clickElementId).bind("click",{pageNum:2,urlStr:urlStr,clickElementId:clickElementId,toElementId:toElementId},addList);90 }91 },92 error : function(data) {93 layer.close(_load);94 layer.msg('ç½ç»è¿æ¥å¼å¸¸ï¼è¯·å·æ°é¡µé¢æç¨åéè¯ï¼', 1, 5);95 }96 });97}98/**99 * å è½½å表(åæ°ä¾æ¬¡æ¯ï¼é¡µç ï¼æ¼æ¥é¡µç åçurl,ç¹å»çæé®idï¼å è½½å°ç大å表çid)100 */101function addList(event){102 var _load = layer.load('æ°æ®å è½½ä¸..');103 $.ajax({104 url : event.data.urlStr+"/"+event.data.pageNum,105 type : 'post',106 dataType : 'text',107 success : function(data){108 layer.close(_load);109 $('#'+event.data.clickElementId).remove();110 $('#'+event.data.toElementId).append(data);111 $('#'+event.data.clickElementId).bind("click",{pageNum:event.data.pageNum+1,urlStr:event.data.urlStr,clickElementId:event.data.clickElementId,toElementId:event.data.toElementId},addList);112 },113 error : function(data) {114 layer.close(_load);115 layer.msg('ç½ç»è¿æ¥å¼å¸¸ï¼è¯·å·æ°é¡µé¢æç¨åéè¯ï¼', 1, 5);116 }117 });118}119/**120 * å è½½å表(åæ°ä¾æ¬¡æ¯ï¼é¡µç ï¼æ¼æ¥é¡µç åçurl,ç¹å»çæé®idï¼å è½½å°ç大å表çid)121 */122function getMoreData(version,realPath,urlStr,clickElementId,toElementId,toShowElementId){123 var _load = layer.load('æ°æ®å è½½ä¸..');124 $.ajax({125 url : urlStr+"/1",126 type : 'post',127 dataType : 'text',128 success : function(data){129 layer.close(_load);130 if(data==null||$.trim(data)==''){131 $('#'+toShowElementId).append("<div class='mx-none'><p><i class='iconfont'></i></p><span>ææ æ°æ®</span></div><div style='height:4rem;'></div>");132 }else{133 $('#'+toElementId).append(data);134 $('#'+clickElementId).bind("click",{pageNum:2,urlStr:urlStr,clickElementId:clickElementId,toElementId:toElementId,toShowElementId:toShowElementId},addMoreList);135 }136 },137 error : function(data) {138 layer.close(_load);139 layer.msg('ç½ç»è¿æ¥å¼å¸¸ï¼è¯·å·æ°é¡µé¢æç¨åéè¯ï¼', 1, 5);140 }141 });142}143/**144 * å è½½å表(åæ°ä¾æ¬¡æ¯ï¼é¡µç ï¼æ¼æ¥é¡µç åçurl,ç¹å»çæé®idï¼å è½½å°ç大å表çid)145 */146function addMoreList(event){147 var _load = layer.load('æ°æ®å è½½ä¸..');148 $.ajax({149 url : event.data.urlStr+"/"+event.data.pageNum,150 type : 'post',151 dataType : 'text',152 success : function(data){153 layer.close(_load);154 $('#'+event.data.clickElementId).remove();155 $('#'+event.data.toElementId).append(data);156 $('#'+event.data.clickElementId).bind("click",{pageNum:event.data.pageNum+1,urlStr:event.data.urlStr,clickElementId:event.data.clickElementId,toElementId:event.data.toElementId,toShowElementId:event.data.toShowElementId},addList);157 },158 error : function(data) {159 layer.close(_load);160 layer.msg('ç½ç»è¿æ¥å¼å¸¸ï¼è¯·å·æ°é¡µé¢æç¨åéè¯ï¼', 1, 5);161 }162 });163}164/**165 * éé¢è½¬æ¢ä¸ºå¤§å166 * @param Num167 * @returns168 */169function numToChinese(Num) {170 for (i = Num.length - 1; i >= 0; i--) {171 Num = Num.replace(",", "");172 Num = Num.replace(" ", "");173 }174 Num = Num.replace("ï¿¥", "")175 if (isNaN(Num)) {176 layer.msg("éé¢æ ¼å¼ä¸æ£ç¡®ã", 2, 5);177 return;178 }179 part = String(Num).split(".");180 newchar = "";181 for (i = part[0].length - 1; i >= 0; i--) {182 tmpnewchar = ""183 perchar = part[0].charAt(i);184 switch (perchar) {185 case "0":186 tmpnewchar = "é¶" + tmpnewchar;187 break;188 case "1":189 tmpnewchar = "壹" + tmpnewchar;190 break;191 case "2":192 tmpnewchar = "è´°" + tmpnewchar;193 break;194 case "3":195 tmpnewchar = "å" + tmpnewchar;196 break;197 case "4":198 tmpnewchar = "è" + tmpnewchar;199 break;200 case "5":201 tmpnewchar = "ä¼" + tmpnewchar;202 break;203 case "6":204 tmpnewchar = "é" + tmpnewchar;205 break;206 case "7":207 tmpnewchar = "æ" + tmpnewchar;208 break;209 case "8":210 tmpnewchar = "æ" + tmpnewchar;211 break;212 case "9":213 tmpnewchar = "ç" + tmpnewchar;214 break;215 }216 switch (part[0].length - i - 1) {217 case 0:218 tmpnewchar = tmpnewchar + "å
";219 break;220 case 1:221 if (perchar != 0)222 tmpnewchar = tmpnewchar + "æ¾";223 break;224 case 2:225 if (perchar != 0)226 tmpnewchar = tmpnewchar + "ä½°";227 break;228 case 3:229 if (perchar != 0)230 tmpnewchar = tmpnewchar + "ä»";231 break;232 case 4:233 tmpnewchar = tmpnewchar + "ä¸";234 break;235 case 5:236 if (perchar != 0)237 tmpnewchar = tmpnewchar + "æ¾";238 break;239 case 6:240 if (perchar != 0)241 tmpnewchar = tmpnewchar + "ä½°";242 break;243 case 7:244 if (perchar != 0)245 tmpnewchar = tmpnewchar + "ä»";246 break;247 case 8:248 tmpnewchar = tmpnewchar + "亿";249 break;250 case 9:251 tmpnewchar = tmpnewchar + "æ¾";252 break;253 }254 newchar = tmpnewchar + newchar;255 }256 if (Num.indexOf(".") != -1) {257 if (part[1].length > 2) {258 part[1] = part[1].substr(0, 2)259 }260 for (i = 0; i < part[1].length; i++) {261 tmpnewchar = ""262 perchar = part[1].charAt(i)263 switch (perchar) {264 case "0":265 tmpnewchar = "é¶" + tmpnewchar;266 break;267 case "1":268 tmpnewchar = "壹" + tmpnewchar;269 break;270 case "2":271 tmpnewchar = "è´°" + tmpnewchar;272 break;273 case "3":274 tmpnewchar = "å" + tmpnewchar;275 break;276 case "4":277 tmpnewchar = "è" + tmpnewchar;278 break;279 case "5":280 tmpnewchar = "ä¼" + tmpnewchar;281 break;282 case "6":283 tmpnewchar = "é" + tmpnewchar;284 break;285 case "7":286 tmpnewchar = "æ" + tmpnewchar;287 break;288 case "8":289 tmpnewchar = "æ" + tmpnewchar;290 break;291 case "9":292 tmpnewchar = "ç" + tmpnewchar;293 break;294 }295 if (i == 0)296 tmpnewchar = tmpnewchar + "è§";297 if (i == 1)298 tmpnewchar = tmpnewchar + "å";299 newchar = newchar + tmpnewchar;300 }301 }302 while (newchar.search("é¶é¶") != -1)303 newchar = newchar.replace("é¶é¶", "é¶");304 newchar = newchar.replace("é¶äº¿", "亿");305 newchar = newchar.replace("亿ä¸", "亿");306 newchar = newchar.replace("é¶ä¸", "ä¸");307 newchar = newchar.replace("é¶å
", "å
");308 newchar = newchar.replace("é¶è§", "");309 newchar = newchar.replace("é¶å", "");310 if (newchar.charAt(newchar.length - 1) == "å
" || newchar.charAt(newchar.length - 1) == "è§")311 newchar = newchar + "æ´";312 return newchar;313}314function downloadApp(path){315 /* 316 * æºè½æºæµè§å¨çæ¬ä¿¡æ¯: 317 */ 318 var browser={ 319 versions:function(){ 320 var u = navigator.userAgent, app = navigator.appVersion; 321 return {//移å¨ç»ç«¯æµè§å¨çæ¬ä¿¡æ¯ 322 trident: u.indexOf('Trident') > -1, //IEå
æ ¸ 323 presto: u.indexOf('Presto') > -1, //operaå
æ ¸ 324 webKit: u.indexOf('AppleWebKit') > -1, //è¹æãè°·æå
æ ¸ 325 gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //ç«çå
æ ¸ 326 mobile: !!u.match(/AppleWebKit.*Mobile.*/)||!!u.match(/AppleWebKit/), //æ¯å¦ä¸ºç§»å¨ç»ç«¯ 327 ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //iosç»ç«¯ 328 android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //androidç»ç«¯æè
ucæµè§å¨ 329 iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //æ¯å¦ä¸ºiPhoneæè
QQ HDæµè§å¨ 330 iPad: u.indexOf('iPad') > -1, //æ¯å¦iPad 331 webApp: u.indexOf('Safari') == -1 //æ¯å¦webåºè¯¥ç¨åºï¼æ²¡æ头é¨ä¸åºé¨ 332 }; 333 }(), 334 language:(navigator.browserLanguage || navigator.language).toLowerCase() 335 }; 336 if(browser.versions.ios){337 window.location.href="https://itunes.apple.com/us/app/id1086548123";338 }else if(browser.versions.android){339 window.location.href=path +"/images/download/android/zgz_v1.0.apk";340 }else{341 window.location.href=path +"/images/download/android/zgz_v1.0.apk";342 }343}344/**345 * æ ¼å¼åéé¢346 * @param s347 * @param n348 * @returns {string}349 */350function fmoney(s, n)351{352 n = n > 0 && n <= 20 ? n : 2;353 s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";354 var l = s.split(".")[0].split("").reverse(),355 r = s.split(".")[1];356 t = "";357 for(i = 0; i < l.length; i ++ )358 {359 t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");360 }361 return t.split("").reverse().join("") + "." + r;...
myjs.js
Source:myjs.js
1function bodyMargin(){2 document.getElementsByTagName("body").setAttribute("style","margin-top:"+document.getElementById('#fixed_header').offsetHeight+";"); 3}4function checkCookie(name) {5/* var nameEQ = name + "=";*/6// To print all cookies of current site7// var x= document.cookie;8// window.alert(x);9// To print all cookies of current site10 var ca = document.cookie.split('; '); // split(';'); --> will not work because after 1st cookie ; comes and then comes space so, 2nd cookie starts actually after space so split from there.11 for(var i=0;i < ca.length;i++) {12 var c = ca[i];13 var cnames = c.split('=');14 if(cnames[0] == name){15 return cnames[1];16 }17 }18 return null;19}20function validatePass(x){21 var pass = document.getElementById(x).value;22 if(pass.includes('"')){23 alert('Cant Use "(Double Inverted Commas) ');24 document.getElementById(x).value = "";25 }26}27function chk() {28 var mail = document.getElementById("txtMailId").value;29 if(validateMail(mail))30 {31 var cValue = checkCookie(mail);32 if(cValue != null)33 {34 var finalCValue = cValue.split('"');35 var a = finalCValue.length;36 if(a == 1){37 // Do Nothing38 }39 else{40 cValue = finalCValue[1];41 }42 if(cValue != null){43 document.getElementById("txtPassword").setAttribute("value",cValue);44 }45 }46 else if(cValue == null){47 document.getElementById("txtPassword").setAttribute("value","");48 }49 }50}51function confirmPass(){52 var pass= document.getElementById("pass").value;53 var pass1= document.getElementById("pass1").value;54 if(pass != pass1){55 alert("Password not same.");56 window.location.href="";57 }58}59function attachHref(appendingValueElementId,hrefTargetId,targetPage,targetAttributeToAppend){60 var mail = document.getElementById(appendingValueElementId).value;61 var tagetHref=targetPage+"?"+targetAttributeToAppend+"="+mail;62 document.getElementById(hrefTargetId).setAttribute("href",targetPage+"?"+targetAttributeToAppend+"="+mail);63}64function temp1(){65 var mail = document.getElementById("txtMailId").value;66 if(validateMail(mail))67 {68 document.getElementById("fp").setAttribute("href","MailServlet?txtEmailId="+mail);69 }70}71function removeStyle(x){72 document.getElementById(x).removeAttribute("style");73}74function borderBlue(){75 document.getElementById("remember").setAttribute("style","padding: 5px;");76}77function Shadow(){78 document.getElementById("submit").setAttribute("style","margin: 5px;");79}80function forgetPass(){81 document.getElementById("fp2").setAttribute("style","font-size: 20px; text-decoration:overline;");82}83function otpResend(){84 document.getElementById("otp").setAttribute("style","font-size: 20px; text-decoration:overline;");85}86function validateMobile(){87 var mobile = document.getElementById("txtMobile").value;88 var pmobile=/^[0-9]{1,10}$/;89 if(mobile.length!=10)90 {91 alert("Only 10 Digits");92 }93 if (!pmobile.test(mobile)) {94 alert("Phone nubmer is in 0123456789 format(Only Numbers)");95 return false;96 }97}98function validatePin(){99 var pin = document.getElementById("txtPin").value;100 var ppin=/^[0-9]{1,6}$/;101 if ( !ppin.test(pin) ) {102 alert("Pin code should be 6 digits ");103 return false;104 } 105}106function validateMail(){107 var mail = document.getElementById("txtMailId").value;108 var pmail=/^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$/;109 if(mail.length == 0)110 {111 alert("Email is Required");112 return false;113 }114 else if (!pmail.test(mail)) {115 alert("Email must be thakkarbhumit.1@gmail.com format");116 return false;117 }118 else if(pmail.test(mail)){119 return true;120 }121}122function checkAndSign(){ /* from add_mall.jsp when mall name consists of & sign */123 var mallName = document.getElementById("txtMallName").value;124 var patt = /[&]/g;125 if(mallName.match(patt)){126 alert("No '&' Accepted, Instead use 'and'");127 }128}129function setValueTo(value,toElementId){130 document.getElementById(toElementId).value = value;131}132function setSpecialCaseValueFromTo(fromElementId,toElementId,fromElementId2,toElementId2){133 document.getElementById(toElementId).value = document.getElementById(fromElementId).innerHTML;134 document.getElementById(toElementId2).value = document.getElementById(fromElementId2).innerHTML;135}136function displayOn(toOnElementId){137 document.getElementById(toOnElementId).setAttribute("style","display:true;");138}139function displayOff(toOffElementId){140 document.getElementById(toOffElementId).setAttribute("style","display:none;");141 document.getElementById(toOffElementId).value=null;142}143function dropdown(){144 ...
extras-string.js
Source:extras-string.js
1if( !String.prototype.trim ) {2 String.prototype.trim = function () {3 return this.replace(/^\s*/, '').replace(/\s*$/, '');4 };5}6if( !String.prototype.ltrim ) {7 String.prototype.ltrim=function() {return this.replace(/^\s+/, '');};8}9if( !String.prototype.rtrim ) {10 String.prototype.rtrim=function() {return this.replace(/\s+$/, '');};11}12String.prototype.fulltrim=function() {return this.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g, '').replace(/\s+/g, ' ');};13if( !String.prototype.camelize )14 String.prototype.camelize = function() {15 return this.replace(/_+(.)?/g, function(match, chr) {16 return chr ? chr.toUpperCase() : '';17 });18 };19if( !String.prototype.seperate )20 String.prototype.seperate = function() {21 return this.replace(/_+(.)?/g, function(match, chr) {22 return chr ? ' ' + chr.toUpperCase() : '';23 });24 };25if( !String.prototype.capitalize )26 String.prototype.capitalize = function() {27 return this.charAt(0).toUpperCase() + this.substring(1);28 };29if( !String.prototype.endInSlash )30 String.prototype.endInSlash = function() {31 var sStr = this;32 if( /\/$/.test(this) === false ) {33 sStr = this + '/';34 }35 return sStr;36 };37if( !String.prototype.endInBSlash )38 String.prototype.endInBSlash = function() {39 var sStr = this;40 if( /\$/.test(this) === false ) {41 /*sStr = this + '\\';*/42 }43 return sStr;44 };45if( !String.prototype.escapeCSV )46 String.prototype.escapeCSV = function() {47 var sStr = this;48 sStr = sStr.replace(/"/g, '\\"').replace(/\n/g, '');49 return sStr;50 };51if( !String.prototype.htmlEscape )52 String.prototype.htmlEscape = function() {53 return String(this)54 .replace(/&/g, '&')55 .replace(/"/g, '"')56 .replace(/'/g, ''')57 .replace(/</g, '<')58 .replace(/>/g, '>');59 };60if( !String.prototype.htmlUnescape )61 String.prototype.htmlUnescape = function() {62 return String(this)63 .replace(/"/g, '"')64 .replace(/'/g, '\'')65 .replace(/</g, '<')66 .replace(/>/g, '>')67 .replace(/&/g, '&');68 };69if( !String.prototype.toElementId )70 String.prototype.toElementId = function() {71 return String(this).replace(/[!@$%&*()-=+~^.#' \n\t\f\r`"]+/g, '_');//this makes the id less unique, need a better way72 //Before html5 id's not supposed to start with a number? Might want to check for that.73 //jQuery has issues with . and : might want to replace that.74 //May also want to check on CSS restrictions75 };76if( !String.prototype.toElementIdForjQuery )77 String.prototype.toElementIdForjQuery = function() {78 return String(this).replace(/[~!@$%&*()-=+^#' \n\t\f\r:.`"]+/g, '_');79 //See notes from toElementID80 };81if( !String.prototype.supplant )82 String.prototype.supplant = function(o) {83 return this.replace(/{([^{}]*)}/g, function(a, b) {84 var r = o[b];85 return typeof r === 'string' ? r:a;86 });87 };88if( !String.prototype.mustache )89 String.prototype.mustache = function(o) {90 return this.replace(/{{([^{}]*)}}/g, function(a, b) {91 var r = o[b];92 return typeof r === 'string' || typeof r === 'number' ? r:a;93 });94 };...
ContactMenu.js
Source:ContactMenu.js
1// @flow2// #region imports3import React, { PureComponent, SyntheticEvent } from 'react';4// import Router from 'next/router';5import Link from 'next/link';6import { withStyles } from 'material-ui/styles';7import { ListItem, ListItemIcon, ListItemText } from 'material-ui/List';8import MailOutlineIcon from 'material-ui-icons/MailOutline';9import Typography from 'material-ui/Typography';10import ArticleIcon from 'material-ui-icons/Subject';11import PressIcon from 'material-ui-icons/LocalSee';12import Divider from 'material-ui/Divider';13import ContactIcon from 'material-ui-icons/PermContactCalendar';14import styles from './styles';15// #endregion16// #region flow types17type Props = {18 // from withStyle HOC:19 classes: any,20 ...any,21};22type State = {23 ...any,24};25// #endregion26class ContactMenus extends PureComponent<Props, State> {27 // #region lifecycle methods28 render() {29 const { classes } = this.props;30 return (31 <div>32 <Typography33 className={classes.menuTitle}34 type="subheading"35 gutterBottom36 >37 Main menu (Contact)38 </Typography>39 {/* Contact */}40 <ListItem button onClick={this.scrollTo('')}>41 <ListItemIcon>42 <ContactIcon />43 </ListItemIcon>44 <ListItemText primary={'Contact'} />45 </ListItem>46 {/* Blog (blogSection) */}47 <ListItem button onClick={this.scrollTo('#blogSection')}>48 <ListItemIcon>49 <ArticleIcon />50 </ListItemIcon>51 <ListItemText primary={'Blog'} />52 </ListItem>53 {/* NewsLetter (newsletterSection) */}54 <ListItem button onClick={this.scrollTo('#newsletterSection')}>55 <ListItemIcon>56 <MailOutlineIcon />57 </ListItemIcon>58 <ListItemText primary={'NewsLetter'} />59 </ListItem>60 {/* Press (pressSection) */}61 <ListItem button onClick={this.scrollTo('#pressSection')}>62 <ListItemIcon>63 <PressIcon />64 </ListItemIcon>65 <ListItemText primary={'Press'} />66 </ListItem>67 <Divider />68 </div>69 );70 }71 // #endregion72 // #region on menu clicl : scroll to73 scrollTo = (toElementId: string = null) => (event: SyntheticEvent<>) => {74 if (event) {75 event.preventDefault();76 }77 if (!toElementId) {78 return;79 }80 // no target element = go top page81 if (!toElementId.length > 0) {82 window.scroll({ top: 0, left: 0, behavior: 'smooth' });83 }84 // otherwise smooth scroll to target element85 const startsWithSharp = toElementId.slice(0, 1) === '#';86 const queryEl = startsWithSharp ? toElementId : `#${toElementId}`;87 // using here "smooth scroll polyfill"88 document.querySelector(queryEl).scrollIntoView({89 behavior: 'smooth',90 });91 };92 // #endregion93}...
application.js
Source:application.js
1var Ajax;2if (Ajax && (Ajax != null)) {3 Ajax.Responders.register({4 onCreate: function() {5 if($('spinner') && Ajax.activeRequestCount>0)6 Effect.Appear('spinner',{duration:0.5,queue:'end'});7 },8 onComplete: function() {9 if($('spinner') && Ajax.activeRequestCount==0)10 Effect.Fade('spinner',{duration:0.5,queue:'end'});11 }12 });13}14/**15 * move selected Options from one select box to another16 */17function moveSelectedOptions(fromElementId, toElementId)18{19 // finding objects20 var fromObj = document.getElementById(fromElementId);21 var toObj = document.getElementById(toElementId);22 var ret=false;23 // is this a select box24 if((fromObj && fromObj.type=="select-multiple")25 && (toObj&&toObj.type=="select-multiple")) {26 ret=true;27 }28 // 2 multiple select boxes found29 if(ret){30 //========================31 // moving selected options32 //========================33 // iterating all options from source select box34 for(var i=0;i<fromObj.options.length;i++){35 // is this a selected option36 if(fromObj.options[i].selected){37 // creating new option in target select box38 toObj.options[toObj.options.length] = new Option(fromObj.options[i].text39 ,fromObj.options[i].value);40 // delete current option41 fromObj.options[i] = null;42 i--;43 }44 }45 }46 return ret;47}48/**49 * move all Options from one select box to another50 */51function moveAllOptions(fromElementId, toElementId)52{53 var ret=false;54 ret=selectAllOptions(fromElementId);55 if (ret){56 ret=moveSelectedOptions(fromElementId, toElementId);57 }58 return ret;59}60/**61 * select all Options from one select box62 */63function selectAllOptions(selectId)64{65 // finding objects66 var selectObj = document.getElementById(selectId);67 var ret=false;68 // is this a select box69 if(selectObj != undefined && selectObj.type=="select-multiple"){70 ret=true;71 }72 if(ret) {73 for(var i=0;i<selectObj.options.length;i++){74 selectObj.options[i].selected = true;75 }76 }77 return ret;...
tabs.js
Source:tabs.js
1 $(function(){2 var $window = $(window);3 $(window).on("load", function(){4 function getElementOffset(getElement){5 return $(getElement).offset().top;6 }7 8 var $tabs = $("#catalogElement .tabs");9 var $tabElements = $tabs.find(".tab");10 var $mainScrollObj = $("html, body");11 var arCoordinates = {};12 $tabElements.each(function(i, nextElement){13 var $nextElement = $(nextElement);14 if($nextElement.data("id")){15 arCoordinates[$nextElement.data("id")] = getElementOffset("#" + $nextElement.data("id"));16 }17 });18 var scrollToElement = function(event){19 var $this = $(this).parents(".tab");20 var toElementID = $this.data("id");21 if(toElementID){22 $tabElements.removeClass("active");23 $mainScrollObj.stop().animate({24 scrollTop: getElementOffset("#" + toElementID) + "px"25 }, 250);26 return event.preventDefault($this.addClass("active"));27 }28 };29 var calcCloseElement = function(coordinate){30 var copyCoordinate = [];31 $.each(arCoordinates, function(i, val) {32 if(coordinate <= val){33 copyCoordinate.push({34 id: i, value: val35 })36 }37 });38 copyCoordinate.sort(function(obj1, obj2) {39 if (obj1.value < obj2.value) return -1;40 if (obj1.value > obj2.value) return 1;41 return 0;42 });43 return copyCoordinate[0];44 };45 var scrollControl = function(event){46 var curScrollValueY = (event.currentTarget.scrollY) ? event.currentTarget.scrollY : $(window).scrollTop()47 var arCurrentTab = calcCloseElement(curScrollValueY);48 if(arCurrentTab != undefined){49 $tabElements.removeClass("active");50 $tabElements.filter('[data-id="' + arCurrentTab["id"] + '"]').addClass("active");51 }52 };53 $(document).on("click", "#elementNavigation .tab a, #elementSmallNavigation .tab a", scrollToElement);54 $(window).on("scroll", scrollControl);55 });...
selectors.js
Source:selectors.js
1import { createSelector } from "reselect";2import { elementType } from "sideBar/operators/operatorsData";3import { getElementId } from "workbench/utils";4// These selectors add layout info to the graph queries and filters.5// The extra info are contained in operatorsExtraInfo obj.6// 1 is the id I'd given to queries and 2 is the one for filters.7const sessionInfoSelector = state => state.sessionReducer.sessionInfo;8export const getSessionInfo = createSelector(9 sessionInfoSelector,10 ({11 Graph: { Queries, InteractiveFilters, Connections, ...graphRest },12 ...sessionInfoRest13 }) => ({14 ...sessionInfoRest,15 Graph: {16 ...graphRest,17 Queries: Queries.map(18 ({ ElementId, Label, Columns, LayoutX, LayoutY, ...queryRest }) => ({19 type: elementType.QUERY,20 elementId: getElementId(ElementId),21 elementLabel: Label,22 columns: Columns,23 x: LayoutX,24 y: LayoutY,25 ...queryRest26 })27 ),28 InteractiveFilters: InteractiveFilters.map(29 ({30 ElementId,31 Label,32 FilterType,33 LayoutX,34 LayoutY,35 ...filterRest36 }) => ({37 type: elementType.FILTER,38 elementId: getElementId(ElementId),39 elementLabel: Label,40 filterType: FilterType,41 x: LayoutX,42 y: LayoutY,43 ...filterRest44 })45 ),46 Connections: Connections.map(47 ({ FromElementId, ToElementId, ...connectionRest }) => ({48 source: getElementId(FromElementId),49 target: getElementId(ToElementId),50 ...connectionRest51 })52 )53 }54 })...
backend.js
Source:backend.js
1/**2 * Copy element text in clipboard3 *4 * @param {Object} element5 */6function copyInClipboard (element) {7 element.select();8 document.execCommand('copy');9}10/**11 * Copy value from input to another input12 *13 * @param {string} fromElementId14 * @param {string} toElementId15 * @param {boolean} normalize16 *17 * @returns {boolean}18 */19function copyValue (fromElementId, toElementId, normalize) {20 let toElement = document.getElementById(toElementId);21 let fromElement = document.getElementById(fromElementId);22 if (!toElement || !fromElement) {23 return false;24 }25 if (toElement.value) {26 return false;27 }28 fromElement.addEventListener('change', function () {29 let value = this.value;30 if (normalize) {31 value = removeAccents(value).toLowerCase().replace(/[\W_]+/g, '-');32 }33 toElement.value = value;34 });35 return true;36}37/**38 * Remove accents in string39 *40 * @param {string} str41 *42 * @returns {string}43 */44function removeAccents (str) {45 let map = {46 'a':'á|à |ã|â|Ã|Ã|Ã|Ã',47 'e':'é|è|ê|Ã|Ã|Ã',48 'i':'Ã|ì|î|Ã|Ã|Ã',49 'o':'ó|ò|ô|õ|Ã|Ã|Ã|Ã',50 'u':'ú|ù|û|ü|Ã|Ã|Ã|Ã',51 'c':'ç|Ã',52 'n':'ñ|Ã'53 };54 for (let pattern in map) {55 str = str.replace(new RegExp(map[pattern], 'g'), pattern);56 }57 return str;...
Using AI Code Generation
1const {remote} = require('webdriverio');2(async () => {3 const browser = await remote({4 capabilities: {5 }6 });7 await browser.pause(5000);8 console.log(elementId);9 await browser.pause(5000);10 await browser.deleteSession();11})();12from appium import webdriver13desired_caps = {}14driver.implicitly_wait(5)15print(element_id)16driver.implicitly_wait(5)17driver.quit()
Using AI Code Generation
1const { remote } = require('webdriverio');2async function main() {3 const browser = await remote({4 capabilities: {5 }6 });7 await browser.switchToFrame(0);8 await browser.$('input[name="q"]').setValue('Hello World!');9}10main();11const { remote } = require('webdriverio');12async function main() {13 const browser = await remote({14 capabilities: {15 }16 });17 await browser.switchToFrame(0);18 await browser.$('input[name="q"]').setValue('Hello World!');19}20main();21const { remote } = require('webdriverio');22async function main() {23 const browser = await remote({24 capabilities: {25 }26 });27 await browser.switchToFrame(0);28 await browser.$('input[name="q"]').setValue('Hello World!');29}30main();31const { remote } = require('webdriverio');32async function main() {33 const browser = await remote({
Using AI Code Generation
1const { remote } = require('webdriverio');2async function main () {3 const browser = await remote({4 capabilities: {5 }6 });7 await browser.pause(5000);8 const element = await browser.$('~Buttons');9 await element.click();10 await browser.pause(2000);11 const element2 = await browser.$('~Back');12 await element2.click();13 await browser.pause(2000);14 const element3 = await browser.$('~UICatalog');15 await element3.click();16 await browser.pause(2000);17 const element4 = await browser.$('~Alerts');18 await element4.click();19 await browser.pause(2000);20 const element5 = await browser.$('~Text Entry');21 await element5.click();22 await browser.pause(2000);23 const element6 = await browser.$('~OK');24 await element6.click();25 await browser.pause(2000);26 const element7 = await browser.$('~Back');27 await element7.click();28 await browser.pause(2000);29 const element8 = await browser.$('~UICatalog');30 await element8.click();31 await browser.pause(2000);32 const element9 = await browser.$('~TextFields');33 await element9.click();34 await browser.pause(2000);35 const element10 = await browser.$('~Back');36 await element10.click();37 await browser.pause(2000);38 const element11 = await browser.$('~UICatalog');39 await element11.click();40 await browser.pause(2000);41 const element12 = await browser.$('~Activity Indicators');42 await element12.click();43 await browser.pause(2000);44 const element13 = await browser.$('~Gray');45 await element13.click();46 await browser.pause(2000);47 const element14 = await browser.$('~Back');48 await element14.click();49 await browser.pause(2000);
Using AI Code Generation
1const { remote } = require('webdriverio');2const { XCUITestDriver } = require('appium-xcuitest-driver');3async function main() {4 const driver = new XCUITestDriver();5 await driver.createSession({6 capabilities: {
Using AI Code Generation
1await driver.elementClick(elementId);2await driver.elementClick(elementIds[0]);3await driver.elementClick(element.ELEMENT);4await driver.elementClick(elements[0].ELEMENT);5await driver.elementClick(elementId);6await driver.elementClick(elementIds[0]);7await driver.elementClick(element.ELEMENT);8await driver.elementClick(elements[0].ELEMENT);9await driver.elementClick(elementId);10await driver.elementClick(elementIds[0]);11await driver.elementClick(element.ELEMENT);12await driver.elementClick(elements[0].ELEMENT);
Using AI Code Generation
1driver.toElementId('elementId')2.then(function(elementId){3 console.log(elementId);4});5driver.toElementId('elementId')6.then(function(elementId){7 console.log(elementId);8});9driver.toElementId('elementId')10.then(function(elementId){11 console.log(elementId);12});13driver.toElementId('elementId')14.then(function(elementId){15 console.log(elementId);16});17driver.toElementId('elementId')18.then(function(elementId){19 console.log(elementId);20});21driver.toElementId('elementId')22.then(function(elementId){23 console.log(elementId);24});25driver.toElementId('elementId')26.then(function(elementId){27 console.log(elementId);28});29driver.toElementId('elementId')30.then(function(elementId){31 console.log(elementId);32});33driver.toElementId('elementId')34.then(function(elementId){35 console.log(elementId);36});37driver.toElementId('elementId')38.then(function(elementId){39 console.log(elementId);40});41driver.toElementId('elementId')42.then(function(elementId){43 console.log(elementId);44});45driver.toElementId('elementId')46.then(function(elementId){47 console.log(elementId);48});49driver.toElementId('elementId')50.then(function(elementId){51 console.log(elementId);52});53driver.toElementId('elementId')54.then(function(elementId){55 console.log(elementId);56});57driver.toElementId('elementId')58.then(function(element
Using AI Code Generation
1const wd = require('wd');2const config = {3};4const driver = wd.promiseChainRemote(config);5const desiredCaps = {6};7(async function () {8 await driver.init(desiredCaps);9 await driver.sleep(5000);10 const elementId = await driver.elementByAccessibilityId('show alert').then(function (el) {11 return driver.toElementId(el);12 });13 const elementId2 = await driver.elementByAccessibilityId('show alert').then(function (el) {14 return driver.toElementId(el);15 });16 await driver.elementById(elementId).click();17 await driver.elementById(elementId2).click();18 await driver.sleep(5000);19 await driver.quit();20})();
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!!