Best JavaScript code snippet using taiko
jquery.textbox.js
Source:jquery.textbox.js
1/**2 * jQuery EasyUI 1.4.53 * 4 * Copyright (c) 2009-2016 www.jeasyui.com. All rights reserved.5 *6 * Licensed under the freeware license: http://www.jeasyui.com/license_freeware.php7 * To use it on other terms please contact us: info@jeasyui.com8 *9 */10(function($){11function _1(_2){12$(_2).addClass("textbox-f").hide();13var _3=$("<span class=\"textbox\">"+"<input class=\"textbox-text\" autocomplete=\"off\">"+"<input type=\"hidden\" class=\"textbox-value\">"+"</span>").insertAfter(_2);14var _4=$(_2).attr("name");15if(_4){16_3.find("input.textbox-value").attr("name",_4);17$(_2).removeAttr("name").attr("textboxName",_4);18}19return _3;20};21function _5(_6){22var _7=$.data(_6,"textbox");23var _8=_7.options;24var tb=_7.textbox;25tb.find(".textbox-text").remove();26if(_8.multiline){27$("<textarea class=\"textbox-text\" autocomplete=\"off\"></textarea>").prependTo(tb);28}else{29$("<input type=\""+_8.type+"\" class=\"textbox-text\" autocomplete=\"off\">").prependTo(tb);30}31tb.find(".textbox-addon").remove();32var bb=_8.icons?$.extend(true,[],_8.icons):[];33if(_8.iconCls){34bb.push({iconCls:_8.iconCls,disabled:true});35}36if(bb.length){37var bc=$("<span class=\"textbox-addon\"></span>").prependTo(tb);38bc.addClass("textbox-addon-"+_8.iconAlign);39for(var i=0;i<bb.length;i++){40bc.append("<a href=\"javascript:void(0)\" class=\"textbox-icon "+bb[i].iconCls+"\" icon-index=\""+i+"\" tabindex=\"-1\"></a>");41}42}43tb.find(".textbox-button").remove();44if(_8.buttonText||_8.buttonIcon){45var _9=$("<a href=\"javascript:void(0)\" class=\"textbox-button\"></a>").prependTo(tb);46_9.addClass("textbox-button-"+_8.buttonAlign).linkbutton({text:_8.buttonText,iconCls:_8.buttonIcon});47}48_a(_6);49_b(_6,_8.disabled);50_c(_6,_8.readonly);51};52function _d(_e){53var tb=$.data(_e,"textbox").textbox;54tb.find(".textbox-text").validatebox("destroy");55tb.remove();56$(_e).remove();57};58function _f(_10,_11){59var _12=$.data(_10,"textbox");60var _13=_12.options;61var tb=_12.textbox;62var _14=tb.parent();63if(_11){64_13.width=_11;65}66if(isNaN(parseInt(_13.width))){67var c=$(_10).clone();68c.css("visibility","hidden");69c.insertAfter(_10);70_13.width=c.outerWidth();71c.remove();72}73var _15=tb.is(":visible");74if(!_15){75tb.appendTo("body");76}77var _16=tb.find(".textbox-text");78var btn=tb.find(".textbox-button");79var _17=tb.find(".textbox-addon");80var _18=_17.find(".textbox-icon");81tb._size(_13,_14);82btn.linkbutton("resize",{height:tb.height()});83btn.css({left:(_13.buttonAlign=="left"?0:""),right:(_13.buttonAlign=="right"?0:"")});84_17.css({left:(_13.iconAlign=="left"?(_13.buttonAlign=="left"?btn._outerWidth():0):""),right:(_13.iconAlign=="right"?(_13.buttonAlign=="right"?btn._outerWidth():0):"")});85_18.css({width:_13.iconWidth+"px",height:tb.height()+"px"});86_16.css({paddingLeft:(_10.style.paddingLeft||""),paddingRight:(_10.style.paddingRight||""),marginLeft:_19("left"),marginRight:_19("right")});87if(_13.multiline){88_16.css({paddingTop:(_10.style.paddingTop||""),paddingBottom:(_10.style.paddingBottom||"")});89_16._outerHeight(tb.height());90}else{91_16.css({paddingTop:0,paddingBottom:0,height:tb.height()+"px",lineHeight:tb.height()+"px"});92}93_16._outerWidth(tb.width()-_18.length*_13.iconWidth-btn._outerWidth());94if(!_15){95tb.insertAfter(_10);96}97_13.onResize.call(_10,_13.width,_13.height);98function _19(_1a){99return (_13.iconAlign==_1a?_17._outerWidth():0)+(_13.buttonAlign==_1a?btn._outerWidth():0);100};101};102function _a(_1b){103var _1c=$(_1b).textbox("options");104var _1d=$(_1b).textbox("textbox");105_1d.validatebox($.extend({},_1c,{deltaX:$(_1b).textbox("getTipX"),onBeforeValidate:function(){106_1c.onBeforeValidate.call(_1b);107var box=$(this);108if(!box.is(":focus")){109_1c.oldInputValue=box.val();110box.val(_1c.value);111}112},onValidate:function(_1e){113var box=$(this);114if(_1c.oldInputValue!=undefined){115box.val(_1c.oldInputValue);116_1c.oldInputValue=undefined;117}118var tb=box.parent();119if(_1e){120tb.removeClass("textbox-invalid");121}else{122tb.addClass("textbox-invalid");123}124_1c.onValidate.call(_1b,_1e);125}}));126};127function _1f(_20){128var _21=$.data(_20,"textbox");129var _22=_21.options;130var tb=_21.textbox;131var _23=tb.find(".textbox-text");132_23.attr("placeholder",_22.prompt);133_23.unbind(".textbox");134if(!_22.disabled&&!_22.readonly){135_23.bind("blur.textbox",function(e){136if(!tb.hasClass("textbox-focused")){137return;138}139_22.value=$(this).val();140if(_22.value==""){141$(this).val(_22.prompt).addClass("textbox-prompt");142}else{143$(this).removeClass("textbox-prompt");144}145tb.removeClass("textbox-focused");146}).bind("focus.textbox",function(e){147if(tb.hasClass("textbox-focused")){148return;149}150if($(this).val()!=_22.value){151$(this).val(_22.value);152}153$(this).removeClass("textbox-prompt");154tb.addClass("textbox-focused");155});156for(var _24 in _22.inputEvents){157_23.bind(_24+".textbox",{target:_20},_22.inputEvents[_24]);158}159}160var _25=tb.find(".textbox-addon");161_25.unbind().bind("click",{target:_20},function(e){162var _26=$(e.target).closest("a.textbox-icon:not(.textbox-icon-disabled)");163if(_26.length){164var _27=parseInt(_26.attr("icon-index"));165var _28=_22.icons[_27];166if(_28&&_28.handler){167_28.handler.call(_26[0],e);168_22.onClickIcon.call(_20,_27);169}170}171});172_25.find(".textbox-icon").each(function(_29){173var _2a=_22.icons[_29];174var _2b=$(this);175if(!_2a||_2a.disabled||_22.disabled||_22.readonly){176_2b.addClass("textbox-icon-disabled");177}else{178_2b.removeClass("textbox-icon-disabled");179}180});181var btn=tb.find(".textbox-button");182btn.unbind(".textbox").bind("click.textbox",function(){183if(!btn.linkbutton("options").disabled){184_22.onClickButton.call(_20);185}186});187btn.linkbutton((_22.disabled||_22.readonly)?"disable":"enable");188tb.unbind(".textbox").bind("_resize.textbox",function(e,_2c){189if($(this).hasClass("easyui-fluid")||_2c){190_f(_20);191}192return false;193});194};195function _b(_2d,_2e){196var _2f=$.data(_2d,"textbox");197var _30=_2f.options;198var tb=_2f.textbox;199var _31=tb.find(".textbox-text");200var ss=$(_2d).add(tb.find(".textbox-value"));201_30.disabled=_2e;202if(_30.disabled){203_31.validatebox("disable");204tb.addClass("textbox-disabled");205ss.attr("disabled","disabled");206}else{207_31.validatebox("enable");208tb.removeClass("textbox-disabled");209ss.removeAttr("disabled");210}211};212function _c(_32,_33){213var _34=$.data(_32,"textbox");214var _35=_34.options;215var tb=_34.textbox;216var _36=tb.find(".textbox-text");217_36.validatebox("readonly",_33);218_35.readonly=_36.validatebox("options").readonly;219tb.removeClass("textbox-readonly").addClass(_35.readonly?"textbox-readonly":"");220};221$.fn.textbox=function(_37,_38){222if(typeof _37=="string"){223var _39=$.fn.textbox.methods[_37];224if(_39){225return _39(this,_38);226}else{227return this.each(function(){228var _3a=$(this).textbox("textbox");229_3a.validatebox(_37,_38);230});231}232}233_37=_37||{};234return this.each(function(){235var _3b=$.data(this,"textbox");236if(_3b){237$.extend(_3b.options,_37);238if(_37.value!=undefined){239_3b.options.originalValue=_37.value;240}241}else{242_3b=$.data(this,"textbox",{options:$.extend({},$.fn.textbox.defaults,$.fn.textbox.parseOptions(this),_37),textbox:_1(this)});243_3b.options.originalValue=_3b.options.value;244}245_5(this);246_1f(this);247_f(this);248$(this).textbox("initValue",_3b.options.value);249});250};251$.fn.textbox.methods={options:function(jq){252return $.data(jq[0],"textbox").options;253},cloneFrom:function(jq,_3c){254return jq.each(function(){255var t=$(this);256if(t.data("textbox")){257return;258}259if(!$(_3c).data("textbox")){260$(_3c).textbox();261}262var _3d=t.attr("name")||"";263t.addClass("textbox-f").hide();264t.removeAttr("name").attr("textboxName",_3d);265var _3e=$(_3c).next().clone().insertAfter(t);266_3e.find("input.textbox-value").attr("name",_3d);267$.data(this,"textbox",{options:$.extend(true,{},$(_3c).textbox("options")),textbox:_3e});268var _3f=$(_3c).textbox("button");269if(_3f.length){270t.textbox("button").linkbutton($.extend(true,{},_3f.linkbutton("options")));271}272_1f(this);273_a(this);274});275},textbox:function(jq){276return $.data(jq[0],"textbox").textbox.find(".textbox-text");277},button:function(jq){278return $.data(jq[0],"textbox").textbox.find(".textbox-button");279},destroy:function(jq){280return jq.each(function(){281_d(this);282});283},resize:function(jq,_40){284return jq.each(function(){285_f(this,_40);286});287},disable:function(jq){288return jq.each(function(){289_b(this,true);290_1f(this);291});292},enable:function(jq){293return jq.each(function(){294_b(this,false);295_1f(this);296});297},readonly:function(jq,_41){298return jq.each(function(){299_c(this,_41);300_1f(this);301});302},isValid:function(jq){303return jq.textbox("textbox").validatebox("isValid");304},clear:function(jq){305return jq.each(function(){306$(this).textbox("setValue","");307});308},setText:function(jq,_42){309return jq.each(function(){310var _43=$(this).textbox("options");311var _44=$(this).textbox("textbox");312_42=_42==undefined?"":String(_42);313if($(this).textbox("getText")!=_42){314_44.val(_42);315}316_43.value=_42;317if(!_44.is(":focus")){318if(_42){319_44.removeClass("textbox-prompt");320}else{321_44.val(_43.prompt).addClass("textbox-prompt");322}323}324$(this).textbox("validate");325});326},initValue:function(jq,_45){327return jq.each(function(){328var _46=$.data(this,"textbox");329_46.options.value="";330$(this).textbox("setText",_45);331_46.textbox.find(".textbox-value").val(_45);332$(this).val(_45);333});334},setValue:function(jq,_47){335return jq.each(function(){336var _48=$.data(this,"textbox").options;337var _49=$(this).textbox("getValue");338$(this).textbox("initValue",_47);339if(_49!=_47){340_48.onChange.call(this,_47,_49);341$(this).closest("form").trigger("_change",[this]);342}343});344},getText:function(jq){345var _4a=jq.textbox("textbox");346if(_4a.is(":focus")){347return _4a.val();348}else{349return jq.textbox("options").value;350}351},getValue:function(jq){352return jq.data("textbox").textbox.find(".textbox-value").val();353},reset:function(jq){354return jq.each(function(){355var _4b=$(this).textbox("options");356$(this).textbox("setValue",_4b.originalValue);357});358},getIcon:function(jq,_4c){359return jq.data("textbox").textbox.find(".textbox-icon:eq("+_4c+")");360},getTipX:function(jq){361var _4d=jq.data("textbox");362var _4e=_4d.options;363var tb=_4d.textbox;364var _4f=tb.find(".textbox-text");365var _50=tb.find(".textbox-addon")._outerWidth();366var _51=tb.find(".textbox-button")._outerWidth();367if(_4e.tipPosition=="right"){368return (_4e.iconAlign=="right"?_50:0)+(_4e.buttonAlign=="right"?_51:0)+1;369}else{370if(_4e.tipPosition=="left"){371return (_4e.iconAlign=="left"?-_50:0)+(_4e.buttonAlign=="left"?-_51:0)-1;372}else{373return _50/2*(_4e.iconAlign=="right"?1:-1);374}375}376}};377$.fn.textbox.parseOptions=function(_52){378var t=$(_52);379return $.extend({},$.fn.validatebox.parseOptions(_52),$.parser.parseOptions(_52,["prompt","iconCls","iconAlign","buttonText","buttonIcon","buttonAlign",{multiline:"boolean",iconWidth:"number"}]),{value:(t.val()||undefined),type:(t.attr("type")?t.attr("type"):undefined)});380};381$.fn.textbox.defaults=$.extend({},$.fn.validatebox.defaults,{width:"auto",height:22,prompt:"",value:"",type:"text",multiline:false,icons:[],iconCls:null,iconAlign:"right",iconWidth:18,buttonText:"",buttonIcon:null,buttonAlign:"right",inputEvents:{blur:function(e){382var t=$(e.data.target);383var _53=t.textbox("options");384t.textbox("setValue",_53.value);385},keydown:function(e){386if(e.keyCode==13){387var t=$(e.data.target);388t.textbox("setValue",t.textbox("getText"));389}390}},onChange:function(_54,_55){391},onResize:function(_56,_57){392},onClickButton:function(){393},onClickIcon:function(_58){394}});...
Using AI Code Generation
1const { openBrowser, goto, textBox, write, closeBrowser } = require('taiko');2(async () => {3 try {4 await openBrowser({headless:false});5 await goto("google.com");6 await write("Taiko",textBox());7 await closeBrowser();8 } catch (error) {9 console.error(error);10 }11})();
Using AI Code Generation
1const { openBrowser, goto, textBox, write, closeBrowser } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await goto("google.com");6 await write("Hello World", into(textBox({id:"lst-ib"})));7 } catch (error) {8 console.error(error);9 } finally {10 await closeBrowser();11 }12})();13const { openBrowser, goto, textBox, write, closeBrowser } = require('taiko');14(async () => {15 try {16 await openBrowser();17 await goto("google.com");18 var searchBox = await textBox({id:"lst-ib"});19 await write("Hello World", into(searchBox));20 } catch (error) {21 console.error(error);22 } finally {23 await closeBrowser();24 }25})();26const { openBrowser, goto, link, write, closeBrowser } = require('taiko');27(async () => {28 try {29 await openBrowser();30 await goto("google.com");31 await write("Hello World", into(link("Gmail")));32 } catch (error) {33 console.error(error);34 } finally {35 await closeBrowser();36 }37})();
Using AI Code Generation
1const { openBrowser, goto, textBox, closeBrowser } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await goto("google.com");6 await textBox("q").type("Hello World");7 } catch (e) {8 console.error(e);9 } finally {10 await closeBrowser();11 }12})();13const { openBrowser, goto, textBox, closeBrowser } = require('taiko');14(async () => {15 try {16 await openBrowser();17 await goto("google.com");18 await textBox("q").type("Hello World");19 } catch (e) {20 console.error(e);21 } finally {22 await closeBrowser();23 }24})();25const { openBrowser, goto, textBox, closeBrowser } = require('taiko');26(async () => {27 try {28 await openBrowser();29 await goto("google.com");30 await textBox("q").type("Hello World");31 } catch (e) {32 console.error(e);33 } finally {34 await closeBrowser();35 }36})();37const { openBrowser, goto, textBox, closeBrowser } = require('taiko');38(async () => {39 try {40 await openBrowser();41 await goto("google.com");42 await textBox("q").type("Hello World");43 } catch (e) {44 console.error(e);45 } finally {46 await closeBrowser();47 }48})();49const { openBrowser, goto, textBox, closeBrowser } = require('taiko');50(async () => {51 try {52 await openBrowser();53 await goto("google.com");54 await textBox("q").type("Hello World");55 } catch (e) {56 console.error(e);57 } finally {58 await closeBrowser();59 }60})();61const { openBrowser, goto, textBox, closeBrowser } = require('taiko');62(async () => {63 try {64 await openBrowser();65 await goto("google.com");66 await textBox("q").type("Hello World");67 } catch (e) {68 console.error(e);69 } finally {70 await closeBrowser();71 }72})();73const { openBrowser, goto
Using AI Code Generation
1const { openBrowser, goto, textBox, closeBrowser } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await goto("google.com");6 await textBox("Search").type("Hello");7 } catch (e) {8 console.error(e);9 } finally {10 await closeBrowser();11 }12})();13const { openBrowser, goto, textBox, closeBrowser } = require('taiko');14(async () => {15 try {16 await openBrowser();17 await goto("google.com");18 await textBox("Search").type("Hello");19 } catch (e) {20 console.error(e);21 } finally {22 await closeBrowser();23 }24})();25const { openBrowser, goto, textBox, closeBrowser } = require('taiko');26(async () => {27 try {28 await openBrowser();29 await goto("google.com");30 await textBox("Search").type("Hello");31 } catch (e) {32 console.error(e);33 } finally {34 await closeBrowser();35 }36})();37const { openBrowser, goto, textBox, closeBrowser } = require('taiko');38(async () => {39 try {40 await openBrowser();41 await goto("google.com");42 await textBox("Search").type("Hello");43 } catch (e) {44 console.error(e);45 } finally {46 await closeBrowser();47 }48})();49const { openBrowser, goto, textBox, closeBrowser } = require('taiko');50(async () => {51 try {52 await openBrowser();53 await goto("google.com");54 await textBox("Search").type("Hello");55 } catch (e) {56 console.error(e);57 } finally {58 await closeBrowser();59 }60})();61const { openBrowser, goto, textBox, closeBrowser } = require('taiko');62(async () => {63 try {64 await openBrowser();65 await goto("google.com");66 await textBox("Search").type("Hello");67 } catch (e) {68 console.error(e);69 } finally {
Using AI Code Generation
1const { openBrowser, goto, textBox, closeBrowser } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await goto("google.com");6 await textBox("input").type("Taiko");7 } catch (e) {8 console.error(e);9 } finally {10 await closeBrowser();11 }12})();13const { openBrowser, goto, textBox, closeBrowser } = require('taiko');14describe('Google Search', () => {15 before(async () => {16 await openBrowser();17 await goto("google.com");18 });19 after(async () => {20 await closeBrowser();21 });22 it('should search for taiko', async () => {23 await textBox("input").type("Taiko");24 });25});26const { openBrowser, goto, textBox, closeBrowser } = require('taiko');27describe('Google Search', () => {28 before(async () => {29 await openBrowser();30 await goto("google.com");31 });32 after(async () => {33 await closeBrowser();34 });35 it('should search for taiko', async () => {36 await textBox("input").type("Taiko");37 });38});39In the above example, we are using the openBrowser() and goto()
Using AI Code Generation
1var taiko = require('taiko');2var assert = require("assert");3var { openBrowser, goto, write, closeBrowser } = require('taiko');4(async () => {5 try {6 await openBrowser();7 await goto("google.com");8 await write("Taiko");9 await taiko.textBox().value("Taiko");10 await taiko.die();11 } catch (error) {12 console.error(error);13 } finally {14 await closeBrowser();15 }16})();17var taiko = require('taiko');18var assert = require("assert");19var { openBrowser, goto, write, closeBrowser } = require('taiko');20(async () => {21 try {22 await openBrowser();23 await goto("google.com");24 await write("Taiko");25 await taiko.textBox().value("Taiko");26 await taiko.die();27 } catch (error) {28 console.error(error);29 } finally {30 await closeBrowser();31 }32})();33var taiko = require('taiko');34var assert = require("assert");35var { openBrowser, goto, write, closeBrowser } = require('taiko');36(async () => {37 try {38 await openBrowser();39 await goto("google.com");40 await write("Taiko");41 await taiko.textBox().value("Taiko");42 await taiko.die();43 } catch (error) {44 console.error(error);45 } finally {46 await closeBrowser();47 }48})();49var taiko = require('taiko');50var assert = require("assert");51var { openBrowser, goto, write, closeBrowser } = require('taiko');52(async () => {53 try {54 await openBrowser();55 await goto("google.com");56 await write("Taiko");57 await taiko.textBox().value("Taiko");58 await taiko.die();59 } catch (error) {60 console.error(error);61 } finally {62 await closeBrowser();63 }64})();65var taiko = require('taiko');66var assert = require("assert");67var { openBrowser, goto, write, close
Using AI Code Generation
1var taiko = require('taiko');2console.log(taiko.textBox('First Name').exists());3console.log(taiko.textBox('Last Name').exists());4console.log(taiko.textBox('Email').exists());5console.log(taiko.textBox('Password').exists());6console.log(taiko.textBox('Confirm Password').exists());7console.log(taiko.textBox('Phone Number').exists());8console.log(taiko.textBox('Address').exists());9console.log(taiko.textBox('City').exists());10console.log(taiko.textBox('State').exists());11console.log(taiko.textBox('Zip').exists());12console.log(taiko.textBox('Country').exists());
Using AI Code Generation
1const { textBox, openBrowser, goto, write, closeBrowser, press, into, click, text, toRightOf, $ } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await write("Taiko", into(textBox("Search")));6 await press("Enter");7 await click(text("Taiko: A Node.js library for automating ..."));8 await click("Download");9 await click("Download");10 await click("Download");
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!!