Best JavaScript code snippet using testcafe
RESTWorkerController.js
Source:RESTWorkerController.js
...4(function(Platform) {"use strict";5 var CannotLocateResourceError = {6 description: AppMagic.Strings.CannotLocateResourceErrorDescription, message: AppMagic.Strings.CannotLocateResourceErrorMessage, number: -21466972117 };8 function areErrorsSame(err0, err1) {9 return err0.description === err1.description && err0.message === err1.message && err0.number === err1.number10 }11 var ComplexTypeArray = AppMagic.Schema.TypeArray,12 ComplexTypeObject = AppMagic.Schema.TypeObject,13 AcceptedComplexTypes = [ComplexTypeArray, ComplexTypeObject],14 DTypeMap = {15 boolean: AppMagic.Schema.TypeBoolean, color: "c", currency: "$", date: "d", hyperlink: "h", image: AppMagic.Schema.TypeImage, number: AppMagic.Schema.TypeNumber, media: AppMagic.Schema.TypeMedia, string: AppMagic.Schema.TypeString16 },17 SupportedResponseDTypes = [AppMagic.Schema.TypeBoolean, AppMagic.Schema.TypeNumber, AppMagic.Schema.TypeString, ],18 ForbiddenTypeNames = Object.keys(DTypeMap);19 ForbiddenTypeNames.unshift("");20 var ForbiddenFieldNames = ["", "_id", AppMagic.Constants.Services.SpIdProperty],21 ForbiddenParameterNames = [""],22 OAuthTokenParamReplacementToken = "{access_token}",...
lxq.main.js
Source:lxq.main.js
1/* global LXQ */2/*3 Component: lxq.main4 */5const LXQ = {6 enabled: function () {7 return !!config.lxq_enabled8 },9 enable: function () {10 if (!config.lxq_enabled) {11 config.lxq_enabled = 112 // Todo Call Service to enable Tag Lexiqa13 var path = sprintf(14 APP.getRandomUrl() + 'api/v2/jobs/%s/%s/options',15 config.id_job,16 config.password,17 )18 var data = {19 lexiqa: true,20 }21 $.ajax({22 url: path,23 type: 'POST',24 data: data,25 xhrFields: {withCredentials: true},26 }).done(function (data) {27 if (!LXQ.initialized) {28 LXQ.init()29 } else {30 SegmentActions.qaComponentsetLxqIssues(LXQ.lexiqaData.segments)31 }32 UI.render()33 })34 }35 },36 disable: function () {37 if (config.lxq_enabled) {38 config.lxq_enabled = 039 var path = sprintf(40 APP.getRandomUrl() + 'api/v2/jobs/%s/%s/options',41 config.id_job,42 config.password,43 )44 var data = {45 lexiqa: false,46 }47 $.ajax({48 url: path,49 type: 'POST',50 data: data,51 xhrFields: {withCredentials: true},52 }).done(function (data) {53 UI.render()54 SegmentActions.qaComponentsetLxqIssues([])55 })56 }57 },58 checkCanActivate: function () {59 if (_.isUndefined(this.canActivate)) {60 this.canActivate =61 config.lexiqa_languages.indexOf(config.source_rfc) > -1 &&62 config.lexiqa_languages.indexOf(config.target_rfc) > -163 }64 return this.canActivate65 },66 lexiqaData: {67 lexiqaWarnings: {},68 enableHighlighting: true,69 lexiqaFetching: false,70 segments: [],71 segmentsInfo: {},72 },73 getTargetTextForQa: function (segment) {74 let clone = $(UI.targetContainerSelector(), segment).clone()75 return clone.text().replace(/\uFEFF/g, '')76 },77 getSourceTextForQa: function (text) {78 var div = document.createElement('div')79 var $div = $(div)80 $div.html(text)81 return $div.text()82 },83 doLexiQA: function (segment, isSegmentCompleted, callback) {84 if (!LXQ.enabled()) {85 if (callback !== undefined && typeof callback === 'function') {86 callback()87 }88 return89 }90 let id_segment = segment.sid91 var segObj = segment92 if (!segObj) return93 var sourcetext = segObj.lxqDecodedSource94 var translation = segObj.lxqDecodedTranslation95 var returnUrl = window.location.href.split('#')[0] + '#' + id_segment96 $.lexiqaAuthenticator.doLexiQA(97 {98 sourcelanguage: config.source_rfc,99 targetlanguage: config.target_rfc,100 sourcetext: sourcetext,101 targettext: translation,102 returnUrl: returnUrl,103 segmentId: id_segment,104 partnerId: LXQ.partnerid,105 projectId: LXQ.projectid,106 isSegmentCompleted: isSegmentCompleted,107 responseMode: 'includeQAResults',108 },109 function (err, result) {110 if (!err) {111 var noVisibleErrorsFound = false,112 source_val,113 target_val114 if (result.hasOwnProperty('qaData') && result.qaData.length > 0) {115 //highlight the segments116 // source_val = $( ".source", segment ).html();117 var highlights = {}118 var errorsMap = {119 numbers: [],120 punctuation: [],121 spaces: [],122 urls: [],123 spelling: [],124 specialchardetect: [],125 mspolicheck: [],126 glossary: [],127 blacklist: [],128 }129 var newWarnings = {}130 newWarnings[id_segment] = {}131 result.qaData.forEach(function (qadata) {132 if (133 LXQ.lexiqaData.lexiqaWarnings.hasOwnProperty(id_segment) &&134 LXQ.lexiqaData.lexiqaWarnings[id_segment].hasOwnProperty(135 qadata.errorid,136 )137 ) {138 //this error is already here, update it139 //basically do thing because each error is unique....140 qadata.ignored =141 LXQ.lexiqaData.lexiqaWarnings[id_segment][142 qadata.errorid143 ].ignored144 }145 newWarnings[id_segment][qadata.errorid] = qadata146 if (!qadata.ignored) {147 qadata.color = LXQ.colors[qadata.category]148 var category = qadata.category149 if (qadata.insource) {150 highlights.source = highlights.source151 ? highlights.source152 : _.cloneDeep(errorsMap)153 highlights.source[category].push(qadata)154 } else {155 highlights.target = highlights.target156 ? highlights.target157 : _.cloneDeep(errorsMap)158 highlights.target[category].push(qadata)159 }160 }161 })162 LXQ.lexiqaData.lexiqaWarnings[id_segment] = newWarnings[id_segment]163 //do something here -- enable qa errors164 if (LXQ.lexiqaData.segments.indexOf(id_segment) < 0) {165 LXQ.lexiqaData.segments.push(id_segment)166 LXQ.updateWarningsUI()167 }168 SegmentActions.addLexiqaHighlight(id_segment, highlights)169 if (!(LXQ.getVisibleWarningsCountForSegment(id_segment) > 0)) {170 noVisibleErrorsFound = true171 }172 } else {173 //do something else174 noVisibleErrorsFound = true175 if (callback != null) callback()176 }177 if (noVisibleErrorsFound) {178 LXQ.lxqRemoveSegmentFromWarningList(id_segment)179 }180 } //there was no error181 else {182 if (callback != null) callback()183 } //error in doQA184 }, //end lexiqaAuthenticator callback185 ) //end lexiqaAuthenticator.doLexiqa186 },187 lxqRemoveSegmentFromWarningList: function (id_segment) {188 SegmentActions.addLexiqaHighlight(id_segment, {})189 LXQ.removeSegmentWarning(id_segment)190 },191 getLexiqaWarnings: function (callback) {192 if (!LXQ.enabled()) {193 if (callback) callback()194 return195 }196 //FOTD197 LXQ.lexiqaData.lexiqaFetching = true198 $.ajax({199 type: 'GET',200 url: config.lexiqaServer + '/matecaterrors',201 data: {id: LXQ.partnerid + '-' + config.id_job + '-' + config.password},202 cache: false,203 success: function (results) {204 var errorCnt = 0,205 ind206 if (results.errors != 0) {207 //only do something if there are errors in lexiqa server208 LXQ.lexiqaData.lexiqaWarnings = {}209 results.segments.forEach(function (element) {210 LXQ.lexiqaData.segments.push(element.segid)211 if (element.errornum === 0) {212 return213 }214 //highlight the respective segments here215 var highlights = {}216 var errorsMap = {217 numbers: [],218 punctuation: [],219 spaces: [],220 urls: [],221 spelling: [],222 specialchardetect: [],223 mspolicheck: [],224 glossary: [],225 blacklist: [],226 }227 let seg = SegmentStore.getSegmentByIdToJS(element.segid)228 if (!seg) return229 LXQ.lexiqaData.lexiqaWarnings[element.segid] = {}230 results.results[element.segid].forEach(function (qadata) {231 LXQ.lexiqaData.lexiqaWarnings[element.segid][232 qadata.errorid233 ] = qadata234 if (!qadata.ignored) {235 qadata.color = LXQ.colors[qadata.category]236 if (qadata.insource) {237 highlights.source = highlights.source238 ? highlights.source239 : _.cloneDeep(errorsMap)240 highlights.source[qadata.category].push(qadata)241 } else {242 highlights.target = highlights.target243 ? highlights.target244 : _.cloneDeep(errorsMap)245 highlights.target[qadata.category].push(qadata)246 }247 }248 })249 if (!LXQ.getVisibleWarningsCountForSegment(element.segid) > 0) {250 LXQ.removeSegmentWarning(element.segid)251 }252 SegmentActions.addLexiqaHighlight(element.segid, highlights)253 })254 LXQ.updateWarningsUI()255 }256 if (LXQ.enabled()) {257 LXQ.doQAallSegments()258 //LXQ.refreshElements();259 }260 LXQ.lexiqaData.lexiqaFetching = false261 if (callback) callback()262 },263 })264 },265 updateWarningsUI: function () {266 LXQ.lexiqaData.segments.sort()267 var segments = LXQ.lexiqaData.segments.filter(function (id_segment) {268 return LXQ.lexiqaData.lexiqaWarnings.hasOwnProperty(id_segment)269 })270 SegmentActions.qaComponentsetLxqIssues(segments)271 },272 removeSegmentWarning: function (idSegment) {273 let ind = LXQ.lexiqaData.segments.indexOf(idSegment)274 if (ind >= 0) {275 LXQ.lexiqaData.segments.splice(ind, 1)276 delete LXQ.lexiqaData.lexiqaWarnings[idSegment]277 this.updateWarningsUI()278 }279 },280}281LXQ.init = function () {282 LXQ.initialized = true283 var globalReceived = false284 if (config.lxq_license && $.lexiqaAuthenticator) {285 $.lexiqaAuthenticator.init({286 licenseKey: config.lxq_license,287 partnerId: config.lxq_partnerid,288 lxqServer: config.lexiqaServer,289 projectId: config.id_job + '-' + config.password,290 })291 } else {292 config.lxq_enabled = false293 }294 /*295 * Add lexiQA event handlers for warnings events296 */297 $(document).on('getWarning:local:success', function (e, data) {298 LXQ.doLexiQA(data.segment, false, function () {})299 })300 /* Invoked when page loads */301 $(document).on('getWarning:global:success', function (e, data) {302 if (globalReceived) {303 return304 }305 LXQ.getLexiqaWarnings(function () {306 globalReceived = true307 })308 })309 /* invoked when segment is completed (translated clicked)*/310 $(document).on('setTranslation:success', function (e, data) {311 LXQ.doLexiQA(data.segment, true, null)312 })313 /* invoked when more segments are loaded...*/314 $(window).on('segmentsAdded', function (e, data) {315 globalReceived = false316 console.log('[LEXIQA] got segmentsAdded ')317 _.each(data.resp, function (file, id) {318 if (319 file.segments &&320 LXQ.hasOwnProperty('lexiqaData') &&321 LXQ.lexiqaData.hasOwnProperty('lexiqaWarnings')322 ) {323 _.each(file.segments, function (segment, i) {324 if (LXQ.lexiqaData.lexiqaWarnings.hasOwnProperty(segment.sid)) {325 // console.log('in loadmore segments, segment: '+segment.sid+' already has qa info...');326 //clean up and redo powertip on any glossaries/blacklists327 LXQ.redoHighlighting(segment.sid, true)328 LXQ.redoHighlighting(segment.sid, false)329 }330 })331 }332 })333 })334 return (function ($, config, window, LXQ, undefined) {335 var partnerid = config.lxq_partnerid336 var colors = {337 numbers: '#D08053',338 punctuation: '#3AB45F',339 spaces: '#3AB45F',340 urls: '#b8a300',341 spelling: '#563d7c',342 specialchardetect: '#38C0C5',343 mspolicheck: '#38C0C5',344 multiple: '#EA92B8',345 glossary: '#EA92B8',346 blacklist: '#EA92B8',347 }348 var warningMessages = {349 u2: {t: 'email not found in source', s: 'email missing from target'},350 u1: {t: 'url not found in source', s: 'url missing from target'},351 n1: {t: 'index not found in source', s: 'index missing from target'},352 n2: {t: 'number not found in source', s: 'number missing from target'},353 n3: {354 t: 'phonenumber not found in source',355 s: 'phonenumber missing from target',356 },357 n4: {t: 'date not found in source', s: 'date missing from target'},358 s1: {359 t: 'placeholder not found in source',360 s: 'placeholder missing from target',361 },362 p1: {t: 'consecutive punctuation marks', s: ''},363 p2: {t: 'space before punctuation mark', s: ''},364 p2sub1: {t: 'space before punctuation mark missing', s: ''},365 p2sub2: {t: 'no space before opening parenthesis', s: ''},366 p3: {t: 'space after punctuation mark missing', s: ''},367 p3sub1: {t: 'no space after closing parenthesis', s: ''},368 p4: {369 t: 'trailing punctuation mark different from source',370 s: 'trailing punctuation mark different from target',371 },372 l2: {373 t: 'leading capitalization different from source',374 s: 'leading capitalization different from target',375 },376 p6: {t: 'should be capitalized after punctuation mark', s: ''},377 l1: {t: 'repeated word', s: ''},378 c1: {t: 'multiple spaces', s: ''},379 c2: {t: 'segment starting with space', s: ''},380 c2sub1: {t: 'space found after opening bracket/parenthesis', s: ''},381 c3sub1: {t: 'space found before closing bracket/parenthesis', s: ''},382 c3: {t: 'space found at the end of segment', s: ''},383 s2: {t: 'foreign character', s: ''},384 s3: {t: 'bracket mismatch', s: ''},385 s3sub1: {t: 'bracket not closed', s: ''},386 s3sub2: {t: 'bracket not opened', s: ''},387 s4: {388 t: 'character missing from source',389 s: 'character missing from target',390 },391 s5: {t: 'currency mismatch', s: 'currency mismatch'},392 default: {t: 'not found in source', s: 'missing from target'},393 }394 var modulesNoHighlight = ['b1g', 'g1g', 'g2g', 'g3g']395 var isNumeric = function (n) {396 return !isNaN(parseFloat(n)) && isFinite(n)397 }398 var cleanRanges = function (ranges) {399 var out = []400 if ($.isPlainObject(ranges) || isNumeric(ranges[0])) {401 ranges = [ranges]402 }403 for (var i = 0, l = ranges.length; i < l; i++) {404 var range = ranges[i]405 if ($.isArray(range)) {406 out.push({407 color: color,408 start: range[0],409 end: range[1],410 })411 } else {412 if (range.ranges) {413 if ($.isPlainObject(range.ranges) || isNumeric(range.ranges[0])) {414 range.ranges = [range.ranges]415 }416 for (var j = 0, m = range.ranges.length; j < m; j++) {417 if ($.isArray(range.ranges[j])) {418 out.push({419 color: range.color,420 class: range.class,421 start: range.ranges[j][0],422 end: range.ranges[j][1],423 })424 } else {425 if (range.ranges[j].length) {426 range.ranges[j].end =427 range.ranges[j].start + range.ranges[j].length428 }429 out.push(range.ranges[j])430 }431 }432 } else {433 if (range.length) {434 range.end = range.start + range.length435 }436 out.push(range)437 }438 }439 }440 if (out.length == 0) {441 return null442 }443 out.sort(function (a, b) {444 if (a.end == b.end) {445 return a.start - b.start446 }447 return a.end - b.end448 })449 var textMaxHighlight = out[out.length - 1].end450 out.sort(function (a, b) {451 if (a.start == b.start) {452 return a.end - b.end453 }454 return a.start - b.start455 })456 var textMinHighlight = out[0].start457 var txt = new Array(textMaxHighlight - textMinHighlight + 1)458 for (var i = 0; i < txt.length; i++) txt[i] = []459 $.each(out, function (j, range) {460 var i461 if (range.ignore != true) {462 //do not add the ignored errors463 //if (!(!isSegmentCompleted && (range.module=== 'c1' || range.module=== 'c3'))) {464 //if (!(!isSegmentCompleted && range.module=== 'c3')) {465 if (!(range.module === 'c3')) {466 //if segment is not complete - completely ignore doublespaces, becuase467 //they seriously break formating....468 for (i = range.start; i < range.end; i++) {469 txt[i - textMinHighlight].push(j)470 }471 }472 }473 })474 var newout = []475 var curitem = null476 for (var i = 0; i < txt.length; i++) {477 if (txt[i].length > 0) {478 //more than one errors - start multiple479 if (curitem == null) {480 curitem = {}481 curitem.start = i + textMinHighlight482 curitem.errors = txt[i].slice(0)483 curitem.ignore = false484 } else {485 //check if the errors are the same or not..486 var areErrorsSame = true487 if (curitem.errors.length == txt[i].length) {488 for (var j = 0; j < curitem.errors.length; j++) {489 if (curitem.errors[j] != txt[i][j]) {490 areErrorsSame = false491 continue492 }493 }494 } else {495 areErrorsSame = false496 }497 if (!areErrorsSame) {498 curitem.end = i + textMinHighlight499 newout.push(curitem)500 //restart it!501 curitem = {}502 curitem.start = i + textMinHighlight503 curitem.errors = txt[i].slice(0)504 }505 }506 } else {507 if (curitem != null) {508 curitem.end = i + textMinHighlight509 newout.push(curitem)510 curitem = null511 }512 }513 }514 return {out: out, newout: newout}515 }516 var getRanges = function (results, text, isSource) {517 //var text = $(area).val();518 // var LTPLACEHOLDER = "##LESSTHAN##";519 // var GTPLACEHOLDER = "##GREATERTHAN##";520 var rangesIn = [521 {522 //color: '#D08053',523 ranges: results.numbers,524 },525 {526 //color: '#3AB45F',527 ranges: results.punctuation,528 },529 {530 //color: '#3AB45F',531 ranges: results.spaces,532 },533 {534 //color: '#38C0C5',535 ranges: results.specialchardetect,536 },537 {538 //color: '#38C0C5',539 ranges: results.mspolicheck,540 },541 {542 //color: '#b8a300',543 ranges: results.urls,544 },545 {546 //color: '#563d7c',547 ranges: results.spelling,548 },549 {550 //color: '#563d7c',551 ranges: results.glossary,552 },553 {554 //color: '#563d7c',555 ranges: results.blacklist,556 },557 ]558 var ranges = cleanRanges(rangesIn)559 if (ranges == null) {560 //do nothing561 return {}562 }563 ranges.newout.map(function (range) {564 if (text && range.start !== range.end) {565 if (range.start < text.length && !range.ignore) {566 var dataErrors = '',567 multiple568 //calculate the color569 if (range.errors.length === 1) {570 range.color = ranges.out[range.errors[0]].color571 range.myClass =572 ranges.out[range.errors[0]].module +573 ' ' +574 ranges.out[range.errors[0]].module[0] +575 '0' //.p0 for instance576 dataErrors = ranges.out[range.errors[0]].errorid577 } else {578 range.myClass = ''579 multiple = 0580 range.errors.forEach(function (element) {581 range.myClass +=582 ' ' +583 ranges.out[element].module +584 ' ' +585 ranges.out[element].module[0] +586 '0'587 dataErrors += ' ' + ranges.out[element].errorid588 if (modulesNoHighlight.indexOf(ranges.out[element].module) < 0)589 multiple++590 })591 range.color = colors.multiple592 if (multiple > 1) range.myClass += ' m'593 range.myClass = range.myClass.trim()594 }595 if (!LXQ.lexiqaData.enableHighlighting) {596 range.myClass += ' lxq-invisible'597 } else {598 if (isSource) range.myClass += ' tooltipas'599 else range.myClass += ' tooltipa'600 }601 }602 }603 return range604 })605 return _.merge(ranges.out, ranges.newout)606 }607 var buildTooltipMessages = function (range, sid, isSource) {608 let classList = range.myClass.split(/\s+/)609 let messages = []610 let errorList = range.errorid.split(/\s+/)611 $.each(classList, function (j, cl) {612 var txt = getWarningForModule(cl, isSource)613 if (cl === 'g3g' && LXQ.lexiqaData.lexiqaWarnings[sid]) {614 //need to modify message with word.615 ind = Math.floor(j / 2) //we aredding the x0 classes after each class..616 var word = LXQ.lexiqaData.lexiqaWarnings[sid][errorList[ind]].msg617 txt = txt.replace('#xxx#', word)618 } else if (cl === 'o1' && LXQ.lexiqaData.lexiqaWarnings[sid]) {619 //need to modify message with word.620 ind = Math.floor(j / 2) //we aredding the x0 classes after each class..621 word =622 LXQ.lexiqaData.lexiqaWarnings[sid][errorList[ind]].tootipExtraText623 txt = txt.replace('XXXX', word)624 }625 if (txt !== null && LXQ.lexiqaData.lexiqaWarnings[sid]) {626 messages.push({627 msg: txt,628 error: errorList[j],629 })630 }631 })632 return messages633 }634 // var replaceWord = function(word, suggest,target) {635 //636 // //retrieve suggestion code637 // // var word = $(this).text();638 // // $.ajax({639 // // url: config.lexiqaServer+'/getSuggestions',640 // // data: {641 // // word: word,642 // // lang: config.target_rfc643 // // },644 // // type: 'GET',645 // // success: function(response) {646 // // $.each(response,function(i,suggest) {647 // // //txt+='</br>'+suggest;648 // // var row = $('<div class="tooltip-error-container"> '+649 // // '<a class="tooltip-error-category"/></div>');650 // // row.find('.tooltip-error-category').text(suggest);651 // // row.find('.tooltip-error-category').on('click', function (e) {652 // // e.preventDefault();653 // // LXQ.replaceWord(word, suggest,that);654 // // });655 // // $('#powerTip').append(row);656 // // });657 // // }658 // // });659 //660 //661 // };662 var ignoreError = function (errorid) {663 var splits = errorid.split(/_/g)664 var targetSeg = splits[1]665 var inSource = splits[splits.length - 1] === 's' ? true : false666 //console.log('ignoring error with id: '+ errorid +' in segment: '+targetSeg);667 LXQ.lexiqaData.lexiqaWarnings[targetSeg][errorid].ignored = true668 redoHighlighting(targetSeg, inSource)669 if (getVisibleWarningsCountForSegment(targetSeg) <= 0) {670 //remove the segment from database/reduce the number count671 LXQ.lxqRemoveSegmentFromWarningList(targetSeg)672 }673 postIgnoreError(errorid)674 }675 var redoHighlighting = function (segmentId, insource) {676 // var segment = UI.getSegmentById(segmentId);677 var highlights = {678 source: {679 numbers: [],680 punctuation: [],681 spaces: [],682 urls: [],683 spelling: [],684 specialchardetect: [],685 mspolicheck: [],686 glossary: [],687 blacklist: [],688 },689 target: {690 numbers: [],691 punctuation: [],692 spaces: [],693 urls: [],694 spelling: [],695 specialchardetect: [],696 mspolicheck: [],697 glossary: [],698 blacklist: [],699 },700 }701 $.each(LXQ.lexiqaData.lexiqaWarnings[segmentId], function (key, qadata) {702 if (!qadata.ignored)703 if (qadata.insource) {704 highlights.source[qadata.category].push(qadata)705 } else {706 highlights.target[qadata.category].push(qadata)707 }708 })709 SegmentActions.addLexiqaHighlight(segmentId, highlights)710 }711 var postIgnoreError = function (errorid) {712 $.ajax({713 type: 'POST',714 url: config.lexiqaServer + '/ignoreerror',715 data: {716 data: {717 errorid: errorid,718 },719 },720 success: function (result) {721 // console.log('postIgnoreError success: '+result);722 },723 })724 }725 var getVisibleWarningsCountForSegment = function (segment) {726 var segId727 if (typeof segment === 'string') {728 segId = segment729 } else segId = UI.getSegmentId(segment)730 if (!LXQ.lexiqaData.lexiqaWarnings.hasOwnProperty(segId)) return 0731 var count = 0732 $.each(LXQ.lexiqaData.lexiqaWarnings[segId], function (i, element) {733 if (734 (element.ignored === undefined || !element.ignored) &&735 element.module !== 'c3'736 )737 count++738 })739 return count740 }741 var getWarningForModule = function (module, isSource) {742 if (warningMessages.hasOwnProperty(module))743 return isSource ? warningMessages[module].s : warningMessages[module].t744 else return null745 }746 var notCheckedSegments //store the unchecked segments at startup747 var doQAallSegments = function () {748 var segments = SegmentStore.getAllSegments749 var notChecked = []750 $.each(segments, function (keys, segment) {751 var segId = segment.sid752 if (LXQ.lexiqaData.segments.indexOf(segId) < 0) {753 notChecked.push(segment)754 }755 })756 notCheckedSegments = notChecked757 checkNextUncheckedSegment()758 }759 var checkNextUncheckedSegment = function () {760 if (!(notCheckedSegments.length > 0)) return761 var segment = notCheckedSegments.pop()762 if (!segment) return763 if (segment.translation) {764 // console.log('Requesting QA for: '+segment);765 LXQ.doLexiQA(segment, true, checkNextUncheckedSegment)766 } else {767 checkNextUncheckedSegment()768 }769 }770 var initPopup = function () {771 $.ajax({772 type: 'GET',773 url: config.lexiqaServer + '/tooltipwarnings',774 success: function (result) {775 warningMessages = result776 modulesNoHighlight = []777 $.each(result, function (key, el) {778 if (key[key.length - 1] === 'g') modulesNoHighlight.push(key)779 })780 },781 error: function (result) {782 // console.err(result);783 },784 })785 }786 // Interfaces787 $.extend(LXQ, {788 getRanges: getRanges,789 colors: colors,790 buildTooltipMessages: buildTooltipMessages,791 getVisibleWarningsCountForSegment: getVisibleWarningsCountForSegment,792 ignoreError: ignoreError,793 redoHighlighting: redoHighlighting,794 doQAallSegments: doQAallSegments,795 initPopup: initPopup,796 partnerid: partnerid,797 projectid: config.id_job + '-' + config.password,798 })799 })(jQuery, config, window, LXQ)800}801$(document).ready(function () {802 if (LXQ.enabled()) {803 LXQ.init()804 }805})...
get-test-error.js
Source:get-test-error.js
...40 });41 const normalizedErrors = errs.map(function (err) {42 return normalizeError(err, userAgents);43 });44 if (areErrorsSame(normalizedErrors) && normalizedErrors.length === browsers.length)45 return [normalizedErrors[0]];46 if (browsers.length > 1) {47 const testError = {};48 browsers.forEach(function (browserInfo) {49 const errorsArray = errs50 .filter(function (error) {51 return error.indexOf(browserInfo.connection.userAgent) > -1;52 })53 .map(function (err) {54 return normalizeError(err, userAgents);55 });56 if (errorsArray.length)57 testError[browserInfo.settings.alias] = errorsArray;58 else...
Using AI Code Generation
1import {areErrorsSame} from 'testcafe';2test('My test', async t => {3 await t.click('#non-existent-element');4});5import {areErrorsSame} from 'testcafe/lib/errors';6test('My test', async t => {7 await t.click('#non-existent-element');8});9import {areErrorsSame} from 'testcafe';10test('My test', async t => {11 await t.click('#non-existent-element');12});13import {areErrorsSame} from 'testcafe';14test('My test', async t => {15 await t.click('#non-existent-element');16});17import {areErrorsSame} from 'testcafe';18test('My test', async t => {19 await t.click('#non-existent-element');20});21import {areErrorsSame} from 'testcafe';22test('My test', async t => {23 await t.click('#non-existent-element');24});25import {areErrorsSame} from 'testcafe';26test('My test', async t => {27 await t.click('#non-existent-element');28});29import {areErrorsSame} from 'testcafe';30test('My test', async t => {31 await t.click('#non-existent-element');32});33import {areErrorsSame} from 'testcafe';34test('My test', async t => {35 await t.click('#non-existent-element');36});37import {areErrorsSame
Using AI Code Generation
1import {areErrorsSame} from 'testcafe';2import {areErrorsSame} from 'testcafe';3import {areErrorsSame} from 'testcafe';4import {areErrorsSame} from 'testcafe';5import {areErrorsSame} from 'testcafe';6import {areErrorsSame} from 'testcafe';7import {areErrorsSame} from 'testcafe';8import {areErrorsSame} from 'testcafe';9import {areErrorsSame} from 'testcafe';10import {areErrorsSame} from 'testcafe';11import {areErrorsSame} from 'testcafe';12import {areErrorsSame} from 'testcafe';13import {areErrorsSame} from 'testcafe';14import {areErrorsSame} from 'testcafe';15import {areErrorsSame} from 'testcafe';16import {areErrorsSame} from 'testcafe';17import {areErrorsSame} from 'testcafe';18import {areErrorsSame} from 'testcafe';
Using AI Code Generation
1import {areErrorsSame} from 'testcafe';2import {isTestCafeError} from 'testcafe';3test('test', async t => {4 const err1 = await t.eval(() => {5 throw new Error('error1');6 });7 const err2 = await t.eval(() => {8 throw new Error('error2');9 });10 await t.expect(areErrorsSame(err1, err2)).ok();11 await t.expect(isTestCafeError(err1)).ok();12 await t.expect(isTestCafeError(err2)).ok();13});14import {isTestCafeError} from 'testcafe';15test('test', async t => {16 const err = await t.eval(() => {17 throw new Error('error');18 });19 await t.expect(isTestCafeError(err)).ok();20});21import {isSelector} from 'testcafe';22test('test', async t => {23 await t.expect(isSelector('selector')).ok();24});25import {Selector} from 'testcafe';26test('test', async t => {27 const selector = Selector('selector');28 await t.expect(selector.exists).ok();29});30import {ClientFunction} from 'testcafe';31test('test', async t => {32 const clientFunction = ClientFunction(() => {
Using AI Code Generation
1import { ClientFunction } from 'testcafe';2const areErrorsSame = ClientFunction(() => window.__testCafeErrorComparator.areErrorsSame);3test('test', async t => {4 const err1 = new Error('message');5 const err2 = new Error('message');6 await t.expect(areErrorsSame(err1, err2)).eql(true);7});
Using AI Code Generation
1import { ClientFunction } from 'testcafe';2const areErrorsSame = ClientFunction(() => window.__testCafeErrorsAreSame);3test('My Test', async t => {4 .click('#submit-button')5 .expect(areErrorsSame()).ok();6});7test('My Test', async t => {8 .click('#submit-button')9 .expect(areErrorsSame()).ok();10});11test('My Test', async t => {12 .click('#submit-button')13 .expect(areErrorsSame()).ok();14});15test('My Test', async t => {16 .click('#submit-button')17 .expect(areErrorsSame()).ok();18});19test('My Test', async t => {20 .click('#submit-button')21 .expect(areErrorsSame()).ok();22});23test('My Test', async t => {24 .click('#submit-button')25 .expect(areErrorsSame()).ok();26});27test('My Test', async t => {28 .click('#submit-button')29 .expect(areErrorsSame()).ok();30});
Using AI Code Generation
1const reporter = require('testcafe').reporter;2const assert = require('assert');3test('My test', async t => {4 .click('#button');5 assert.ok(reporter.areErrorsSame(6 new Error('error1'),7 new Error('error1')8 ));9});10const reporter = require('testcafe').reporter;11const assert = require('assert');12test('My test', async t => {13 .click('#button');14 assert.ok(reporter.areErrorsSame(15 new Error('error1'),16 new Error('error2')17 ));18});
Using AI Code Generation
1import {areErrorsSame} from 'testcafe';2const firstErr = new TypeError('First error');3const secondErr = new TypeError('Second error');4const thirdErr = new TypeError('First error');5import {areErrorsSame} from 'testcafe';6const firstErr = new TypeError('First error');7const secondErr = new TypeError('Second error');8const thirdErr = new TypeError('First error');
Using AI Code Generation
1import { TestcafeErrorList } from 'testcafe-error-list';2const errorList = new TestcafeErrorList();3 {4 {5 },6 {7 }8 },9 {10 {
Using AI Code Generation
1import { TestcafeErrorList } from './testcafeErrorList';2import { TestcafeError } from './testcafeError';3let errors1 = new TestcafeErrorList();4let errors2 = new TestcafeErrorList();5let err1 = new TestcafeError('err1', 'err1', 'err1');6let err2 = new TestcafeError('err2', 'err2', 'err2');7let err3 = new TestcafeError('err3', 'err3', 'err3');8errors1.add(err1);9errors1.add(err2);10errors1.add(err3);11errors2.add(err1);12errors2.add(err2);13errors2.add(err3);14console.log(errors1.areErrorsSame(errors2));15errors2.add(err1);16console.log(errors1.areErrorsSame(errors2));17errors2.remove(err1);18console.log(errors1.areErrorsSame(errors2));19errors2.remove(err2);20console.log(errors1.areErrorsSame(errors2));21errors2.remove(err3);22console.log(errors1.areErrorsSame(errors2));23errors2.add(err3);24console.log(errors1.areErrorsSame(errors2));25errors2.add(err2);26console.log(errors1.areErrorsSame(errors2));27errors2.add(err1);28console.log(errors1.areErrorsSame(errors2));29import { TestcafeError } from './testcafeError';30export class TestcafeErrorList {31 constructor() {32 this.errors = [];33 }34 add(err) {35 if (err instanceof TestcafeError) {36 this.errors.push(err);37 }38 }39 remove(err) {40 let index = this.errors.indexOf(err);41 if (index >= 0) {42 this.errors.splice(index, 1);43 }44 }45 areErrorsSame(errList) {46 if (!(errList instanceof TestcafeErrorList)) {47 return false;48 }49 if (this.errors.length !== errList.errors.length) {50 return false;51 }52 for (let i = 0; i < this.errors.length;
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!!