Best JavaScript code snippet using appium-android-driver
script.js
Source:script.js
...30 var published_text = document.id('invisible').getElements('.gk_tab_item_state span')[0].innerHTML;31 var unpublished_text = document.id('invisible').getElements('.gk_tab_item_state span')[1].innerHTML;32 document.id('invisible').getElements('.gk_tab_item_state span').destroy();33 // set the add form34 if(add_form.getElement('.gk_tab_add_type').value == 'article') {35 add_form.getElement('.gk_tab_add_art').setStyle('display', 'block');36 add_form.getElement('.gk_tab_add_artK2').setStyle('display', 'none');37 add_form.getElement('.gk_tab_add_name').getParent().setStyle('display', 'block');38 add_form.getElement('.gk_tab_add_content').getParent().setStyle('display', 'none');39 add_form.getElement('.gk_tab_add_url').getParent().setStyle('display', 'none');40 } else if (add_form.getElement('.gk_tab_add_type').value == 'text') {41 add_form.getElement('.gk_tab_add_art').setStyle('display', 'none');42 add_form.getElement('.gk_tab_add_name').getParent().setStyle('display', 'block');43 add_form.getElement('.gk_tab_add_artK2').setStyle('display', 'none');44 add_form.getElement('.gk_tab_add_content').getParent().setStyle('display', 'block');45 add_form.getElement('.gk_tab_add_url').getParent().setStyle('display', 'block');46 } else {47 add_form.getElement('.gk_tab_add_artK2').setStyle('display', 'block');48 add_form.getElement('.gk_tab_add_art').setStyle('display', 'none');49 add_form.getElement('.gk_tab_add_name').getParent().setStyle('display', 'block');50 add_form.getElement('.gk_tab_add_content').getParent().setStyle('display', 'none');51 add_form.getElement('.gk_tab_add_url').getParent().setStyle('display', 'none');52 53 }54 //55 // add tab form events56 //57 add_form.getElement('.gk_tab_add_type').addEvent('change', function(){58 if(add_form.getElement('.gk_tab_add_type').value == 'article') {59 add_form.getElement('.gk_tab_add_art').setStyle('display', 'block');60 add_form.getElement('.gk_tab_add_artK2').setStyle('display', 'none');61 add_form.getElement('.gk_tab_add_name').getParent().setStyle('display', 'block');62 add_form.getElement('.gk_tab_add_content').getParent().setStyle('display', 'none');63 add_form.getElement('.gk_tab_add_url').getParent().setStyle('display', 'none');64 } else if (add_form.getElement('.gk_tab_add_type').value == 'text') {65 add_form.getElement('.gk_tab_add_art').setStyle('display', 'none');66 add_form.getElement('.gk_tab_add_artK2').setStyle('display', 'none');67 add_form.getElement('.gk_tab_add_name').getParent().setStyle('display', 'block');68 add_form.getElement('.gk_tab_add_content').getParent().setStyle('display', 'block');69 add_form.getElement('.gk_tab_add_url').getParent().setStyle('display', 'block');70 } else {71 add_form.getElement('.gk_tab_add_artK2').setStyle('display', 'block');72 add_form.getElement('.gk_tab_add_art').setStyle('display', 'none');73 add_form.getElement('.gk_tab_add_name').getParent().setStyle('display', 'block');74 add_form.getElement('.gk_tab_add_content').getParent().setStyle('display', 'none');75 add_form.getElement('.gk_tab_add_url').getParent().setStyle('display', 'none');76 }77 });78 //79 var add_form_scroll_wrap = document.id('gk_tab_add_form').getElement('.height_scroll');80 var add_form_scroll = new Fx.Tween(add_form_scroll_wrap, { duration: 250, property: 'height', onComplete: function() { if(add_form_scroll_wrap.getSize().y > 0) add_form_scroll_wrap.setStyle('height', 'auto'); } });81 //82 document.id('gk_tab_add_header').getElement('a').addEvent('click', function(e) {83 e.stop();84 add_form_scroll.start(add_form.getElement('.gk_tab_add').getSize().y);85 });86 //87 document.id('gk_tab_add_header').addEvent('click', function(e) {88 e.stop();89 add_form_scroll.start(add_form.getElement('.gk_tab_add').getSize().y);90 });91 //92 var add_form_btns = add_form.getElements('.gk_tab_add_submit a');93 // cancel button94 add_form_btns[1].addEvent('click', function(e) {95 if(e) e.stop();96 //97 add_form.getElement('.gk_tab_add_art').setStyle('display', 'none');98 add_form.getElement('.gk_tab_add_artK2').setStyle('display', 'none');99 add_form.getElement('.gk_tab_add_name').getParent().setStyle('display', 'block');100 add_form.getElement('.gk_tab_add_content').getParent().setStyle('display', 'block');101 add_form.getElement('.gk_tab_add_url').getParent().setStyle('display', 'block');102 // clear the form 103 add_form.getElement('.gk_tab_add_name').set('value', '');104 add_form.getElement('.gk_tab_add_type').set('value', 'text');105 add_form.getElement('.gk_tab_add_image').set('value', '');106 add_form.getElement('.gk_tab_add_stretch').set('value', 'nostretch');107 add_form.getElement('.gk_tab_add_content_access').set('value', 'public');108 add_form.getElement('.gk_tab_add_published').set('value', '1');109 add_form.getElement('.gk_tab_add_content').set('value', '');110 add_form.getElement('.gk_tab_add_url').set('value', '');111 add_form.getElement('#jform_request_art_name').set('value', '');112 add_form.getElement('#jform_request_art_add').set('value', '');113 add_form.getElement('#jform_request_artK2_name').set('value', '');114 add_form.getElement('#jform_request_artK2_add').set('value', '');115 // hide the form116 add_form_scroll_wrap.setStyle('height', add_form_scroll_wrap.getSize().y + 'px');117 add_form_scroll.start(0);118 });119 // save button120 add_form_btns[0].addEvent('click', function(e) {121 create_item('new');122 });123 // create item124 function create_item(source) {125 // duplicate item structure126 var item = document.id('invisible').getElement('.gk_tab_item').clone();127 // get the values from the form128 var name = (source == 'new') ? add_form.getElement('.gk_tab_add_name').get('value') : source.name;129 var type = (source == 'new') ? add_form.getElement('.gk_tab_add_type').get('value') : source.type;130 var image = (source == 'new') ? add_form.getElement('.gk_tab_add_image').get('value') : source.image;131 var stretch = (source == 'new') ? add_form.getElement('.gk_tab_add_stretch').get('value') : source.stretch;132 var access = (source == 'new') ? add_form.getElement('.gk_tab_add_content_access').get('value') : source.access;133 var published = (source == 'new') ? add_form.getElement('.gk_tab_add_published').get('value') : source.published;134 var content = (source == 'new') ? add_form.getElement('.gk_tab_add_content').get('value') : source.content;135 var url = (source == 'new') ? add_form.getElement('.gk_tab_add_url').get('value') : source.url;136 var artK2_id = (source == 'new') ? add_form.getElement('#jform_request_artK2_add').get('value') : source.artK2_id;137 var artK2_title = (source == 'new') ? add_form.getElement('#jform_request_artK2_name').get('value') : source.artK2_title;138 var art_id = (source == 'new') ? add_form.getElement('#jform_request_art_add').get('value') : source.art_id;139 var art_title = (source == 'new') ? add_form.getElement('#jform_request_art_name').get('value') : source.art_title;140 // put the values to the item141 item.getElement('.gk_tab_item_name').innerHTML = name;142 item.getElement('.gk_tab_item_type').innerHTML = (type == 'text') ? module_text : article_text;143 item.getElement('.gk_tab_item_state').setProperty('class', (published == 1) ? 'gk_tab_item_state published' : 'gk_tab_item_state unpublished');144 item.getElement('.gk_tab_item_state').setProperty('title', (published == 1) ? published_text : unpublished_text);145 item.getElement('.gk_tab_item_access').innerHTML = (access == 'public') ? public_text : registered_text;146 //147 // add the events to the item buttons148 //149 // fill the edit form150 item.getElement('.gk_tab_edit_name').set('value', name);151 item.getElement('.gk_tab_edit_type').set('value', type);152 item.getElement('.gk_tab_edit_image').set('value', image);153 item.getElement('.gk_tab_edit_stretch').set('value', stretch);154 item.getElement('.gk_tab_edit_content_access').set('value', access);155 item.getElement('.gk_tab_edit_published').set('value', published);156 item.getElement('.gk_tab_edit_content').set('value', htmlspecialchars_decode(content));157 item.getElement('.gk_tab_edit_url').set('value', url);158 item.getElement('.jform_request_edit_art').set('value', art_id);159 item.getElement('.jform_request_edit_artK2').set('value', artK2_id);160 item.getElement('.modal-art-name').set('value', art_title);161 item.getElement('.modal-artK2-name').set('value', artK2_title);162 // edit163 item.getElements('.gk_tab_item_edit').addEvent('click', function(e){164 if(e) e.stop();165 item.getElement('.gk_tab_item_desc').fireEvent('click');166 });167 // edit168 item.getElement('.gk_tab_item_desc').addEvent('click', function(e){169 if(e) e.stop();170 var scroller = item.getElement('.gk_tab_editor_scroll');171 scroller.setStyle('height', scroller.getSize().y + "px");172 var fx = new Fx.Tween(scroller, { duration: 250, property: 'height', onComplete: function() { if(scroller.getSize().y > 0) scroller.setStyle('height', 'auto'); } });173 174 if(scroller.getSize().y > 0) {175 fx.start(0);176 } else {177 var items = item.getParent().getElements('.gk_tab_item');178 179 items.each(function(it) {180 if(it != item) it.getElements('.gk_tab_edit_submit a')[1].fireEvent('click');181 });182 183 fx.start(scroller.getElement('div').getSize().y);184 var temp_id = item.getElement('.modal-art-name').getProperty('id');185 $currently_opened = temp_id.replace('jform_request_edit_art_name_', '');186 }187 });188 // publish / unpublish189 item.getElement('.gk_tab_item_state').addEvent('click', function(e) {190 if(e) e.stop();191 var btn = item.getElement('.gk_tab_item_state');192 if(btn.hasClass('published')) {193 item.getElement('.gk_tab_edit_published').set('value', 0);194 btn.setProperty('class', 'gk_tab_item_state unpublished');195 btn.setProperty('title', unpublished_text);196 item.getElements('.gk_tab_edit_submit a')[0].fireEvent('click');197 } else {198 item.getElement('.gk_tab_edit_published').set('value', 1);199 btn.setProperty('class', 'gk_tab_item_state published');200 btn.setProperty('title', published_text);201 item.getElements('.gk_tab_edit_submit a')[0].fireEvent('click');202 }203 });204 // set the content of the form205 if(item.getElement('.gk_tab_edit_type').value == 'article') {206 item.getElement('.gk_tab_edit_art').setStyle('display', 'block');207 item.getElement('.gk_tab_edit_name').getParent().setStyle('display', 'block');208 item.getElement('.gk_tab_edit_content').getParent().setStyle('display', 'none');209 item.getElement('.gk_tab_edit_url').getParent().setStyle('display', 'none');210 item.getElement('.gk_tab_edit_artK2').setStyle('display', 'none');211 } else if(item.getElement('.gk_tab_edit_type').value == 'text') {212 item.getElement('.gk_tab_edit_artK2').setStyle('display', 'none');213 item.getElement('.gk_tab_edit_art').setStyle('display', 'none');214 item.getElement('.gk_tab_edit_name').getParent().setStyle('display', 'block');215 item.getElement('.gk_tab_edit_content').getParent().setStyle('display', 'block');216 item.getElement('.gk_tab_edit_url').getParent().setStyle('display', 'block');217 } else {218 item.getElement('.gk_tab_edit_artK2').setStyle('display', 'block');219 item.getElement('.gk_tab_edit_name').getParent().setStyle('display', 'block');220 item.getElement('.gk_tab_edit_art').setStyle('display', 'none');221 item.getElement('.gk_tab_edit_content').getParent().setStyle('display', 'none');222 item.getElement('.gk_tab_edit_url').getParent().setStyle('display', 'none'); 223 }224 // change event225 item.getElement('.gk_tab_edit_type').addEvent('change', function(){226 if(item.getElement('.gk_tab_edit_type').value == 'article') {227 item.getElement('.gk_tab_edit_art').setStyle('display', 'block');228 item.getElement('.gk_tab_edit_artK2').setStyle('display', 'none');229 item.getElement('.gk_tab_edit_name').getParent().setStyle('display', 'block');230 item.getElement('.gk_tab_edit_content').getParent().setStyle('display', 'none');231 item.getElement('.gk_tab_edit_url').getParent().setStyle('display', 'none');232 } else if(item.getElement('.gk_tab_edit_type').value == 'text') {233 item.getElement('.gk_tab_edit_artK2').setStyle('display', 'none');234 item.getElement('.gk_tab_edit_art').setStyle('display', 'none');235 item.getElement('.gk_tab_edit_name').getParent().setStyle('display', 'block');236 item.getElement('.gk_tab_edit_content').getParent().setStyle('display', 'block');237 item.getElement('.gk_tab_edit_url').getParent().setStyle('display', 'block');238 239 } else {240 item.getElement('.gk_tab_edit_artK2').setStyle('display', 'block');241 item.getElement('.gk_tab_edit_name').getParent().setStyle('display', 'block');242 item.getElement('.gk_tab_edit_art').setStyle('display', 'none');243 item.getElement('.gk_tab_edit_content').getParent().setStyle('display', 'none');244 item.getElement('.gk_tab_edit_url').getParent().setStyle('display', 'none'); 245 246 }247 });248 // remove249 item.getElements('.gk_tab_item_remove').addEvent('click', function(e){250 if(e) e.stop();251 // get all items list252 var items = item.getParent().getElements('.gk_tab_item');253 // get the item ID on list254 var item_id = items.indexOf(item);255 // remove the object from the JSON array256 tabs.splice(item_id, 1);257 // remove the item from list258 item.destroy();259 // put the data to textarea field260 document.id('jform_params_image_show_data').innerHTML = JSON.encode(tabs);261 });262 // cancel edit263 item.getElements('.gk_tab_edit_submit a')[1].addEvent('click', function(e) {264 if(e) e.stop();265 // hide the form266 var scroller = item.getElement('.gk_tab_editor_scroll');267 scroller.setStyle('height', scroller.getSize().y + "px");268 new Fx.Tween(scroller, { duration: 250, property: 'height' }).start(0);269 });270 // save edit271 item.getElements('.gk_tab_edit_submit a')[0].addEvent('click', function(e) {272 if(e) e.stop();273 // get the data from editor 274 var name = item.getElement('.gk_tab_edit_name').get('value');275 var type = item.getElement('.gk_tab_edit_type').get('value');276 var image = item.getElement('.gk_tab_edit_image').get('value');277 var stretch = item.getElement('.gk_tab_edit_stretch').get('value');278 var access = item.getElement('.gk_tab_edit_content_access').get('value');279 var published = item.getElement('.gk_tab_edit_published').get('value');280 var content = item.getElement('.gk_tab_edit_content').get('value');281 var url = item.getElement('.gk_tab_edit_url').get('value');282 var art_id = item.getElement('.jform_request_edit_art').get('value');283 var art_title = item.getElement('.modal-art-name').get('value');284 var artK2_id = item.getElement('.jform_request_edit_artK2').get('value');285 var artK2_title = item.getElement('.modal-artK2-name').get('value');286 // set the data in the JSON object287 var items = item.getParent().getElements('.gk_tab_item');288 var item_id = items.indexOf(item);289 tabs[item_id] = {290 "name" : name,291 "type" : type,292 "image" : image,293 "stretch" : stretch,294 "access" : access,295 "published" : published,296 "content" : htmlspecialchars(content),297 "url" : url,298 "art_id" : art_id,299 "art_title" : art_title,300 "artK2_id" : artK2_id,301 "artK2_title" : artK2_title302 };303 // update the item content304 item.getElement('.gk_tab_item_name').innerHTML = name;305 item.getElement('.gk_tab_item_type').innerHTML = (type == 'text') ? module_text : article_text;306 item.getElement('.gk_tab_item_state').setProperty('class', (published == 1) ? 'gk_tab_item_state published' : 'gk_tab_item_state unpublished');307 item.getElement('.gk_tab_item_state').setProperty('title', (published == 1) ? published_text : unpublished_text);308 item.getElement('.gk_tab_item_access').innerHTML = (access == 'public') ? public_text : registered_text;309 item.getElement('.modal-img').setProperty('href', '../' + image);310 // hide the form311 item.getElements('.gk_tab_edit_submit a')[1].fireEvent('click');312 // put the data to textarea field313 document.id('jform_params_image_show_data').innerHTML = JSON.encode(tabs);314 });315 // order up 316 item.getElement('.gk_tab_item_order_up').addEvent('click', function(e) {317 if(e) e.stop();318 var wrap = item.getParent();319 // get item ID320 var items = item.getParent().getElements('.gk_tab_item');321 var item_id = items.indexOf(item);322 // check item ID323 if(item_id > 0) {324 var tmp = tabs[item_id - 1];325 tabs[item_id - 1] = tabs[item_id];326 tabs[item_id] = tmp;327 item.inject(item.getPrevious(), 'before');328 // refresh order buttons state329 if(items.length > 0) {330 wrap.getElements('.gk_tab_item_order_down').setStyle('opacity', 1);331 wrap.getElements('.gk_tab_item_order_up').setStyle('opacity', 1);332 wrap.getElement('.gk_tab_item_order_up').setStyle('opacity', 0.3);333 wrap.getElements('.gk_tab_item_order_down')[items.length - 1].setStyle('opacity', 0.3);334 }335 // put the data to textarea field336 document.id('jform_params_image_show_data').innerHTML = JSON.encode(tabs);337 } 338 });339 // order down340 item.getElement('.gk_tab_item_order_down').addEvent('click', function(e) {341 if(e) e.stop();342 var wrap = item.getParent();343 // get item ID344 var items = wrap.getElements('.gk_tab_item');345 var item_id = items.indexOf(item);346 // check item ID347 if(item_id < items.length - 1) {348 var tmp = tabs[item_id + 1];349 tabs[item_id + 1] = tabs[item_id];350 tabs[item_id] = tmp;351 item.inject(item.getNext(), 'after');352 // refresh order buttons state353 if(items.length > 0) {354 wrap.getElements('.gk_tab_item_order_down').setStyle('opacity', 1);355 wrap.getElements('.gk_tab_item_order_up').setStyle('opacity', 1);356 wrap.getElement('.gk_tab_item_order_up').setStyle('opacity', 0.3);357 wrap.getElements('.gk_tab_item_order_down')[items.length - 1].setStyle('opacity', 0.3);358 }359 // put the data to textarea field360 document.id('jform_params_image_show_data').innerHTML = JSON.encode(tabs);361 } 362 });363 //364 // put the data to object365 //366 if(source == 'new') { // only new objects367 tabs.push({368 "name" : name,369 "type" : type,370 "image" : image,371 "stretch" : stretch,372 "access" : access,373 "published" : published,374 "content" : htmlspecialchars(content),375 "url" : url,376 "art_id" : art_id,377 "art_title" : art_title,378 "artK2_id" : artK2_id, 379 "artK2_title" : artK2_title380 });381 382 // clear and hide the form383 add_form_btns[1].fireEvent('click');384 // put the data to textarea field385 document.id('jform_params_image_show_data').innerHTML = JSON.encode(tabs);386 387 SqueezeBox.assign(item.getElements('.gk-modal'), { parse: 'rel' });388 } /*else {389 SqueezeBox.assign(item.getElements('.gk-modal'), { parse: 'rel' });390 }*/391 // put the item to the list392 item.inject(document.id('tabs_list'), 'bottom');393 // refresh order buttons state394 var wrap = item.getParent();395 var items = wrap.getElements('.gk_tab_item');396 if(items.length > 0) {397 wrap.getElements('.gk_tab_item_order_down').setStyle('opacity', 1);398 wrap.getElements('.gk_tab_item_order_up').setStyle('opacity', 1);399 wrap.getElement('.gk_tab_item_order_up').setStyle('opacity', 0.3);400 wrap.getElements('.gk_tab_item_order_down')[items.length - 1].setStyle('opacity', 0.3);401 }402 // prepare preview link403 item.getElement('.modal-img').setProperty('href', '../' + image);404 // prepare media manager405 $current_slide++;406 item.getElement('.gk_tab_edit_image').setProperty('id', 'jform_params_edit_img_' + $current_slide);407 item.getElement('.modal-media').setProperty('href', 'index.php?option=com_media&view=images&tmpl=component&asset=&author=&fieldid=jform_params_edit_img_'+$current_slide+'&folder=');408 item.getElement('.modal-media-clear').setProperty('onclick', 'javascript:document.getElementById(\'jform_params_edit_img_'+$current_slide+'\').value=\'\';return false;');409 // prepare article selector410 item.getElement('.modal-art-name').setProperty('id', 'jform_request_edit_art_name_' + $current_slide);411 item.getElement('.jform_request_edit_art').setProperty('id', 'jform_request_edit_art_' + $current_slide);412 item.getElement('.modal-artK2-name').setProperty('id', 'jform_request_edit_artK2_name_' + $current_slide);413 item.getElement('.jform_request_edit_artK2').setProperty('id', 'jform_request_edit_artK2_' + $current_slide);414 }415 // generate the list416 tabs.each(function(tab) {417 create_item(tab);418 });419 420 (function() {421 //SqueezeBox.initialize();422 SqueezeBox.assign('.gk-modal', { parse: 'rel' });423 }).delay(1500);424 425 // manage the styles settings426 $$('.module_style').each(function(el) {427 var style_name = el.getProperty('id').replace('module_style_', '');428 // initialize429 if(config[style_name]) {430 el.getElements('.field').each(function(field) {431 if(config[style_name][field.getProperty('id')]) {432 field.set('value', config[style_name][field.getProperty('id')]);433 } else {434 config[style_name][field.getProperty('id')] = field.get('value');435 }436 });437 } else {438 config[style_name] = {};439 440 el.getElements('.field').each(function(field) {441 config[style_name][field.getProperty('id')] = field.get('value');442 });443 }444 445 el.getElements('.field').each(function(elm) {446 elm.addEvent('change', function() {447 config[style_name][elm.getProperty('id')] = elm.get('value');448 document.id('jform_params_config').innerHTML = JSON.encode(config);449 });450 451 elm.addEvent('blur', function() {452 config[style_name][elm.getProperty('id')] = elm.get('value');453 document.id('jform_params_config').innerHTML = JSON.encode(config);454 });455 });456 457 document.id('jform_params_config').innerHTML = JSON.encode(config);458 });459 460 // enable time update in last_modification element461 (function() {462 document.id('jform_params_last_modification').set('value', Math.round(new Date().getTime() / 1000));463 }).periodical(3000);464 465 // initialize switcher466 $$('.module_style').setStyle('display', 'none');467 document.id('module_style_' + document.id('jform_params_module_style').get('value')).setStyle('display', 'block');468 469 document.id('jform_params_module_style').addEvent('change', function() {470 $$('.module_style').setStyle('display', 'none');471 document.id('module_style_' + document.id('jform_params_module_style').get('value')).setStyle('display', 'block');472 });473 474 document.id('jform_params_module_style').addEvent('blur', function() {475 $$('.module_style').setStyle('display', 'none');476 document.id('module_style_' + document.id('jform_params_module_style').get('value')).setStyle('display', 'block');477 });478 479 // other form operations480 /*$$('.input-px').each(function(el){ el.set('class', 'add-on'); el.getParent().innerHTML = "<div class=\"input-prepend\">" + el.getParent().innerHTML + "</div>"});481 $$('.input-ms').each(function(el){el.set('class', 'add-on'); el.getParent().innerHTML = "<div class=\"input-prepend\">" + el.getParent().innerHTML + "</div>"});482 $$('.input-percents').each(function(el){el.set('class', 'add-on'); el.getParent().innerHTML = "<div class=\"input-prepend\">" + el.getParent().innerHTML + "</div>"});483 $$('.input-minutes').each(function(el){el.set('class', 'add-on'); el.getParent().innerHTML = "<div class=\"input-prepend\">" + el.getParent().innerHTML + "</div>"});*/484 485 document.id('gk_tab_manager').getParent().setStyle('margin-left', '5px');486 document.id('gk_about_us').getParent().setStyle('margin-left', '15px');487 //document.id('options-IMAGE_SHOW_INTERFACE').getElement('.controls').setStyle('margin-left', '5px');488 if(!document.id('module-form').hasClass('j32')) {489 document.id('moduleOptions').getElement('.module_style').getParent().setStyle('margin-left', '5px');490 }491 492 493 // help link494 var link = new Element('a', { 'class' : 'gkHelpLink', 'href' : 'https://www.gavick.com/image-show-gk4.html', 'target' : '_blank' })495 link.inject($$('ul.nav li')[$$('ul.nav li').length-2].getElement('a'), 'bottom');496 link.addEvent('click', function(e) { e.stopPropagation(); });497 498 //499 //document.id('IMAGE_SHOW_MANAGER-options').getParent().getElement('.panelform .adminformlist li').setStyle('border', 'none');500});501// encode chars502function htmlspecialchars(string) {503 string = string.toString();504 string = string.replace(/&/g, '[ampersand]').replace(/</g, '[leftbracket]').replace(/>/g, '[rightbracket]');505 return string;506}507// decode chars508function htmlspecialchars_decode(string) {509 string = string.toString();510 string = string.replace(/\[ampersand\]/g, '&').replace(/\[leftbracket\]/g, '<').replace(/\[rightbracket\]/g, '>');511 return string;...
pattern_test.js
Source:pattern_test.js
...32 testStartTag() {33 const pattern = new StartTag('DIV');34 assertEquals(35 'StartTag(div) should match div', MatchType.MATCH,36 pattern.matchToken(dom.getElement('div1'), TagWalkType.START_TAG));37 assertEquals(38 'StartTag(div) should not match span', MatchType.NO_MATCH,39 pattern.matchToken(dom.getElement('span1'), TagWalkType.START_TAG));40 assertEquals(41 'StartTag(div) should not match /div', MatchType.NO_MATCH,42 pattern.matchToken(dom.getElement('div1'), TagWalkType.END_TAG));43 },44 testStartTagCase() {45 const pattern = new StartTag('diV');46 assertEquals(47 'StartTag(diV) should match div', MatchType.MATCH,48 pattern.matchToken(dom.getElement('div1'), TagWalkType.START_TAG));49 assertEquals(50 'StartTag(diV) should not match span', MatchType.NO_MATCH,51 pattern.matchToken(dom.getElement('span1'), TagWalkType.START_TAG));52 },53 testStartTagRegex() {54 const pattern = new StartTag(/D/);55 assertEquals(56 'StartTag(/D/) should match div', MatchType.MATCH,57 pattern.matchToken(dom.getElement('div1'), TagWalkType.START_TAG));58 assertEquals(59 'StartTag(/D/) should not match span', MatchType.NO_MATCH,60 pattern.matchToken(dom.getElement('span1'), TagWalkType.START_TAG));61 assertEquals(62 'StartTag(/D/) should not match /div', MatchType.NO_MATCH,63 pattern.matchToken(dom.getElement('div1'), TagWalkType.END_TAG));64 },65 testStartTagAttributes() {66 const pattern = new StartTag('DIV', {id: 'div1'});67 assertEquals(68 'StartTag(div,id:div1) should match div1', MatchType.MATCH,69 pattern.matchToken(dom.getElement('div1'), TagWalkType.START_TAG));70 assertEquals(71 'StartTag(div,id:div2) should not match div1', MatchType.NO_MATCH,72 pattern.matchToken(dom.getElement('div2'), TagWalkType.START_TAG));73 },74 testStartTagStyle() {75 const pattern = new StartTag('SPAN', null, {color: 'red'});76 assertEquals(77 'StartTag(span,null,color:red) should match span1', MatchType.MATCH,78 pattern.matchToken(dom.getElement('span1'), TagWalkType.START_TAG));79 assertEquals(80 'StartTag(span,null,color:blue) should not match span1',81 MatchType.NO_MATCH,82 pattern.matchToken(dom.getElement('span2'), TagWalkType.START_TAG));83 },84 testStartTagAttributeRegex() {85 const pattern = new StartTag('SPAN', {id: /span\d/});86 assertEquals(87 'StartTag(span,id:/span\\d/) should match span1', MatchType.MATCH,88 pattern.matchToken(dom.getElement('span1'), TagWalkType.START_TAG));89 assertEquals(90 'StartTag(span,id:/span\\d/) should match span2', MatchType.MATCH,91 pattern.matchToken(dom.getElement('span1'), TagWalkType.START_TAG));92 },93 testEndTag() {94 const pattern = new EndTag('DIV');95 assertEquals(96 'EndTag should match div', MatchType.MATCH,97 pattern.matchToken(dom.getElement('div1'), TagWalkType.END_TAG));98 },99 testEndTagRegex() {100 const pattern = new EndTag(/D/);101 assertEquals(102 'EndTag(/D/) should match /div', MatchType.MATCH,103 pattern.matchToken(dom.getElement('div1'), TagWalkType.END_TAG));104 assertEquals(105 'EndTag(/D/) should not match /span', MatchType.NO_MATCH,106 pattern.matchToken(dom.getElement('span1'), TagWalkType.END_TAG));107 assertEquals(108 'EndTag(/D/) should not match div', MatchType.NO_MATCH,109 pattern.matchToken(dom.getElement('div1'), TagWalkType.START_TAG));110 },111 testChildMatches() {112 const pattern = new ChildMatches(new StartTag('DIV'), 2);113 assertEquals(114 'ChildMatches should match div', MatchType.MATCHING,115 pattern.matchToken(dom.getElement('div1'), TagWalkType.START_TAG));116 assertEquals(117 'ChildMatches should match /div', MatchType.MATCHING,118 pattern.matchToken(dom.getElement('div1'), TagWalkType.END_TAG));119 assertEquals(120 'ChildMatches should match div', MatchType.MATCHING,121 pattern.matchToken(dom.getElement('div2'), TagWalkType.START_TAG));122 assertEquals(123 'ChildMatches should match /div', MatchType.MATCHING,124 pattern.matchToken(dom.getElement('div2'), TagWalkType.END_TAG));125 assertEquals(126 'ChildMatches should finish match at /body', MatchType.BACKTRACK_MATCH,127 pattern.matchToken(document.body, TagWalkType.END_TAG));128 assertEquals(129 'ChildMatches should match div', MatchType.MATCHING,130 pattern.matchToken(dom.getElement('div2'), TagWalkType.START_TAG));131 assertEquals(132 'ChildMatches should match /div', MatchType.MATCHING,133 pattern.matchToken(dom.getElement('div2'), TagWalkType.END_TAG));134 assertEquals(135 'ChildMatches should fail to match at /body: not enough child matches',136 MatchType.NO_MATCH,137 pattern.matchToken(document.body, TagWalkType.END_TAG));138 },139 testFullTag() {140 const pattern = new FullTag('DIV');141 assertEquals(142 'FullTag(div) should match div', MatchType.MATCHING,143 pattern.matchToken(dom.getElement('div1'), TagWalkType.START_TAG));144 assertEquals(145 'FullTag(div) should match /div', MatchType.MATCH,146 pattern.matchToken(dom.getElement('div1'), TagWalkType.END_TAG));147 assertEquals(148 'FullTag(div) should start match at div', MatchType.MATCHING,149 pattern.matchToken(dom.getElement('div1'), TagWalkType.START_TAG));150 assertEquals(151 'FullTag(div) should continue to match span', MatchType.MATCHING,152 pattern.matchToken(dom.getElement('span1'), TagWalkType.START_TAG));153 assertEquals(154 'FullTag(div) should continue to match /span', MatchType.MATCHING,155 pattern.matchToken(dom.getElement('span1'), TagWalkType.END_TAG));156 assertEquals(157 'FullTag(div) should finish match at /div', MatchType.MATCH,158 pattern.matchToken(dom.getElement('div1'), TagWalkType.END_TAG));159 },160 testAllChildren() {161 const pattern = new AllChildren();162 assertEquals(163 'AllChildren(div) should match div', MatchType.MATCHING,164 pattern.matchToken(dom.getElement('div1'), TagWalkType.START_TAG));165 assertEquals(166 'AllChildren(div) should match /div', MatchType.MATCHING,167 pattern.matchToken(dom.getElement('div1'), TagWalkType.END_TAG));168 assertEquals(169 'AllChildren(div) should match at /body', MatchType.BACKTRACK_MATCH,170 pattern.matchToken(document.body, TagWalkType.END_TAG));171 assertEquals(172 'AllChildren(div) should start match at div', MatchType.MATCHING,173 pattern.matchToken(dom.getElement('div1'), TagWalkType.START_TAG));174 assertEquals(175 'AllChildren(div) should continue to match span', MatchType.MATCHING,176 pattern.matchToken(dom.getElement('span1'), TagWalkType.START_TAG));177 assertEquals(178 'AllChildren(div) should continue to match /span', MatchType.MATCHING,179 pattern.matchToken(dom.getElement('span1'), TagWalkType.END_TAG));180 assertEquals(181 'AllChildren(div) should continue to match at /div', MatchType.MATCHING,182 pattern.matchToken(dom.getElement('div1'), TagWalkType.END_TAG));183 assertEquals(184 'AllChildren(div) should finish match at /body',185 MatchType.BACKTRACK_MATCH,186 pattern.matchToken(document.body, TagWalkType.END_TAG));187 },188 testText() {189 const pattern = new PatternText('Text');190 assertEquals(191 'Text should match div3/text()', MatchType.MATCH,192 pattern.matchToken(193 dom.getElement('div3').firstChild, TagWalkType.OTHER));194 assertEquals(195 'Text should not match div4/text()', MatchType.NO_MATCH,196 pattern.matchToken(197 dom.getElement('div4').firstChild, TagWalkType.OTHER));198 assertEquals(199 'Text should not match div3', MatchType.NO_MATCH,200 pattern.matchToken(dom.getElement('div3'), TagWalkType.START_TAG));201 },202 testTextRegex() {203 const pattern = new PatternText(/Text/);204 assertEquals(205 'Text(regex) should match div3/text()', MatchType.MATCH,206 pattern.matchToken(207 dom.getElement('div3').firstChild, TagWalkType.OTHER));208 assertEquals(209 'Text(regex) should match div4/text()', MatchType.MATCH,210 pattern.matchToken(211 dom.getElement('div4').firstChild, TagWalkType.OTHER));212 },213 testNodeType() {214 const pattern = new PatternNodeType(NodeType.COMMENT);215 assertEquals(216 'Comment matcher should match a comment', MatchType.MATCH,217 pattern.matchToken(218 dom.getElement('nodeTypes').firstChild, TagWalkType.OTHER));219 assertEquals(220 'Comment matcher should not match a text node', MatchType.NO_MATCH,221 pattern.matchToken(222 dom.getElement('nodeTypes').lastChild, TagWalkType.OTHER));223 },224 testSequence() {225 const pattern = new Sequence([226 new StartTag('DIV'),227 new StartTag('SPAN'),228 new EndTag('SPAN'),229 new EndTag('DIV'),230 ]);231 assertEquals(232 'Sequence[0] should match div1', MatchType.MATCHING,233 pattern.matchToken(dom.getElement('div1'), TagWalkType.START_TAG));234 assertEquals(235 'Sequence[1] should match span1', MatchType.MATCHING,236 pattern.matchToken(dom.getElement('span1'), TagWalkType.START_TAG));237 assertEquals(238 'Sequence[2] should match /span1', MatchType.MATCHING,239 pattern.matchToken(dom.getElement('span1'), TagWalkType.END_TAG));240 assertEquals(241 'Sequence[3] should match /div1', MatchType.MATCH,242 pattern.matchToken(dom.getElement('div1'), TagWalkType.END_TAG));243 assertEquals(244 'Sequence[0] should match div1 again', MatchType.MATCHING,245 pattern.matchToken(dom.getElement('div1'), TagWalkType.START_TAG));246 assertEquals(247 'Sequence[1] should match span1 again', MatchType.MATCHING,248 pattern.matchToken(dom.getElement('span1'), TagWalkType.START_TAG));249 assertEquals(250 'Sequence[2] should match /span1 again', MatchType.MATCHING,251 pattern.matchToken(dom.getElement('span1'), TagWalkType.END_TAG));252 assertEquals(253 'Sequence[3] should match /div1 again', MatchType.MATCH,254 pattern.matchToken(dom.getElement('div1'), TagWalkType.END_TAG));255 assertEquals(256 'Sequence[0] should match div1', MatchType.MATCHING,257 pattern.matchToken(dom.getElement('div1'), TagWalkType.START_TAG));258 assertEquals(259 'Sequence[1] should not match div1', MatchType.NO_MATCH,260 pattern.matchToken(dom.getElement('div1'), TagWalkType.START_TAG));261 assertEquals(262 'Sequence[0] should match div1 after failure', MatchType.MATCHING,263 pattern.matchToken(dom.getElement('div1'), TagWalkType.START_TAG));264 assertEquals(265 'Sequence[1] should match span1 after failure', MatchType.MATCHING,266 pattern.matchToken(dom.getElement('span1'), TagWalkType.START_TAG));267 assertEquals(268 'Sequence[2] should match /span1 after failure', MatchType.MATCHING,269 pattern.matchToken(dom.getElement('span1'), TagWalkType.END_TAG));270 assertEquals(271 'Sequence[3] should match /div1 after failure', MatchType.MATCH,272 pattern.matchToken(dom.getElement('div1'), TagWalkType.END_TAG));273 },274 testRepeat() {275 const pattern = new Repeat(new StartTag('B'));276 // Note: this test does not mimic an actual matcher because it is only277 // passing the START_TAG events.278 assertEquals(279 'Repeat[B] should match b1', MatchType.MATCHING,280 pattern.matchToken(dom.getElement('b1'), TagWalkType.START_TAG));281 assertEquals(282 'Repeat[B] should match b2', MatchType.MATCHING,283 pattern.matchToken(dom.getElement('b2'), TagWalkType.START_TAG));284 assertEquals(285 'Repeat[B] should backtrack match i1', MatchType.BACKTRACK_MATCH,286 pattern.matchToken(dom.getElement('i1'), TagWalkType.START_TAG));287 assertEquals('Repeat[B] should have match count of 2', 2, pattern.count);288 assertEquals(289 'Repeat[B] should backtrack match i1 even with no b matches',290 MatchType.BACKTRACK_MATCH,291 pattern.matchToken(dom.getElement('i1'), TagWalkType.START_TAG));292 assertEquals('Repeat[B] should have match count of 0', 0, pattern.count);293 },294 testRepeatWithMinimum() {295 const pattern = new Repeat(new StartTag('B'), 1);296 // Note: this test does not mimic an actual matcher because it is only297 // passing the START_TAG events.298 assertEquals(299 'Repeat[B,1] should match b1', MatchType.MATCHING,300 pattern.matchToken(dom.getElement('b1'), TagWalkType.START_TAG));301 assertEquals(302 'Repeat[B,1] should match b2', MatchType.MATCHING,303 pattern.matchToken(dom.getElement('b2'), TagWalkType.START_TAG));304 assertEquals(305 'Repeat[B,1] should backtrack match i1', MatchType.BACKTRACK_MATCH,306 pattern.matchToken(dom.getElement('i1'), TagWalkType.START_TAG));307 assertEquals('Repeat[B,1] should have match count of 2', 2, pattern.count);308 assertEquals(309 'Repeat[B,1] should not match i1', MatchType.NO_MATCH,310 pattern.matchToken(dom.getElement('i1'), TagWalkType.START_TAG));311 },312 testRepeatWithMaximum() {313 const pattern = new Repeat(new StartTag('B'), 1, 1);314 // Note: this test does not mimic an actual matcher because it is only315 // passing the START_TAG events.316 assertEquals(317 'Repeat[B,1] should match b1', MatchType.MATCH,318 pattern.matchToken(dom.getElement('b1'), TagWalkType.START_TAG));319 },320 testSequenceBacktrack() {321 const pattern = new Sequence([322 new Repeat(new StartTag('SPAN')),323 new PatternText('X'),324 ]);325 const root = dom.getElement('span3');326 assertEquals(327 'Sequence[Repeat[SPAN],"X"] should match span3', MatchType.MATCHING,328 pattern.matchToken(root, TagWalkType.START_TAG));329 assertEquals(330 'Sequence[Repeat[SPAN],"X"] should match span3.firstChild',331 MatchType.MATCHING,332 pattern.matchToken(root.firstChild, TagWalkType.START_TAG));333 assertEquals(334 'Sequence[Repeat[SPAN],"X"] should match span3.firstChild.firstChild',335 MatchType.MATCHING,336 pattern.matchToken(root.firstChild.firstChild, TagWalkType.START_TAG));337 assertEquals(338 'Sequence[Repeat[SPAN],"X"] should finish match text node',339 MatchType.MATCH,...
forms_test.js
Source:forms_test.js
...16goog.require('goog.dom');17goog.require('goog.dom.forms');18goog.require('goog.testing.jsunit');19function testGetFormDataString() {20 var el = goog.dom.getElement('testform1');21 var result = goog.dom.forms.getFormDataString(el);22 assertEquals(23 'in1=foo&in2=bar&in2=baaz&in3=&pass=bar&textarea=foo%20bar%20baz&' +24 'select1=1&select2=a&select2=c&select3=&checkbox1=on&radio=X&radio2=Y',25 result);26}27function testGetFormDataMap() {28 var el = goog.dom.getElement('testform1');29 var result = goog.dom.forms.getFormDataMap(el);30 assertArrayEquals(['foo'], result.get('in1'));31 assertArrayEquals(['bar', 'baaz'], result.get('in2'));32 assertArrayEquals(['1'], result.get('select1'));33 assertArrayEquals(['a', 'c'], result.get('select2'));34 assertArrayEquals(['on'], result.get('checkbox1'));35 assertUndefined(result.get('select6'));36 assertUndefined(result.get('checkbox2'));37 assertArrayEquals(['X'], result.get('radio'));38 assertArrayEquals(['Y'], result.get('radio2'));39}40function testHasFileInput() {41 var el = goog.dom.getElement('testform1');42 assertFalse(goog.dom.forms.hasFileInput(el));43 el = goog.dom.getElement('testform2');44 assertTrue(goog.dom.forms.hasFileInput(el));45}46function testGetValueOnAtypicalValueElements() {47 var el = goog.dom.getElement('testdiv1');48 var result = goog.dom.forms.getValue(el);49 assertNull(result);50 var el = goog.dom.getElement('testfieldset1');51 var result = goog.dom.forms.getValue(el);52 assertNull(result);53 var el = goog.dom.getElement('testlegend1');54 var result = goog.dom.forms.getValue(el);55 assertNull(result);56}57function testHasValueInput() {58 var el = goog.dom.getElement('in1');59 var result = goog.dom.forms.hasValue(el);60 assertTrue(result);61}62function testGetValueByNameForNonExistentElement() {63 var form = goog.dom.getElement('testform1');64 var result = goog.dom.forms.getValueByName(form, 'non_existent');65 assertNull(result);66}67function testHasValueByNameInput() {68 var form = goog.dom.getElement('testform1');69 var result = goog.dom.forms.hasValueByName(form, 'in1');70 assertTrue(result);71}72function testHasValueInputEmpty() {73 var el = goog.dom.getElement('in3');74 var result = goog.dom.forms.hasValue(el);75 assertFalse(result);76}77function testHasValueByNameEmpty() {78 var form = goog.dom.getElement('testform1');79 var result = goog.dom.forms.hasValueByName(form, 'in3');80 assertFalse(result);81}82function testHasValueRadio() {83 var el = goog.dom.getElement('radio1');84 var result = goog.dom.forms.hasValue(el);85 assertTrue(result);86}87function testHasValueByNameRadio() {88 var form = goog.dom.getElement('testform1');89 var result = goog.dom.forms.hasValueByName(form, 'radio');90 assertTrue(result);91}92function testHasValueRadioNotChecked() {93 var el = goog.dom.getElement('radio2');94 var result = goog.dom.forms.hasValue(el);95 assertFalse(result);96}97function testHasValueByNameRadioNotChecked() {98 var form = goog.dom.getElement('testform3');99 var result = goog.dom.forms.hasValueByName(form, 'radio3');100 assertFalse(result);101}102function testHasValueSelectSingle() {103 var el = goog.dom.getElement('select1');104 var result = goog.dom.forms.hasValue(el);105 assertTrue(result);106}107function testHasValueByNameSelectSingle() {108 var form = goog.dom.getElement('testform1');109 var result = goog.dom.forms.hasValueByName(form, 'select1');110 assertTrue(result);111}112function testHasValueSelectMultiple() {113 var el = goog.dom.getElement('select2');114 var result = goog.dom.forms.hasValue(el);115 assertTrue(result);116}117function testHasValueByNameSelectMultiple() {118 var form = goog.dom.getElement('testform1');119 var result = goog.dom.forms.hasValueByName(form, 'select2');120 assertTrue(result);121}122function testHasValueSelectNotSelected() {123 // select without value124 var el = goog.dom.getElement('select3');125 var result = goog.dom.forms.hasValue(el);126 assertFalse(result);127}128function testHasValueByNameSelectNotSelected() {129 var form = goog.dom.getElement('testform1');130 var result = goog.dom.forms.hasValueByName(form, 'select3');131 assertFalse(result);132}133function testHasValueSelectMultipleNotSelected() {134 var el = goog.dom.getElement('select6');135 var result = goog.dom.forms.hasValue(el);136 assertFalse(result);137}138function testHasValueByNameSelectMultipleNotSelected() {139 var form = goog.dom.getElement('testform3');140 var result = goog.dom.forms.hasValueByName(form, 'select6');141 assertFalse(result);142}143// TODO(user): make this a meaningful selenium test144function testSetDisabledFalse() {145}146function testSetDisabledTrue() {147}148// TODO(user): make this a meaningful selenium test149function testFocusAndSelect() {150 var el = goog.dom.getElement('in1');151 goog.dom.forms.focusAndSelect(el);152}153function testGetValueInput() {154 var el = goog.dom.getElement('in1');155 var result = goog.dom.forms.getValue(el);156 assertEquals('foo', result);157}158function testSetValueInput() {159 var el = goog.dom.getElement('in3');160 goog.dom.forms.setValue(el, 'foo');161 assertEquals('foo', goog.dom.forms.getValue(el));162 goog.dom.forms.setValue(el, 3500);163 assertEquals('3500', goog.dom.forms.getValue(el));164 goog.dom.forms.setValue(el, 0);165 assertEquals('0', goog.dom.forms.getValue(el));166 goog.dom.forms.setValue(el, null);167 assertEquals('', goog.dom.forms.getValue(el));168 goog.dom.forms.setValue(el, undefined);169 assertEquals('', goog.dom.forms.getValue(el));170 goog.dom.forms.setValue(el, false);171 assertEquals('false', goog.dom.forms.getValue(el));172 goog.dom.forms.setValue(el, {});173 assertEquals({}.toString(), goog.dom.forms.getValue(el));174 goog.dom.forms.setValue(el, {175 toString: function() {176 return 'test';177 }178 });179 assertEquals('test', goog.dom.forms.getValue(el));180 // unset181 goog.dom.forms.setValue(el);182 assertEquals('', goog.dom.forms.getValue(el));183}184function testGetValuePassword() {185 var el = goog.dom.getElement('pass');186 var result = goog.dom.forms.getValue(el);187 assertEquals('bar', result);188}189function testGetValueByNamePassword() {190 var form = goog.dom.getElement('testform1');191 var result = goog.dom.forms.getValueByName(form, 'pass');192 assertEquals('bar', result);193}194function testGetValueTextarea() {195 var el = goog.dom.getElement('textarea1');196 var result = goog.dom.forms.getValue(el);197 assertEquals('foo bar baz', result);198}199function testGetValueByNameTextarea() {200 var form = goog.dom.getElement('testform1');201 var result = goog.dom.forms.getValueByName(form, 'textarea1');202 assertEquals('foo bar baz', result);203}204function testSetValueTextarea() {205 var el = goog.dom.getElement('textarea2');206 goog.dom.forms.setValue(el, 'foo bar baz');207 var result = goog.dom.forms.getValue(el);208 assertEquals('foo bar baz', result);209}210function testGetValueSelectSingle() {211 var el = goog.dom.getElement('select1');212 var result = goog.dom.forms.getValue(el);213 assertEquals('1', result);214}215function testGetValueByNameSelectSingle() {216 var form = goog.dom.getElement('testform1');217 var result = goog.dom.forms.getValueByName(form, 'select1');218 assertEquals('1', result);219}220function testSetValueSelectSingle() {221 var el = goog.dom.getElement('select4');222 goog.dom.forms.setValue(el, '2');223 var result = goog.dom.forms.getValue(el);224 assertEquals('2', result);225 // unset226 goog.dom.forms.setValue(el);227 var result = goog.dom.forms.getValue(el);228 assertNull(result);229}230function testSetValueSelectSingleEmptyString() {231 var el = goog.dom.getElement('select7');232 // unset233 goog.dom.forms.setValue(el);234 var result = goog.dom.forms.getValue(el);235 assertNull(result);236 goog.dom.forms.setValue(el, '');237 result = goog.dom.forms.getValue(el);238 assertEquals('', result);239}240function testGetValueSelectMultiple() {241 var el = goog.dom.getElement('select2');242 var result = goog.dom.forms.getValue(el);243 assertArrayEquals(['a', 'c'], result);244}245function testGetValueSelectMultipleNotSelected() {246 var el = goog.dom.getElement('select6');247 var result = goog.dom.forms.getValue(el);248 assertNull(result);249}250function testGetValueByNameSelectMultiple() {251 var form = goog.dom.getElement('testform1');252 var result = goog.dom.forms.getValueByName(form, 'select2');253 assertArrayEquals(['a', 'c'], result);254}255function testSetValueSelectMultiple() {256 var el = goog.dom.getElement('select5');257 goog.dom.forms.setValue(el, ['a', 'c']);258 var result = goog.dom.forms.getValue(el);259 assertArrayEquals(['a', 'c'], result);260 goog.dom.forms.setValue(el, 'a');261 var result = goog.dom.forms.getValue(el);262 assertArrayEquals(['a'], result);263 // unset264 goog.dom.forms.setValue(el);265 var result = goog.dom.forms.getValue(el);266 assertNull(result);267}268function testGetValueCheckbox() {269 var el = goog.dom.getElement('checkbox1');270 var result = goog.dom.forms.getValue(el);271 assertEquals('on', result);272 var el = goog.dom.getElement('checkbox2');273 var result = goog.dom.forms.getValue(el);274 assertNull(result);275}276function testGetValueByNameCheckbox() {277 var form = goog.dom.getElement('testform1');278 var result = goog.dom.forms.getValueByName(form, 'checkbox1');279 assertEquals('on', result);280 result = goog.dom.forms.getValueByName(form, 'checkbox2');281 assertNull(result);282}283function testGetValueRadio() {284 var el = goog.dom.getElement('radio1');285 var result = goog.dom.forms.getValue(el);286 assertEquals('X', result);287 var el = goog.dom.getElement('radio2');288 var result = goog.dom.forms.getValue(el);289 assertNull(result);290}291function testGetValueByNameRadio() {292 var form = goog.dom.getElement('testform1');293 var result = goog.dom.forms.getValueByName(form, 'radio');294 assertEquals('X', result);295 result = goog.dom.forms.getValueByName(form, 'radio2');296 assertEquals('Y', result);297}298function testGetValueButton() {299 var el = goog.dom.getElement('button');300 var result = goog.dom.forms.getValue(el);301 assertEquals('button', result);302}303function testGetValueSubmit() {304 var el = goog.dom.getElement('submit');305 var result = goog.dom.forms.getValue(el);306 assertEquals('submit', result);307}308function testGetValueReset() {309 var el = goog.dom.getElement('reset');310 var result = goog.dom.forms.getValue(el);311 assertEquals('reset', result);312}313function testGetFormDataHelperAndNonInputElements() {314 var el = goog.dom.getElement('testform4');315 goog.dom.forms.getFormDataHelper_(el, {}, goog.nullFunction);...
domHandler.js
Source:domHandler.js
...51 }52 return divs;53}54function errorDisplayer() {55 setInner(getElement('main-title'), 'Data not available :(');56 setInner(getElement('city-desc'), 'City');57 setInner(getElement('date-desc'), 'Date: --');58 setInner(getElement('weather-desc'), 'Weather: --');59 setInner(getElement('temperature-desc'), 'Temperature: --');60 setInner(getElement('realFeel-desc'), 'Real Feel: --');61 setInner(getElement('windSpeed-desc'), 'Wind Speed: --');62 setInner(getElement('humidity-desc'), 'Humidity: --');63 setInner(getElement('windDirection-desc'), ' Wind direction: --');64 setToClass(getElement('wicon'), 'unknown');65}66function cleanInput() {67 setValue(getElement('address-input'), '');68}69function setImages() {70 const { isDay } = catchData;71 const code = catchData.weatherPrimaryCoded;72 getElement('main').style.color = '#775e5e';73 if (weatherCodes.hail.test(code)) {74 setToClass(getElement('wicon'), 'hail');75 setToClass(getElement('bkg-cont'), 'hail-bkg');76 } else if (weatherCodes.dust_sand.test(code)) {77 setToClass(getElement('wicon'), 'dust-sand');78 setToClass(getElement('bkg-cont'), 'dust-sand-bkg');79 } else if (weatherCodes.smoke.test(code)) {80 setToClass(getElement('wicon'), 'smoke');81 setToClass(getElement('bkg-cont'), 'smoke-bkg');82 } else if (weatherCodes.wintry_mix.test(code)) {83 setToClass(getElement('wicon'), 'wintry_mix');84 setToClass(getElement('bkg-cont'), 'wintry_mix-bkg');85 } else if (weatherCodes.thunderstorm.test(code)) {86 setToClass(getElement('wicon'), 'thunderstorm');87 setToClass(getElement('bkg-cont'), 'thunderstorm-bkg');88 } else if (weatherCodes.volc_ash.test(code)) {89 setToClass(getElement('wicon'), 'volc_ash');90 setToClass(getElement('bkg-cont'), 'volc_ash-bkg');91 } else if (isDay) {92 getElement('main').style.color = '#000';93 if (cloudCodes.clear.test(code)) {94 setToClass(getElement('wicon'), 'clear-day');95 setToClass(getElement('bkg-cont'), 'clear-d-bkg');96 } else if (cloudCodes.partly_cloudy.test(code)) {97 setToClass(getElement('wicon'), 'partly_cloudy-day');98 setToClass(getElement('bkg-cont'), 'partly_c-d-bkg');99 } else if (cloudCodes.mostly_cloudy.test(code)) {100 setToClass(getElement('wicon'), 'mostly_cloudy-day');101 setToClass(getElement('bkg-cont'), 'mostly_c-d-bkg');102 } else if (weatherCodes.mist_fog.test(code)) {103 setToClass(getElement('wicon'), 'mist_fog-day');104 setToClass(getElement('bkg-cont'), 'mist_f-d-bkg');105 } else if (weatherCodes.frost_snow.test(code)) {106 setToClass(getElement('wicon'), 'frost_snow-day');107 setToClass(getElement('bkg-cont'), 'frost_s-d-bkg');108 } else if (weatherCodes.rain_drizzle.test(code)) {109 setToClass(getElement('wicon'), 'rain_drizzle-day');110 setToClass(getElement('bkg-cont'), 'rain_d-d-bkg');111 } else if (weatherCodes.waterspouts.test(code)) {112 setToClass(getElement('wicon'), 'waterspouts-day');113 setToClass(getElement('bkg-cont'), 'watersp-d-bkg');114 } else {115 setToClass(getElement('wicon'), 'unknown');116 setToClass(getElement('bkg-cont'), 'unknown-bkg');117 }118 } else {119 getElement('main').style.color = '#ccc';120 if (cloudCodes.clear.test(code)) {121 setToClass(getElement('wicon'), 'clear-night');122 setToClass(getElement('bkg-cont'), 'clear-n-bkg');123 } else if (cloudCodes.partly_cloudy.test(code)) {124 setToClass(getElement('wicon'), 'partly_cloudy-night');125 setToClass(getElement('bkg-cont'), 'partly_c-n-bkg');126 } else if (cloudCodes.mostly_cloudy.test(code)) {127 setToClass(getElement('wicon'), 'mostly_cloudy-night');128 setToClass(getElement('bkg-cont'), 'mostly_c-n-bkg');129 } else if (weatherCodes.mist_fog.test(code)) {130 setToClass(getElement('wicon'), 'mist_fog-night');131 setToClass(getElement('bkg-cont'), 'mist_f-n-bkg');132 } else if (weatherCodes.frost_snow.test(code)) {133 setToClass(getElement('wicon'), 'frost_snow-night');134 setToClass(getElement('bkg-cont'), 'frost_s-n-bkg');135 } else if (weatherCodes.rain_drizzle.test(code)) {136 setToClass(getElement('wicon'), 'rain_drizzle-night');137 setToClass(getElement('bkg-cont'), 'rain_d-n-bkg');138 } else if (weatherCodes.waterspouts.test(code)) {139 setToClass(getElement('wicon'), 'waterspouts-night');140 setToClass(getElement('bkg-cont'), 'watersp-n-bkg');141 } else {142 setToClass(getElement('wicon'), 'unknown');143 setToClass(getElement('bkg-cont'), 'unknown-bkg');144 }145 }146}147function setFields() {148 setInner(getElement('main-title'), 'Here\'s your weather!');149 if (getElement('switchCF').checked) {150 setInner(getElement('city-desc'), `${catchData.placeName || 'City'}`);151 setInner(getElement('date-desc'), `Date: ${catchData.dateTimeISO || '--'}`);152 setInner(getElement('weather-desc'), `Weather: ${catchData.weather || '--'}`);153 setInner(getElement('temperature-desc'), `Temperature: ${catchData.tempC || '--'} °C`);154 setInner(getElement('realFeel-desc'), `Real Feel: ${catchData.feelslikeC || '--'} °C`);155 setInner(getElement('windSpeed-desc'), `Wind Speed: ${catchData.windSpeedKPH || '--'} K/Hr`);156 setInner(getElement('humidity-desc'), `Humidity: ${catchData.humidity || '--'}`);157 setInner(getElement('windDirection-desc'), ` Wind direction: ${catchData.windDir || '--'}`);158 } else {159 setInner(getElement('city-desc'), `${catchData.placeName || 'City'}`);160 setInner(getElement('date-desc'), `Date: ${catchData.dateTimeISO || '--'}`);161 setInner(getElement('weather-desc'), `Weather: ${catchData.weather || '--'}`);162 setInner(getElement('temperature-desc'), `Temperature: ${catchData.tempF || '--'} °F`);163 setInner(getElement('realFeel-desc'), `Real Feel: ${catchData.feelslikeF || '--'} °F`);164 setInner(getElement('windSpeed-desc'), `Wind Speed: ${catchData.windSpeedMPH || '--'} Mi/hr`);165 setInner(getElement('humidity-desc'), `Humidity: ${catchData.humidity || '--'}`);166 setInner(getElement('windDirection-desc'), ` Wind direction: ${catchData.windDir || '--'}`);167 }168}169function setIcon(favicon) {170 const head = document.querySelector('head');171 const linkIcon = createElement('link', 'favicon', '', '');172 linkIcon.setAttribute('rel', 'shortcut icon');173 linkIcon.setAttribute('href', favicon);174 appendChild(head, linkIcon);175}176export function createElements() {177 const main = createElement('main', 'bkg-cont', 'init-bkg', '');178 const divPlace = createElement('div', 'divPlace', '', '');179 const place = createElement('input', 'address-input', 'search-place-input', '');180 const card = createElement('div', 'main', 'main-card', '');...
ToetsView.js
Source:ToetsView.js
...3 constructor(toets) {4 this.toets = toets;5 this.toets.addEventListener(ToetsEvent.CHANGED, this.onQuestionsChanged);6 }7 getElement(selector) {8 const element = document.querySelector(selector);9 return element10 }11 onQuestionsChanged = event => {12 this.showQuestion(event.questions[event.current]);13 this.showNav(event.questions[event.current], event.questions);14 };15 bindNextQuestionButton(handler) {16 this.next = this.getElement("#volgende");17 this.next.addEventListener('click', event => {18 handler();19 })20 }21 bindPreviousQuestionButton(handler) {22 this.next = this.getElement("#vorige");23 this.next.addEventListener('click', event => {24 handler();25 })26 }27 bindChoiceButton(handler) {28 this.choices = document.querySelectorAll("#btn1, #btn2, #btn3, #btn4");29 this.choices.forEach(element => element.addEventListener('click', event => {30 handler(element.id);31 }))32 }33 bindSubmitButton(handler) {34 this.submit = this.getElement("#inleveren");35 this.submit.addEventListener('click', event => {36 handler();37 })38 }39 showQuestion(currentQuestion) {40 const question = this.getElement('#vraag');41 question.innerHTML = currentQuestion.getQuestionID() + ". " + currentQuestion.getQuestion();42 this.getElement('#option1').innerHTML = currentQuestion.getOptions()[0];43 this.getElement('#option2').innerHTML = currentQuestion.getOptions()[1];44 this.getElement('#option3').innerHTML = currentQuestion.getOptions()[2];45 this.getElement('#option4').innerHTML = currentQuestion.getOptions()[3];46 this.getElement('#btn1').setAttribute('style', 'background-color:#e6f3ff');47 this.getElement('#btn2').setAttribute('style', 'background-color:#e6f3ff');48 this.getElement('#btn3').setAttribute('style', 'background-color:#e6f3ff');49 this.getElement('#btn4').setAttribute('style', 'background-color:#e6f3ff');50 if (currentQuestion.getGivenAnswer() != -1) {51 let id = '#btn' + currentQuestion.getGivenAnswer();52 this.getElement(id).setAttribute('style', 'background-color:#99ceff')53 }54 }55 showNav(currentQuestion, questions) {56 if (currentQuestion.getQuestionID() > 1) {57 this.getElement('#vorige').setAttribute('style', 'display:block');58 }59 else {60 this.getElement('#vorige').setAttribute('style', 'display:none');61 }62 if (currentQuestion.getQuestionID() < questions.length) {63 this.getElement('#volgende').setAttribute('style', 'display:block');64 }65 else {66 this.getElement('#volgende').setAttribute('style', 'display:none');67 }68 questions.forEach(vraag => {69 if (vraag.getQuestionID() === currentQuestion.getQuestionID()) {70 this.getElement('#no' + currentQuestion.getQuestionID()).style['border'] = '3px solid orange';71 }72 else {73 this.getElement('#no' + vraag.getQuestionID()).style['border'] = '1.5px solid lightskyblue';74 }75 });76 questions.forEach(vraag => {77 if (vraag.getGivenAnswer() !== -1) {78 this.getElement('#no' + vraag.getQuestionID()).style['background-color'] = 'deepskyblue';79 }80 else {81 this.getElement('#no' + vraag.getQuestionID()).style['background-color'] = 'white';82 }83 });84 let aantalIngevuld = 0;85 questions.forEach(vraag => {86 if (vraag.getGivenAnswer() !== -1) {87 aantalIngevuld++;88 }89 });90 if (aantalIngevuld === parseInt(questions.length)) {91 this.getElement('#inleveren').style['display'] = 'block';92 }93 else {94 this.getElement('#inleveren').style['display'] = 'none';95 }96 }97 showResult() {98 let questions = this.toets.getQuestions();99 let contentHTML = this.getElement("#content");100 contentHTML.style['display'] = 'none';101 let result = this.getElement("#resultaat");102 result.style['display'] = 'block';103 let table = document.createElement("table");104 table.style.width = '100%';105 table.setAttribute('border', '1px solid black');106 let thead = table.createTHead();107 let row = thead.insertRow();108 let heads = ["nummer", "vraag", "jouw antwoord", "juiste antwoord", "oordeel"];109 for (let head in heads) {110 let th = document.createElement("th");111 let text = document.createTextNode(heads[head]);112 th.appendChild(text);113 row.appendChild(th);114 }115 for (let question of questions) {...
options.js
Source:options.js
...8 this.node.rule = this;9 rules.appendChild(this.node);10 this.node.hidden = false;11 if (data) {12 this.getElement('matcher').value = data.matcher;13 this.getElement('match-param').value = data.match_param;14 this.getElement('action').value = data.action;15 this.getElement('action-js').value = data.action_js;16 this.getElement('enabled').checked = data.enabled;17 }18 this.getElement('enabled-label').htmlFor = this.getElement('enabled').id =19 this.node.id + '-enabled';20 this.render();21 this.getElement('matcher').onchange = storeRules;22 this.getElement('match-param').onkeyup = storeRules;23 this.getElement('action').onchange = storeRules;24 this.getElement('action-js').onkeyup = storeRules;25 this.getElement('enabled').onchange = storeRules;26 var rule = this;27 this.getElement('move-up').onclick = function() {28 var sib = rule.node.previousSibling;29 rule.node.parentNode.removeChild(rule.node);30 sib.parentNode.insertBefore(rule.node, sib);31 storeRules();32 };33 this.getElement('move-down').onclick = function() {34 var parentNode = rule.node.parentNode;35 var sib = rule.node.nextSibling.nextSibling;36 parentNode.removeChild(rule.node);37 if (sib) {38 parentNode.insertBefore(rule.node, sib);39 } else {40 parentNode.appendChild(rule.node);41 }42 storeRules();43 };44 this.getElement('remove').onclick = function() {45 rule.node.parentNode.removeChild(rule.node);46 storeRules();47 };48 storeRules();49}50Rule.prototype.getElement = function(name) {51 return document.querySelector('#' + this.node.id + ' .' + name);52}53Rule.prototype.render = function() {54 this.getElement('move-up').disabled = !this.node.previousSibling;55 this.getElement('move-down').disabled = !this.node.nextSibling;56 this.getElement('action-js').style.display =57 (this.getElement('action').value == 'js') ? 'block' : 'none';58}59Rule.next_id = 0;60function loadRules() {61 var rules = localStorage.rules;62 try {63 JSON.parse(rules).forEach(function(rule) {new Rule(rule);});64 } catch (e) {65 localStorage.rules = JSON.stringify([]);66 }67}68function storeRules() {69 localStorage.rules = JSON.stringify(Array.prototype.slice.apply(70 document.getElementById('rules').childNodes).map(function(node) {71 node.rule.render();72 return {matcher: node.rule.getElement('matcher').value,73 match_param: node.rule.getElement('match-param').value,74 action: node.rule.getElement('action').value,75 action_js: node.rule.getElement('action-js').value,76 enabled: node.rule.getElement('enabled').checked};77 }));78}79window.onload = function() {80 loadRules();81 document.getElementById('new').onclick = function() {82 new Rule();83 };...
validation.js
Source:validation.js
1function getElement(id){2 return document.getElementById(id);3}4function login_validation()5{6 refreshLog();7 var hasError=false;8 var username=getElement("username");9 var err_username=getElement("err_username");10 var password=getElement("password");11 var err_password=getElement("err_password");12 13 14 15 if(username.value==""){16 hasError=true;17 err_username.innerHTML="*Username Required";18 username.focus();19 return !hasError;20 }21 if(password.value==""){22 hasError=true;23 err_password.innerHTML="*Password Required";24 password.focus();25 return !hasError;26 }27 return !hasError;28}29function student_validation()30{31 refreshReg();32 var hasError=false;33 var name=getElement("name");34 var err_name=getElement("err_name");35 var dob=getElement("dob");36 var err_dob=getElement("err_dob");37 var department=getElement("department_id");38 var err_department=getElement("err_department");39 var credit=getElement("credit");40 var err_credit=getElement("err_credit");41 var cgpa=getElement("cgpa");42 var err_cgpa=getElement("err_cgpa");43 44 45 if(name.value ==""){46 hasError=true;47 err_name.innerHTML="*Name Required";48 name.focus();49 return !hasError;50 }51 else if(name.value.search("1")!=-1 || name.value.search("2")!=-1 || name.value.search("3")!=-1 || name.value.search("4")!=-1 || name.value.search("5")!=-1 || name.value.search("6")!=-1 || name.value.search("7")!=-1 || name.value.search("8")!=-1 || name.value.search("9")!=-1 || name.value.search("0")!=-1){52 hasError=true;53 err_name.innerHTML="*Name cannot contain numbers";54 name.focus();55 return !hasError;56 }57 if(dob.value==""){58 hasError=true;59 err_dob.innerHTML="*DOB Required";60 dob.focus();61 return !hasError;62 }63 if(department.value=="Choose"){64 hasError=true;65 err_department.innerHTML="*Select Department";66 department.focus();67 return !hasError;68 }69 if(credit.value==""){70 hasError=true;71 err_credit.innerHTML="* Credit Required";72 credit.focus();73 return !hasError;74 }75 if(cgpa.value==""){76 hasError=true;77 err_cgpa.innerHTML="*CGPA Required";78 cgpa.focus();79 return !hasError;80 }81 else if(cgpa.value>4 && cgpa.value<0){82 hasError=true;83 err_cgpa.innerHTML="*CGPA Range 0 - 4";84 cgpa.focus();85 return !hasError;86 }87 88 return !hasError; 89 90}91function refreshLog(){92 var err_username = getElement("err_username");93 var err_password = getElement("err_password");94 err_username.innerHTML = "";95 err_password.innerHTML = "";96}97function refreshReg(){98 var err_name = getElement("err_name");99 var err_dob=getElement("err_dob");100 var err_department=getElement("err_department");101 var err_credit=getElement("err_credit");102 var err_cgpa=getElement("err_cgpa");103 104 err_name.innerHTML = "";105 err_dob.innerHTML = "";106 err_department.innerHTML = "";107 err_credit.innerHTML = "";108 err_cgpa.innerHTML = "";...
ui.settings.js
Source:ui.settings.js
1// Muaz Khan - www.MuazKhan.com2// MIT License - www.WebRTC-Experiment.com/licence3// Experiments - github.com/muaz-khan/RTCMultiConnection4var settingsPanel = getElement('.settings-panel');5getElement('#settings').onclick = function() {6 settingsPanel.style.display = 'block';7};8getElement('#save-settings').onclick = function() {9 settingsPanel.style.display = 'none';10 if (!!getElement('#autoTranslateText').checked) {11 rtcMultiConnection.autoTranslateText = true;12 rtcMultiConnection.language = getElement('#language').value;13 } else rtcMultiConnection.autoTranslateText = false;14 rtcMultiConnection.bandwidth.audio = getElement('#audio-bandwidth').value;15 rtcMultiConnection.bandwidth.video = getElement('#video-bandwidth').value;16 rtcMultiConnection.sdpConstraints.mandatory = {17 OfferToReceiveAudio: !!getElement('#OfferToReceiveAudio').checked,18 OfferToReceiveVideo: !!getElement('#OfferToReceiveVideo').checked,19 IceRestart: !!getElement('#IceRestart').checked20 };21 var videWidth = getElement('#video-width').value;22 var videHeight = getElement('#video-height').value;23 rtcMultiConnection.mediaConstraints.mandatory = {24 minWidth: videWidth,25 maxWidth: videWidth,26 minHeight: videHeight,27 maxHeight: videHeight28 };29 rtcMultiConnection.preferSCTP = !!getElement('#prefer-sctp').checked;30 rtcMultiConnection.chunkSize = +getElement('#chunk-size').value;31 rtcMultiConnection.chunkInterval = +getElement('#chunk-interval').value;32 window.enableLogs = !getElement('#skip-RTCMultiConnection-Logs').checked;33 //rtcMultiConnection.selectDevices(getElement('#audio-devices').value, getElement('#video-devices').value);34 rtcMultiConnection.maxParticipantsAllowed = getElement('#max-participants-allowed').value;35 rtcMultiConnection.candidates = {36 relay: getElement('#prefer-stun').checked,37 reflexive: getElement('#prefer-turn').checked,38 host: getElement('#prefer-host').checked39 };40 rtcMultiConnection.dataChannelDict = eval('(' + getElement('#dataChannelDict').value + ')');41 if (!!getElement('#fake-pee-connection').checked) {42 // http://www.rtcmulticonnection.org/docs/fakeDataChannels/43 rtcMultiConnection.fakeDataChannels = true;44 rtcMultiConnection.session = { };45 }46 ;47};48var audioDeviecs = getElement('#audio-devices');49var videoDeviecs = getElement('#video-devices');50rtcMultiConnection.DetectRTC.load(function() {51 rtcMultiConnection.DetectRTC.MediaDevices.forEach(function(device) {52 appendDevice(device);53 });54});55function appendDevice(device) {56 var option = document.createElement('option');57 option.value = device.id;58 option.innerHTML = device.label || device.id;59 if (device.kind == 'audio') {60 audioDeviecs.appendChild(option);61 } else videoDeviecs.appendChild(option);...
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var By = webdriver.By;3var until = webdriver.until;4var driver = new webdriver.Builder()5 .forBrowser('chrome')6 .build();7driver.findElement(By.name('q')).sendKeys('webdriver');8driver.findElement(By.name('btnG')).click();9driver.wait(until.titleIs('webdriver - Google Search'), 1000);10driver.quit();
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2 withCapabilities({3 build();4driver.findElement(webdriver.By.id('lst-ib')).sendKeys('webdriver');5driver.findElement(webdriver.By.name('btnG')).click();6driver.wait(function() {7 return driver.getTitle().then(function(title) {8 return title === 'webdriver - Google Search';9 });10}, 1000);11var webdriver = require('selenium-webdriver');12 withCapabilities({13 build();14driver.findElement(webdriver.By.id('lst-ib')).sendKeys('webdriver');15driver.findElement(webdriver.By.name('btnG')).click();16driver.wait(function() {17 return driver.getTitle().then(function(title) {18 return title === 'webdriver - Google Search';19 });20}, 1000);21var webdriver = require('selenium-webdriver');22 withCapabilities({23 build();24driver.findElement(webdriver.By.id('lst-ib')).sendKeys('webdriver');25driver.findElement(webdriver.By.name('btnG')).click();26driver.wait(function() {
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.android()).build();3driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');4driver.findElement(webdriver.By.name('btnG')).click();5driver.wait(function() {6 return driver.getTitle().then(function(title) {7 return title === 'webdriver - Google Search';8 });9}, 1000);10driver.quit();11var webdriver = require('selenium-webdriver');12var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.iphone()).build();13driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');14driver.findElement(webdriver.By.name('btnG')).click();15driver.wait(function() {16 return driver.getTitle().then(function(title) {17 return title === 'webdriver - Google Search';18 });19}, 1000);20driver.quit();
Using AI Code Generation
1var By = require('selenium-webdriver').By;2var driver = new webdriver.Builder()3 .forBrowser('chrome')4 .build();5driver.findElement(By.id('lst-ib')).sendKeys('webdriver');6driver.findElement(By.name('btnG')).click();7driver.wait(function() {8 return driver.getTitle().then(function(title) {9 return title === 'webdriver - Google Search';10 });11}, 1000);12var AppiumDriver = require('webdriver-appium').AppiumDriver;13var driver = new AppiumDriver();14driver.findElements('id', 'lst-ib', function(err, elements) {15 if (err) {16 console.log(err);17 } else {18 console.log(elements);19 }20});21var By = require('selenium-webdriver').By;22var driver = new webdriver.Builder()23 .forBrowser('chrome')24 .build();25driver.findElement(By.id('lst-ib')).sendKeys('webdriver');26driver.findElement(By.name('btnG')).click();27driver.wait(function() {28 return driver.getTitle().then(function(title) {29 return title === 'webdriver - Google Search';30 });31}, 1000);32var SeleniumDriver = require('webdriver-appium').SeleniumDriver;33var driver = new SeleniumDriver();34driver.findElements('id', 'lst-ib', function(err, elements) {35 if (err) {36 console.log(err);37 } else {38 console.log(elements);39 }40});41var By = require('selenium-webdriver').By;42var driver = new webdriver.Builder()43 .forBrowser('chrome')44 .build();45driver.findElement(By.id('lst-ib')).sendKeys('webdriver');46driver.findElement(By.name('btnG')).click();47driver.wait(function() {48 return driver.getTitle().then(function(title) {49 return title === 'webdriver - Google Search';50 });51}, 1000);52var SeleniumDriver = require('webdriver-appium').SeleniumDriver;53var driver = new SeleniumDriver();54driver.findElements('id', 'lst-
Using AI Code Generation
1var driver = new AndroidDriver();2element.click();3var driver = new AndroidDriver();4element.click();5var driver = new AndroidDriver();6elements[0].click();7var driver = new AndroidDriver();8element.click();9var driver = new AndroidDriver();10elements[0].click();11var driver = new AndroidDriver();12var element = driver.findElementByAccessibilityId("Contacts");13element.click();14var driver = new AndroidDriver();15var elements = driver.findElementsByAccessibilityId("Contacts");16elements[0].click();17var driver = new AndroidDriver();18var element = driver.findElementByAndroidUIAutomator("new UiSelector().text(\"Contacts\")");19element.click();20var driver = new AndroidDriver();21var elements = driver.findElementsByAndroidUIAutomator("new UiSelector().text(\"Contacts\")");22elements[0].click();23var driver = new AndroidDriver();24var element = driver.findElementByClassName("android.widget.TextView");25element.click();26var driver = new AndroidDriver();27var elements = driver.findElementsByClassName("android
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var desired = require('./desired');3var driver = new webdriver.Builder()4 .withCapabilities(desired)5 .build();6driver.findElement(webdriver.By.id("com.android.calculator2:id/digit_2")).click();7driver.findElement(webdriver.By.id("com.android.calculator2:id/digit_3")).click();8driver.findElement(webdriver.By.id("com.android.calculator2:id/digit_4")).click();9driver.findElement(webdriver.By.id("com.android.calculator2:id/digit_5")).click();10driver.findElement(webdriver.By.id("com.android.calculator2:id/digit_6")).click();11driver.findElement(webdriver.By.name("2")).click();12driver.findElement(webdriver.By.name("3")).click();13driver.findElement(webdriver.By.name("4")).click();14driver.findElement(webdriver.By.name("5")).click();15driver.findElement(webdriver.By.name("6")).click();16driver.findElement(webdriver.By.className("android.widget.Button")).click();
Using AI Code Generation
1var AndroidDriver = require('appium-android-driver');2var driver = new AndroidDriver();3driver.findElementById('com.android.calculator2:id/digit_1').click();4driver.findElementById('com.android.calculator2:id/digit_5').click();5driver.findElementById('com.android.calculator2:id/digit_9').click();6driver.findElementById('com.android.calculator2:id/digit_2').click();7driver.findElementById('com.android.calculator2:id/op_add').click();8driver.findElementById('com.android.calculator2:id/digit_6').click();9driver.findElementById('com.android.calculator2:id/digit_3').click();10driver.findElementById('com.android.calculator2:id/digit_4').click();11driver.findElementById('com.android.calculator2:id/digit_5').click();12driver.findElementById('com.android.calculator2:id/eq').click();13driver.quit();14var IOSDriver = require('appium-ios-driver');15var driver = new IOSDriver();16driver.findElementById('com.apple.calculator:id/digit_1').click();17driver.findElementById('com.apple.calculator:id/digit_5').click();18driver.findElementById('com.apple.calculator:id/digit_9').click();19driver.findElementById('com.apple.calculator:id/digit_2').click();20driver.findElementById('com.apple.calculator:id/op_add').click();21driver.findElementById('com.apple.calculator:id/digit_6').click();22driver.findElementById('com.apple.calculator:id/digit_3').click();23driver.findElementById('com.apple.calculator:id/digit_4').click();24driver.findElementById('
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!!