Best JavaScript code snippet using testcafe
xml-parser-ui.js
Source:xml-parser-ui.js
1/*2Copyright 2011, Google Inc.3All rights reserved.4Redistribution and use in source and binary forms, with or without5modification, are permitted provided that the following conditions are6met:7 * Redistributions of source code must retain the above copyright8notice, this list of conditions and the following disclaimer.9 * Redistributions in binary form must reproduce the above10copyright notice, this list of conditions and the following disclaimer11in the documentation and/or other materials provided with the12distribution.13 * Neither the name of Google Inc. nor the names of its14contributors may be used to endorse or promote products derived from15this software without specific prior written permission.16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS17"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT18LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR19A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT20OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,21SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT22LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT25(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE26OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.27 */28Refine.XmlParserUI = function(controller, jobID, job, format, config,29 dataContainerElmt, progressContainerElmt, optionContainerElmt) {30 this._controller = controller;31 this._jobID = jobID;32 this._job = job;33 this._format = format;34 this._config = config;35 this._dataContainer = dataContainerElmt;36 this._progressContainer = progressContainerElmt;37 this._optionContainer = optionContainerElmt;38 this._timerID = null;39 this._initialize();40 this._showPickRecordElementsUI();41};42Refine.DefaultImportingController.parserUIs.XmlParserUI = Refine.XmlParserUI;43Refine.XmlParserUI.prototype.dispose = function() {44 if (this._timerID !== null) {45 window.clearTimeout(this._timerID);46 this._timerID = null;47 }48};49Refine.XmlParserUI.prototype.confirmReadyToCreateProject = function() {50 if ((this._config.recordPath) && this._config.recordPath.length > 0) {51 return true;52 } else {53 window.alert('Please specify a record path first.');54 }55};56Refine.XmlParserUI.prototype.getOptions = function() {57 var options = {58 recordPath: this._config.recordPath59 };60 var parseIntDefault = function(s, def) {61 try {62 var n = parseInt(s,10);63 if (!isNaN(n)) {64 return n;65 }66 } catch (e) {67 // Ignore68 }69 return def;70 };71 if (this._optionContainerElmts.limitCheckbox[0].checked) {72 options.limit = parseIntDefault(this._optionContainerElmts.limitInput[0].value, -1);73 } else {74 options.limit = -1;75 }76 options.trimStrings = this._optionContainerElmts.trimStringsCheckbox[0].checked;77 options.guessCellValueTypes = this._optionContainerElmts.guessCellValueTypesCheckbox[0].checked;78 options.storeEmptyStrings = this._optionContainerElmts.storeEmptyStringsCheckbox[0].checked;79 options.includeFileSources = this._optionContainerElmts.includeFileSourcesCheckbox[0].checked;80 return options;81};82Refine.XmlParserUI.prototype._initialize = function() {83 var self = this;84 this._optionContainer.unbind().empty().html(85 DOM.loadHTML("core", "scripts/index/parser-interfaces/xml-parser-ui.html"));86 this._optionContainerElmts = DOM.bind(this._optionContainer);87 this._optionContainerElmts.previewButton.click(function() { self._updatePreview(); });88 if (this._config.limit > 0) {89 this._optionContainerElmts.limitCheckbox.attr("checked", "checked");90 this._optionContainerElmts.limitInput[0].value = this._config.limit.toString();91 }92 if (this._config.trimStrings) {93 this._optionContainerElmts.trimStringsCheckbox.attr("checked", "checked");94 }95 if (this._config.guessCellValueTypes) {96 this._optionContainerElmts.guessCellValueTypesCheckbox.attr("checked", "checked");97 }98 if (this._config.storeEmptyStrings) {99 this._optionContainerElmts.storeEmptyStringsCheckbox.attr("checked", "checked");100 }101 if (this._config.includeFileSources) {102 this._optionContainerElmts.includeFileSourcesCheckbox.attr("checked", "checked");103 }104 this._optionContainerElmts.pickRecordElementsButton.click(function() {105 self._showPickRecordElementsUI();106 });107 var onChange = function() {108 self._scheduleUpdatePreview();109 };110 this._optionContainer.find("input").bind("change", onChange);111 this._optionContainer.find("select").bind("change", onChange);112};113Refine.XmlParserUI.prototype._showPickRecordElementsUI = function() {114 var self = this;115 this._dataContainer.unbind().empty().html(116 DOM.loadHTML("core", "scripts/index/parser-interfaces/xml-parser-select-ui.html"));117 var elmts = DOM.bind(this._dataContainer);118 var escapeElmt = $('<span>');119 var escapeHtml = function(s) {120 escapeElmt.empty().text(s);121 return escapeElmt.html();122 };123 var textAsHtml = function(s) {124 s = s.length <= 200 ? s : (s.substring(0, 200) + ' ...');125 return '<span class="text">' + escapeHtml(s) + '</span>';126 };127 var renderNode = function(node, container, parentPath) {128 if (node.t) {129 $('<div>').html(textAsHtml(node.t)).appendTo(container);130 } else {131 var qname = node.n;132 if (node.p) {133 qname = node.p + ':' + qname;134 }135 var t = qname;136 if (node.a) {137 t += ' ' + $.map(node.a, function(attr) {138 return attr.n + '="' + attr.v + '"';139 }).join(' ');140 }141 if (node.ns) {142 t += ' ' + $.map(node.ns, function(ns) {143 return 'xmlns' + ((ns.p) ? (':' + ns.p) : '') + '="' + ns.uri + '"';144 }).join(' ');145 }146 var path = [].concat(parentPath);147 path.push(qname);148 var div = $('<div>').addClass('elmt').appendTo(container);149 var hasSelectableChildren = false;150 var hotspot;151 if (node.c) {152 if (node.c.length == 1 && (node.c[0].t)) {153 $('<span>').html('<' + t + '>' + textAsHtml(node.c[0].t) + '</' + qname + '>').appendTo(div);154 } else {155 $('<div>').text('<' + t + '>').appendTo(div);156 var divChildren = $('<div>').addClass('children').appendTo(div);157 $.each(node.c, function() {158 renderNode(this, divChildren, path);159 });160 $('<div>').text('</' + qname + '>').appendTo(div);161 hasSelectableChildren = true;162 }163 } else {164 $('<span>').text('<' + t + ' />').appendTo(div);165 }166 var hittest = function(evt) {167 if (hasSelectableChildren) {168 if (evt.target !== div[0] &&169 (evt.target.className == 'elmt' || evt.target.parentNode !== div[0])) {170 return false;171 }172 }173 return true;174 };175 div.attr('title', '/' + path.join('/'))176 .bind('mouseover', function(evt) {177 if (hittest(evt)) {178 elmts.domContainer.find('.highlight').removeClass('highlight');179 div.addClass('highlight');180 }181 })182 .bind('mouseout', function(evt) {183 div.removeClass('highlight');184 })185 .click(function(evt) {186 if (hittest(evt)) {187 self._setRecordPath(path);188 }189 });190 }191 };192 if (this._config.dom) {193 renderNode(this._config.dom, elmts.domContainer, []);194 }195};196Refine.XmlParserUI.prototype._scheduleUpdatePreview = function() {197 if (this._timerID !== null) {198 window.clearTimeout(this._timerID);199 this._timerID = null;200 }201 var self = this;202 this._timerID = window.setTimeout(function() {203 self._timerID = null;204 self._updatePreview();205 }, 500); // 0.5 second206};207Refine.XmlParserUI.prototype._setRecordPath = function(path) {208 this._config.recordPath = path;209 this._updatePreview();210};211Refine.XmlParserUI.prototype._updatePreview = function() {212 var self = this;213 this._progressContainer.show();214 var options = this.getOptions();215 // for preview, we need exact text, so it's easier to show where the columns are split216 options.guessCellValueTypes = false;217 this._controller.updateFormatAndOptions(options, function(result) {218 if (result.status == "ok") {219 self._controller.getPreviewData(function(projectData) {220 self._progressContainer.hide();221 new Refine.PreviewTable(projectData, self._dataContainer.unbind().empty());222 }, 20);223 }224 });...
Using AI Code Generation
1import { Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#submit-button');5 .expect(Selector('#article-header').hasSelectableChildren).ok();6});7Selector().hasVisibleChild()8import { Selector } from 'testcafe';9test('My first test', async t => {10 .typeText('#developer-name', 'John Smith')11 .click('#submit-button');12 .expect(Selector('#article-header').hasVisibleChild).ok();13});14Selector().hasAttribute(attributeName)15import { Selector } from 'testcafe';16test('My first test', async t => {17 .typeText('#developer-name', 'John Smith')18 .click('#submit-button');19 .expect(Selector('#article-header').hasAttribute('id')).ok();20});21Selector().hasClass(className)
Using AI Code Generation
1import { Selector } from 'testcafe';2test('My test', async t => {3 const select = Selector('#preferred-interface');4 const option = select.find('option');5 const hasChildren = await option.hasSelectableChildren;6 await t.expect(hasChildren).ok();7});8import { Selector } from 'testcafe';9test('My test', async t => {10 const select = Selector('#preferred-interface');11 const option = select.find('option');12 const hasChildren = await option.hasChildNodes;13 await t.expect(hasChildren).ok();14});15import { Selector } from 'testcafe';16test('My test', async t => {17 const select = Selector('#preferred-interface');18 const option = select.find('option');19 const hasChildren = await option.hasAttributes;20 await t.expect(hasChildren).ok();21});22import { Selector } from 'testcafe';23test('My test', async t => {24 const select = Selector('#preferred-interface');25 const option = select.find('option');26 const hasChildren = await option.hasAttribute('id');27 await t.expect(hasChildren).ok();28});29import { Selector } from 'testcafe';30test('My test', async t => {31 const select = Selector('#preferred-interface');32 const option = select.find('option');33 const hasChildren = await option.hasClass('class1');34 await t.expect(hasChildren).ok();35});36import { Selector } from 'testcafe';
Using AI Code Generation
1import { Selector } from 'testcafe';2test('My test', async t => {3 const selectCountry = Selector('#preferred-interface');4 const option = selectCountry.find('option');5 .expect(selectCountry.hasSelectableChildren).ok()6 .expect(option.count).eql(9)7 .click(selectCountry)8 .click(option.withText('Both'));9});10import { Selector } from 'testcafe';11test('My test', async t => {12 const selectCountry = Selector('#preferred-interface');13 const option = selectCountry.find('option');14 .expect(selectCountry.hasSelectableChildren).ok()15 .expect(option.count).eql(9)16 .click(selectCountry)17 .click(option.withText('Both'))18 .expect(selectCountry.value).eql('Both');19});20 at Object.<anonymous> (test.js:12:14)21 at Object.<anonymous> (test.js:13:14)22 at Object.<anonymous> (test.js:14:14)23 at Object.<anonymous> (test.js:15:14)24 at Object.<anonymous> (test.js:16:14)
Using AI Code Generation
1import { Selector } from 'testcafe';2test('My first test', async t => {3 const select = Selector('select');4 const option = select.find('option');5 .expect(select.hasSelectableChildren).ok()6 .expect(option.hasSelectableChildren).notOk();7});8import { Selector } from 'testcafe';9test('My first test', async t => {10 const select = Selector('select');11 const option = select.find('option');12 .expect(select.hasSelectableChildren).ok()13 .expect(option.hasSelectableChildren).notOk();14});15import { Selector } from 'testcafe';16test('My first test', async t => {17 const select = Selector('select');18 const option = select.find('option');19 .expect(select.hasSelectableChildren).ok()20 .expect(option.hasSelectableChildren).notOk();21});
Using AI Code Generation
1import { Selector } from 'testcafe';2test('My Test', async t => {3 const hasChildren = Selector('#tried-test-cafe').hasSelectableChildren;4 await t.expect(hasChildren).ok();5});6import { Selector } from 'testcafe';7test('My Test', async t => {8 const hasChildren = Selector('#tried-test-cafe').hasSelectableChildren();9 await t.expect(hasChildren).ok();10});
Using AI Code Generation
1import { Selector } from 'testcafe';2test('My first test', async t => {3 .click(Selector('div').withText('Test1'))4 .click(Selector('div').withText('Test2'))5 .click(Selector('div').withText('Test3'))6 .click(Selector('div').withText('Test4'))7 .click(Selector('div').withText('Test5'))8 .click(Selector('div').withText('Test6'))9 .click(Selector('div').withText('Test7'))10 .click(Selector('div').withText('Test8'))11 .click(Selector('div').withText('Test9'))12 .click(Selector('div').withText('Test10'))13 .click(Selector('div').withText('Test11'))14 .click(Selector('div').withText('Test12'))15 .click(Selector('div').withText('Test13'))16 .click(Selector('div').withText('Test14'))17 .click(Selector('div').withText('Test15'))18 .click(Selector('div').withText('Test16'))19 .click(Selector('div').withText('Test17'))20 .click(Selector('div').withText('Test18'))21 .click(Selector('div').withText('Test19'))22 .click(Selector('div').withText('Test20'))23 .click(Selector('div').withText('Test21'))24 .click(Selector('div').withText('Test22'))25 .click(Selector('div').withText('Test23'))26 .click(Selector('div').withText('Test24'))27 .click(Selector('div').withText('Test25'))28 .click(Selector('div').withText('Test26'))29 .click(Selector('div').withText('Test27'))30 .click(Selector('div').withText('Test28'))31 .click(Selector('div').withText('Test29'))32 .click(Selector('div').withText('Test30'))33 .click(Selector('div').withText('Test31'))34 .click(Selector('div').withText('Test32'))35 .click(Selector('div').with
Using AI Code Generation
1import { Selector } from 'testcafe';2test('My first test', async t => {3 const searchBox = Selector('input').withAttribute('title', 'Search');4 const searchButton = Selector('input').withAttribute('value', 'Google Search');5 const searchResults = Selector('div').withAttribute('role', 'heading');6 .typeText(searchBox, 'Testcafe')7 .click(searchButton)8 .expect(searchResults.count).eql(10)9 .expect(searchResults.nth(0).innerText).contains('TestCafe')10 .expect(searchResults.nth(0).hasSelectableChildren).ok();11});12import { Selector } from 'testcafe';13test('My first test', async t => {14 const searchBox = Selector('input').withAttribute('title', 'Search');15 const searchButton = Selector('input').withAttribute('value', 'Google Search');16 const searchResults = Selector('div').withAttribute('role', 'heading');17 .typeText(searchBox, 'Testcafe')18 .click(searchButton)19 .expect(searchResults.count).eql(10)20 .expect(searchResults.nth(0).innerText).contains('TestCafe')21 .expect(searchResults.nth(0).hasSelectableChildren).ok();22});23import { Selector } from 'testcafe';24test('My first test', async t => {25 const searchBox = Selector('input').withAttribute('title
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!!