Best JavaScript code snippet using playwright-internal
little.js
Source:little.js
...98 if (currentDisplayStatus && currentDisplayStatus !== 'none') 99 this.previousDisplayStatus[reference] = currentDisplayStatus;100 let display = 'none';101 let element = little.getElement(reference);102 little.processElement(element,103 function(element) {104 element.style.display = display;105 });106 },107 108 showElement (reference, userDefinedDisplayClass) {109 let display;110 if (!this.previousDisplayStatus[reference] && !userDefinedDisplayClass)111 display = this.defaultDisplayClass;112 else113 display = userDefinedDisplayClass || this.previousDisplayStatus[reference];114 115 let element = little.getElement(reference);116 if(element)117 little.processElement(element,118 function(element) {119 element.style.display = display;120 });121 }122 123 },124 125 // To get simple input box value. Returned value will be an array.126 getElementValue (reference) {127 let element = little.getElement(reference);128 let data = [];129 if(element) {130 little.processElement(element, function(element) {131 data.push(element.value);132 });133 } 134 else 135 elementNotFound();136 return data;137 138 },139 140 141 // To get html part of an element. Returned value will be an array.142 getElementText (reference) {143 let element = little.getElement(reference);144 let data = [];145 if(element) {146 little.processElement(element, function(element) {147 data.push(element.innerHTML);148 });149 } 150 else 151 elementNotFound();152 return data;153 154 },155 getAutocompleteSelectedValue (value) {},156 157 /* To implement autocomplete in a text box. Input parameter will be JSON of textbox type, textbox reference, resultReference (name of element id where result list will get displayed), interval (in milliseconds after which autocomplete func gets called), classlist to beautify result list and a callback function. 158 Callback function will have text, callback1 and args as input parameters. Text is what user searches and callback1 is the function that will be called taking search result and args as parameters.159 160 Search results will be passed as an array of JSON objects. Each JSON will have id (text value) and label (text). To get selected value, override getAutocompleteSelectedValue function of the library which has value as parameter. 161 To beautify resultlist, classList will be passed as JSON with ulClass (for ul), liClass (for li) and selectedClass (for hovered li).162 163 Requires removeEventFromElement, createNewDataInElement, addEventToElement, displayElement,164 setElementAttribute */165 implementAutoComplete (args) {166 let maxId = 0;167 let listIdPrefix = 'resultList';168 let defaultInterval = 50;169 let showHideResultList = function(reference, resultReference) {170 let clickFunc = function(k) {171 if (k.target.id == reference || k.target.id == resultReference) {172 if (little.getElementValue(reference)[0].trim().length) {173 little.displayElement.showElement('id', resultReference);174 } else {175 little.displayElement.hideElement('id', resultReference);176 }177 } else {178 little.displayElement.hideElement('id', resultReference);179 }180 };181 document.addEventListener('click', clickFunc);182 };183 let autoCompleteResultList = function(data, newVars) {184 try {185 if(data){186 let listId = listIdPrefix + maxId;187 let listIdLi = '#' + listId +' li';188 if (!newVars.classList.liClass)189 newVars.classList.liClass = '';190 if (!newVars.classList.ulClass)191 newVars.classList.ulClass = '';192 193 let clickEvent = function(){194 setCurrentLi(newVars, this.innerHTML, this.getAttribute('value'), this.getAttribute('position'));195 if(newVars.currentLi)196 little.setElementValue(newVars.inputReference, newVars.currentLi);197 little.getAutocompleteSelectedValue(newVars.currentLiValue);198 };199 little.removeEventFromElement('selectorAll', listIdLi, 'click', clickEvent);200 201 let mouseoverEvent = function(){202 little.removeCSSClass('selectorAll', listIdLi, newVars.classList.selectedClass);203 this.classList.add(newVars.classList.selectedClass);204 setCurrentLi(newVars, this.innerHTML, this.getAttribute('value'), this.getAttribute('position'));205 };206 little.removeEventFromElement('selectorAll', listIdLi, 'mouseover', mouseoverEvent);207 208 209 let result = '<ul id="' + listId + '" class="' + newVars.classList.liClass + '">';210 let length = data.length;211 newVars.numOfSearchResults = length;212 let ulClass = newVars.classList.ulClass;213 for ( let n = 0; n < length; n++) {214 let position = n;215 result = result + '<li style="cursor:pointer" class="' + ulClass + '" value="' + data[n].id + '" position="' + position + '">' + data[n].label + '</li>';216 }217 result = result + '</ul>';218 little.createNewDataInElement('id', newVars.resultReference, result);219 little.displayElement.showElement('id', newVars.resultReference);220 little.addEventToElement('selectorAll', listIdLi, 'click', clickEvent);221 little.addEventToElement('selectorAll', listIdLi , 'mouseover', mouseoverEvent);222 newVars.position = -1;223 }224 } catch (e) {225 console.log(e);226 }227 228 };229 230 let autoCompleteGetResult = function(newVars, inputValue, callback) {231 callback(inputValue, autoCompleteResultList, newVars);232 };233 234 let setCurrentLi = function(newVars, html, value, position) {235 newVars.currentLi = html; 236 newVars.currentLiValue = value;237 if(typeof(position)!=='undefined') newVars.position = position;238 };239 240 let implementAutoComplete = function(newVars, 241 interval, callback, classList) {242 243 try {244 maxId++;245 let listId = listIdPrefix + maxId;246 newVars.classList = classList;247 let type = newVars.inputType;248 let reference = newVars.inputReference;249 little.setElementAttribute(reference, 'autocomplete', 'off');250 showHideResultList(reference, newVars.resultReference);251 let keyupFunc = function(j) {252 if (newVars.typingTimer) {253 clearTimeout(newVars.typingTimer);254 }255 let i = (j.keyCode ? j.keyCode : j.which);256 if ((i != "40") && (i != "63233") && (i != "63232") && (i != "38")) {257 newVars.typingTimer = setTimeout(function() {258 autoCompleteGetResult(newVars, little.getElementValue(reference), callback);259 }, interval);260 }261 };262 little.addEventToElement(reference, 'keyup', keyupFunc);263 264 let keydownFunc = function(j) {265 newVars.counter = 0;266 let i = (j.keyCode ? j.keyCode : j.which);267 268 if (i == "27") {269 little.displayElement.hideElement('id',270 newVars.resultReference);271 little.getElement(reference).blur();272 } else if(newVars.currentLi && i=="13") {273 little.setElementValue(newVars.inputReference,newVars.currentLi);274 little.getAutocompleteSelectedValue(newVars.currentLiValue);275 little.displayElement.hideElement('id', newVars.resultReference);276 }277 else if ((i == "40") || (i == "63233")) {278 let list = document279 .getElementById(listId)280 .getElementsByTagName("li");281 282 if (newVars.position < newVars.numOfSearchResults - 1) {283 newVars.position++;284 let current = list[newVars.position];285 286 current.classList287 .add(classList.selectedClass);288 setCurrentLi(newVars, current.innerHTML, current.getAttribute("value")); 289 290 if (newVars.position > 0) {291 list[newVars.position - 1].classList292 .remove(classList.selectedClass);293 }294 }295 } else {296 if ((i == "38") || (i == "63232")) {297 let list = document.getElementById(298 listId).getElementsByTagName(299 "li");300 301 if (newVars.position > 0) {302 newVars.position--;303 let current = list[newVars.position];304 305 current.classList306 .add(classList.selectedClass);307 setCurrentLi(newVars, current.innerHTML, current.getAttribute("value")); 308 list[newVars.position + 1].classList309 .remove(classList.selectedClass);310 311 }312 }313 }314 };315 little.addEventToElement(reference, 'keydown', keydownFunc);316 } catch (e) {317 console.log(e);318 }319 };320 321 let vars = {322 'typingTimer' : null,323 'numOfSearchResults' : 0,324 'position' : -1325 };326 let newVars = Object.create(vars);327 let classList = {328 'selectedClass' : 'selected'329 };330 newVars.resultReference = args.resultReference;331 newVars.inputType = args.type;332 newVars.inputReference = args.reference;333 implementAutoComplete(newVars, 334 args.interval || defaultInterval, args.callback, args.classList || classList);335 },336 337 // Setting attribute's value of an element. Returned value will be an array.338 setElementAttribute (reference, attribute, value) {339 let element = little.getElement(reference);340 if(element)341 little.processElement(element, function(element) {342 element.setAttribute(attribute, value);343 });344 else 345 elementNotFound();346 347 },348 349 /* Adding / removing events to / from elements. 350 Effects like click, mouseover can be passed as an array and action is any function to be called after effect.*/351 addEventToElement (reference, effect, action) {352 let element = little.getElement(reference);353 if(element)354 if(typeof(effect) === 'string') {355 little.processElement(element, function(element) {356 element.addEventListener(effect, action);357 });358 } else {359 let length = effect.length;360 let processElement = little.processElement;361 for(let i=0;i < length; i++) {362 processElement(element, function(element) {363 element.addEventListener(effect[i], action);364 });365 }366 }367 else 368 elementNotFound(); 369 },370 371 removeEventFromElement (reference, effect, action) {372 let element = little.getElement(reference);373 if(element)374 if(typeof(effect) === 'string') {375 little.processElement(element, function(element) {376 element.removeEventListener(effect, action);377 });378 } else {379 let length = effect.length;380 let processElement = little.processElement; 381 for(let i=0;i < length; i++) {382 processElement(element, function(element) {383 element.removeEventListener(effect[i], action);384 });385 }386 }387 else 388 elementNotFound(); 389 },390 391 // To create inner html in an element.392 createNewDataInElement (reference, data) {393 let element = little.getElement(reference);394 if(element)395 little.processElement(element, function(element) {396 element.innerHTML = data;397 });398 else 399 elementNotFound();400 },401 402 // To set value in input box. Value passed as third parameter.403 setElementValue (reference, data) {404 let element = little.getElement(reference);405 if (element)406 little.processElement(element, function(element) {407 element.value = data;408 });409 else 410 elementNotFound();411 },412 413 // For adding / removing css class. Currently has compatibility issues with < IE 10 and for now only single class name can be passed.414 addCSSClass (reference, className) {415 let element = little.getElement(reference);416 className = ' ' + className;417 if(element)418 little.processElement(element, function(element) {419 element.className += className;420 });421 else 422 elementNotFound();423 },424 425 removeCSSClass (reference, className) {426 let element = little.getElement(reference);427 if(element)428 little.processElement(element, function(element) {429 let find = className;430 let re = new RegExp(find, 'g');431 element.className = element.className.replace(re, '');432 });433 else 434 elementNotFound();435 },436 437 // To get css property value of an element. Returned value will be an array.438 getCSSPropertyValue (reference, property) {439 let element = little.getElement(reference);440 let data = [];441 if(element)442 little.processElement(443 element,444 function(element) {445 if (element.currentStyle)446 data.push(element.currentStyle[property]);447 else if (window.getComputedStyle)448 data.push(document.defaultView.getComputedStyle(449 element, null).getPropertyValue(property));450 });451 else 452 elementNotFound();453 return data;454 },455 456 // To change css property value of an element.457 changeCSSPropertyValue (reference, property, value) {458 let element = little.getElement(reference);459 if(element)460 little.processElement(461 element,462 function(element) {463 element.style[property] = value;464 });465 else 466 elementNotFound();467 },468 469 // get selected checkboxes text and respective values as JSON contained in an element like div or span. Return type is array470 getCheckboxSelectedValues (reference) {471 let fieldList = document.querySelectorAll(reference);472 if(fieldList) {473 let checkedIdValues = [];474 let length = fieldList.length;...
DependencyPostprocessor.js
Source:DependencyPostprocessor.js
...22 var previousValue = htmlElement.shouldBeIncluded;23 Firecrow.includeNode(htmlElement, true);24 if(htmlElement.type == "script")25 {26 this.processElement(htmlElement.pathAndModel.model);27 }28 else if(htmlElement.type == "style" || htmlElement.type == "textNode") {}29 else30 {31 var childNodes = htmlElement.childNodes;32 if(childNodes != null)33 {34 for(var i = 0, length = childNodes.length; i < length; i++)35 {36 this.processHtmlElement(childNodes[i]);37 }38 }39 }40 },41 processElement: function(element)42 {43 if (ASTHelper.isProgram(element)) { this.processProgram(element); }44 else if (ASTHelper.isStatement(element)) { this.processStatement(element); }45 else if (ASTHelper.isFunction(element)) { this.processFunction(element); }46 else if (ASTHelper.isExpression(element)) { this.processExpression(element); }47 else if (ASTHelper.isSwitchCase(element)) { this.processSwitchCase(element); }48 else if (ASTHelper.isCatchClause(element)) { this.processCatchClause(element); }49 else if (ASTHelper.isVariableDeclaration(element)) { this.processVariableDeclaration(element); }50 else if (ASTHelper.isVariableDeclarator(element)) { this.processVariableDeclarator(element); }51 else if (ASTHelper.isLiteral(element)) { this.processLiteral(element); }52 else if (ASTHelper.isIdentifier(element)) { this.processIdentifier(element); }53 else { this.notifyError("Error while processing code unidentified ast element"); }54 },55 processProgram: function(programElement)56 {57 if(!this.inclusionFinder.isIncludedProgram(programElement)) { return; }58 Firecrow.includeNode(programElement, true);59 if(programElement.body != null)60 {61 var body = programElement.body;62 for(var i = 0, length = body.length; i < length; i++)63 {64 this.processElement(body[i]);65 }66 }67 },68 processStatement: function(statement)69 {70 if (ASTHelper.isEmptyStatement(statement)) { this.processEmptyStatement(statement); }71 else if (ASTHelper.isBlockStatement(statement)) { this.processBlockStatement(statement); }72 else if (ASTHelper.isExpressionStatement(statement)) { this.processExpressionStatement(statement); }73 else if (ASTHelper.isIfStatement(statement)) { this.processIfStatement(statement); }74 else if (ASTHelper.isWhileStatement(statement)) { this.processWhileStatement(statement); }75 else if (ASTHelper.isDoWhileStatement(statement)) { this.processDoWhileStatement(statement); }76 else if (ASTHelper.isForStatement(statement)) { this.processForStatement(statement); }77 else if (ASTHelper.isForInStatement(statement)) { this.processForInStatement(statement); }78 else if (ASTHelper.isLabeledStatement(statement)) { this.processLabeledStatement(statement); }79 else if (ASTHelper.isBreakStatement(statement)) { this.processBreakStatement(statement); }80 else if (ASTHelper.isContinueStatement(statement)) { this.processContinueStatement(statement); }81 else if (ASTHelper.isReturnStatement(statement)) { this.processReturnStatement(statement); }82 else if (ASTHelper.isWithStatement(statement)) { this.processWithStatement(statement); }83 else if (ASTHelper.isTryStatement(statement)) { this.processTryStatement(statement); }84 else if (ASTHelper.isThrowStatement(statement)) { this.processThrowStatement(statement); }85 else if (ASTHelper.isSwitchStatement(statement)) { this.processSwitchStatement(statement); }86 else if (ASTHelper.isVariableDeclaration(statement)) { this.processVariableDeclaration(statement);}87 else { this.notifyError("Error: AST Statement element not defined: " + statement.type); }88 },89 processExpression: function(expression)90 {91 if (ASTHelper.isAssignmentExpression(expression)) { this.processAssignmentExpression(expression); }92 else if (ASTHelper.isUnaryExpression(expression)) { this.processUnaryExpression(expression); }93 else if (ASTHelper.isBinaryExpression(expression)) { this.processBinaryExpression(expression); }94 else if (ASTHelper.isLogicalExpression(expression)) { this.processLogicalExpression(expression); }95 else if (ASTHelper.isLiteral(expression)) { this.processLiteral(expression); }96 else if (ASTHelper.isIdentifier(expression)) { this.processIdentifier(expression); }97 else if (ASTHelper.isUpdateExpression(expression)) { this.processUpdateExpression(expression); }98 else if (ASTHelper.isNewExpression(expression)) { this.processNewExpression(expression); }99 else if (ASTHelper.isConditionalExpression(expression)) { this.processConditionalExpression(expression); }100 else if (ASTHelper.isThisExpression(expression)) { this.processThisExpression(expression); }101 else if (ASTHelper.isCallExpression(expression)) { this.processCallExpression(expression); }102 else if (ASTHelper.isMemberExpression(expression)) { this.processMemberExpression(expression); }103 else if (ASTHelper.isSequenceExpression(expression)) { this.processSequenceExpression(expression); }104 else if (ASTHelper.isArrayExpression(expression)) { this.processArrayExpression(expression); }105 else if (ASTHelper.isObjectExpression(expression)) { this.processObjectExpression(expression); }106 else if (ASTHelper.isFunctionExpression(expression)) { this.processFunction(expression); }107 else { this.notifyError("Error: AST Expression element not defined: " + expression.type); "";}108 },109 processFunction: function(functionDecExp)110 {111 if(!this.inclusionFinder.isIncludedFunction(functionDecExp)) { return; }112 Firecrow.includeNode(functionDecExp, true);113 Firecrow.includeNode(functionDecExp.body, true);114 if(functionDecExp.id != null) { Firecrow.includeNode(functionDecExp.id);}115 var params = functionDecExp.params;116 if(params != null)117 {118 for(var i = 0, length = params.length; i < length; i++)119 {120 Firecrow.includeNode(params[i], true);121 }122 }123 this.processFunctionBody(functionDecExp);124 },125 processFunctionBody: function(functionDeclExp)126 {127 this.processElement(functionDeclExp.body);128 },129 processBlockStatement: function(blockStatement)130 {131 if(!this.inclusionFinder.isIncludedBlockStatement(blockStatement)) { return; }132 Firecrow.includeNode(blockStatement, true);133 var body = blockStatement.body;134 for(var i = 0, length = body.length; i < length; i++)135 {136 this.processElement(body[i]);137 }138 },139 processEmptyStatement: function(emptyStatement)140 {141 },142 processExpressionStatement: function(expressionStatement)143 {144 if(!this.inclusionFinder.isIncludedExpressionStatement(expressionStatement)) { return; }145 Firecrow.includeNode(expressionStatement, true);146 this.processElement(expressionStatement.expression);147 },148 processAssignmentExpression: function(assignmentExpression)149 {150 if(!this.inclusionFinder.isIncludedAssignmentExpression(assignmentExpression)) { return; }151 if(assignmentExpression.shouldBeIncluded)152 {153 Firecrow.includeNode(assignmentExpression.left, true);154 }155 Firecrow.includeNode(assignmentExpression, true);156 this.processElement(assignmentExpression.left);157 this.processElement(assignmentExpression.right);158 },159 processUnaryExpression: function(unaryExpression)160 {161 if(!this.inclusionFinder.isIncludedUnaryExpression(unaryExpression)) { return; }162 Firecrow.includeNode(unaryExpression, true);163 this.processExpression(unaryExpression.argument);164 },165 processBinaryExpression: function(binaryExpression)166 {167 if(!this.inclusionFinder.isIncludedBinaryExpression(binaryExpression)) { return; }168 Firecrow.includeNode(binaryExpression, true);169 this.processElement(binaryExpression.left);170 this.processElement(binaryExpression.right);171 },172 processLogicalExpression: function(logicalExpression)173 {174 if(!this.inclusionFinder.isIncludedLogicalExpression(logicalExpression)) { return; }175 Firecrow.includeNode(logicalExpression, true);176 this.processElement(logicalExpression.left);177 this.processElement(logicalExpression.right);178 },179 processUpdateExpression: function(updateExpression)180 {181 if(!this.inclusionFinder.isIncludedUpdateExpression(updateExpression)) { return; }182 Firecrow.includeNode(updateExpression, true);183 this.processElement(updateExpression.argument);184 },185 processNewExpression: function(newExpression)186 {187 if(!this.inclusionFinder.isIncludedNewExpression(newExpression)) { return; }188 Firecrow.includeNode(newExpression, true);189 Firecrow.includeNode(newExpression.callee, true);190 this.processElement(newExpression.callee);191 this.processSequence(newExpression.arguments);192 },193 processConditionalExpression: function(conditionalExpression)194 {195 if(!this.inclusionFinder.isIncludedConditionalExpression(conditionalExpression)) { return; }196 Firecrow.includeNode(conditionalExpression, true);197 this.processElement(conditionalExpression.test);198 this.processElement(conditionalExpression.consequent);199 this.processElement(conditionalExpression.alternate);200 },201 processThisExpression: function(thisExpression) { },202 processCallExpression: function(callExpression)203 {204 if(!this.inclusionFinder.isIncludedCallExpression(callExpression)) { return; }205 Firecrow.includeNode(callExpression, true);206 /*if(ASTHelper.isMemberExpression(callExpression.callee))207 {208 if(ASTHelper.isIdentifier(callExpression.callee.property))209 {210 Firecrow.includeNode(callExpression.callee.property);211 }212 if(ASTHelper.isIdentifier(callExpression.callee.object))213 {214 Firecrow.includeNode(callExpression.callee.object);215 }216 }*/217 this.processElement(callExpression.callee);218 this.processSequence(callExpression.arguments);219 },220 processMemberExpression: function(memberExpression)221 {222 if(!this.inclusionFinder.isIncludedMemberExpression(memberExpression)) { return; }223 var isObjectIncluded = this.inclusionFinder.isIncludedElement(memberExpression.object);224 var isPropertyIncluded = this.inclusionFinder.isIncludedElement(memberExpression.property);225 var areChildrenIncluded = isObjectIncluded || isPropertyIncluded;226 if(areChildrenIncluded)227 {228 Firecrow.includeNode(memberExpression, true);229 }230 if(!ASTHelper.isMemberExpression(memberExpression.parent)231 && !ASTHelper.isCallExpression(memberExpression.parent)232 && !ASTHelper.isCallExpression(memberExpression.object))233 {234 Firecrow.includeNode(memberExpression.object, true);235 Firecrow.includeNode(memberExpression.property, true);236 }237 /*else238 {239 if(ASTHelper.isIdentifier(memberExpression.property)240 && !ASTHelper.isCallExpression(memberExpression.parent)241 && areChildrenIncluded)242 {243 Firecrow.includeNode(memberExpression.object);244 Firecrow.includeNode(memberExpression.property);245 }246 } */247 this.processElement(memberExpression.object);248 this.processElement(memberExpression.property);249 },250 processSequenceExpression: function(sequenceExpression)251 {252 if(!this.inclusionFinder.isIncludedSequenceExpression(sequenceExpression)) { return; }253 Firecrow.includeNode(sequenceExpression, true);254 this.processSequence(sequenceExpression.expressions);255 },256 processArrayExpression: function(arrayExpression)257 {258 if(!this.inclusionFinder.isIncludedArrayExpression(arrayExpression)) { return; }259 Firecrow.includeNode(arrayExpression, true);260 this.processSequence(arrayExpression.elements);261 },262 processObjectExpression: function(objectExpression)263 {264 if(!this.inclusionFinder.isIncludedObjectExpression(objectExpression)) { return; }265 Firecrow.includeNode(objectExpression, true);266 var properties = objectExpression.properties;267 for (var i = 0, length = properties.length; i < length; i++)268 {269 this.processObjectExpressionProperty(properties[i]);270 }271 },272 processObjectExpressionProperty: function(objectExpressionProperty)273 {274 if(!this.inclusionFinder.isIncludedObjectExpressionProperty(objectExpressionProperty)) { return; }275 Firecrow.includeNode(objectExpressionProperty, true);276 Firecrow.includeNode(objectExpressionProperty.key, true);277 this.processElement(objectExpressionProperty.value);278 },279 processIfStatement: function(ifStatement)280 {281 if(!this.inclusionFinder.isIncludedIfStatement(ifStatement)) { return; }282 Firecrow.includeNode(ifStatement, true);283 this.processElement(ifStatement.test);284 //TODO - not sure about this: the problem is the if statement gets included, but it does not include the285 //return statement in it's body - and i'm not sure whether it even should286 if(ifStatement.test.shouldBeIncluded)287 {288 var returnStatement = ASTHelper.getDirectlyContainedReturnStatement(ifStatement.consequent);289 if(returnStatement != null && returnStatement.hasBeenExecuted)290 {291 Firecrow.includeNode(returnStatement, true);292 }293 }294 this.processElement(ifStatement.consequent);295 if(ifStatement.alternate != null)296 {297 this.processElement(ifStatement.alternate);298 }299 },300 processWhileStatement: function(whileStatement)301 {302 if(!this.inclusionFinder.isIncludedWhileStatement(whileStatement)) { return; }303 Firecrow.includeNode(whileStatement, true);304 this.processElement(whileStatement.test);305 this.processElement(whileStatement.body);306 },307 processDoWhileStatement: function(doWhileStatement)308 {309 if(!this.inclusionFinder.isIncludedDoWhileStatement(doWhileStatement)) { return; }310 Firecrow.includeNode(doWhileStatement, true);311 this.processElement(doWhileStatement.test);312 this.processElement(doWhileStatement.body);313 },314 processForStatement: function(forStatement)315 {316 if(!this.inclusionFinder.isIncludedForStatement(forStatement)) { return; }317 Firecrow.includeNode(forStatement, true);318 if(forStatement.init != null) { this.processElement(forStatement.init); }319 if(forStatement.test != null) { this.processElement(forStatement.test); }320 if(forStatement.update != null) {this.processElement(forStatement.update)}321 this.processElement(forStatement.body);322 },323 processForInStatement: function(forInStatement)324 {325 if(!this.inclusionFinder.isIncludedForInStatement(forInStatement)) { return; }326 Firecrow.includeNode(forInStatement, true);327 this.processElement(forInStatement.left);328 this.processElement(forInStatement.right);329 this.processElement(forInStatement.body);330 if(forInStatement.right.shouldBeIncluded) { forInStatement.left.shouldBeIncluded; }331 },332 processBreakStatement: function(breakStatement)333 {334 if(!this.inclusionFinder.isIncludedBreakStatement(breakStatement)) { return; }335 Firecrow.includeNode(breakStatement, true);336 },337 processContinueStatement: function(continueStatement)338 {339 if(!this.inclusionFinder.isIncludedContinueStatement(continueStatement)) { return; }340 Firecrow.includeNode(continueStatement, true);341 },342 processReturnStatement: function(returnStatement)343 {344 if(!this.inclusionFinder.isIncludedReturnStatement(returnStatement)) { return; }345 Firecrow.includeNode(returnStatement, true);346 if(returnStatement.argument != null) { this.processExpression(returnStatement.argument); }347 },348 processWithStatement: function(withStatement)349 {350 if(!this.inclusionFinder.isIncludedWithStatement(withStatement)) { return; }351 Firecrow.includeNode(withStatement, true);352 this.processExpression(withStatement.object);353 this.processStatement(withStatement.body);354 },355 processThrowStatement: function(throwStatement)356 {357 if(!this.inclusionFinder.isIncludedThrowStatement(throwStatement)) { return; }358 Firecrow.includeNode(throwStatement, true);359 this.processExpression(throwStatement.argument);360 },361 processSwitchStatement: function(switchStatement)362 {363 if(!this.inclusionFinder.isIncludedSwitchStatement(switchStatement)) { return; }364 Firecrow.includeNode(switchStatement, true);365 this.processExpression(switchStatement.discriminant);366 for(var i = 0; i < switchStatement.cases.length; i++)367 {368 this.processSwitchCase(switchStatement.cases[i]);369 }370 },371 processSwitchCase: function(switchCase)372 {373 if(!this.inclusionFinder.isIncludedSwitchCase(switchCase)) { return; }374 Firecrow.includeNode(switchCase, true);375 if(switchCase.test != null)376 {377 Firecrow.includeNode(switchCase.test, true);378 }379 for(var i = 0; i < switchCase.consequent.length; i++)380 {381 this.processStatement(switchCase.consequent[i]);382 }383 },384 processTryStatement: function(tryStatement)385 {386 if(!this.inclusionFinder.isIncludedTryStatement(tryStatement)) { return; }387 Firecrow.includeNode(tryStatement, true);388 this.processElement(tryStatement.block);389 var handlers = tryStatement.handlers || (ValueTypeHelper.isArray(tryStatement.handler) ? tryStatement.handler : [tryStatement.handler]);390 for(var i = 0; i < handlers.length; i++)391 {392 Firecrow.includeNode(handlers[i], true);393 this.processCatchClause(handlers[i]);394 }395 if(tryStatement.finalizer != null)396 {397 this.processElement(tryStatement.finalizer);398 }399 },400 processLabeledStatement: function(labeledStatement)401 {402 if(!this.inclusionFinder.isIncludedStatement(labeledStatement)) { return; }403 Firecrow.includeNode(labeledStatement, true);404 this.processElement(labeledStatement.body);405 },406 processVariableDeclaration: function(variableDeclaration)407 {408 if(!this.inclusionFinder.isIncludedVariableDeclaration(variableDeclaration)) { return; }409 Firecrow.includeNode(variableDeclaration, true);410 var declarators = variableDeclaration.declarations;411 for (var i = 0, length = declarators.length; i < length; i++)412 {413 this.processVariableDeclarator(declarators[i]);414 }415 },416 processVariableDeclarator: function(variableDeclarator)417 {418 if(!this.inclusionFinder.isIncludedVariableDeclarator(variableDeclarator)) { return; }419 Firecrow.includeNode(variableDeclarator, true);420 Firecrow.includeNode(variableDeclarator.id, true);421 if(variableDeclarator.init != null)422 {423 this.processElement(variableDeclarator.init);424 }425 },426 processPattern: function(pattern)427 {428 if(ASTHelper.isIdentifier(pattern)) { this.processIdentifier(pattern);}429 },430 processCatchClause: function(catchClause)431 {432 if(!this.inclusionFinder.isIncludedCatchClause(catchClause)) { return;}433 Firecrow.includeNode(catchClause, true);434 this.processElement(catchClause.param);435 this.processStatement(catchClause.body);436 },437 processIdentifier: function(identifier) { },438 processLiteral: function(literal)439 {440 if(literal.shouldBeIncluded == true && Firecrow.ValueTypeHelper.isObject(literal.value))441 {442 Firecrow.includeNode(literal.value, true);443 }444 },445 processSequence: function(sequence)446 {447 var code = "";448 for(var i = 0, length = sequence.length; i < length; i++)449 {450 this.processElement(sequence[i])451 }452 },453 notifyError:function(message) { DependencyPostprocessor.notifyError(message); }454 }455 /*************************************************************************************/...
process.service.js
Source:process.service.js
1/* 2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 * 10 * http://www.apache.org/licenses/LICENSE-2.011 * 12 * Unless required by applicable law or agreed to in writing,13 * software distributed under the License is distributed on an14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15 * KIND, either express or implied. See the License for the16 * specific language governing permissions and limitations17 * under the License.18 */19'use strict';20/*global $:false */21/*global vkbeautify:false */22/**23 * @ngdoc service24 * @name angApp.InstanceService25 * @description26 * # InstanceService27 * Service in the angApp.28 */29angular.module('odeConsole')30 .factory('ProcessService', function ($http, $log, $q, $interval, _, SoapService, PMAPI_ENDPOINT, DSAPI_ENDPOINT, POLLING_INTERVAL) {31 32 var PMAPI_NS = 'http://www.apache.org/ode/pmapi';33 /** private functions **/34 var nsResolver = function (prefix) {35 var ns = {36 'ns' : 'http://www.apache.org/ode/pmapi/types/2006/08/02/',37 'soapenv': 'http://schemas.xmlsoap.org/soap/envelope/',38 'pmapi' : 'http://www.apache.org/ode/pmapi'39 };40 return ns[prefix] || null;41 };42 var splitPackageName = function(packageName) {43 var split = packageName.split('-');44 var hasVersion = !isNaN(_.last(split));45 var result = {46 packageId: packageName,47 name: (_.first(split, split.length - hasVersion).join('-')),48 };49 50 result.version = hasVersion ? _.last(split) : null;51 return result;52 };53 var mapProcessInfo = function(processElement) {54 var processNameEl = processElement.xpath('ns:definition-info/ns:process-name', nsResolver);55 var result = {};56 result.pid = processElement.xpath('ns:pid', nsResolver).text();57 result.status = processElement.xpath('ns:status', nsResolver).text();58 result.version = processElement.xpath('ns:version', nsResolver).text();59 result.package = processElement.xpath('ns:deployment-info/ns:package', nsResolver).text();60 result.deployDate = processElement.xpath('ns:deployment-info/ns:deploy-date', nsResolver).text();61 result.nameShort = processNameEl.text();62 result.nameFull = SoapService.qnameToString(SoapService.createQNameObj(processNameEl.text(), processNameEl[0]));63 // endpoints64 result.endpoints = {65 myRole: [],66 partnerRole: []67 };68 processElement.xpath('ns:endpoints/ns:endpoint-ref[@my-role]', nsResolver).each(function() {69 result.endpoints.myRole.push(vkbeautify.xml($(this).first().html().trim(), 2));70 });71 processElement.xpath('ns:endpoints/ns:endpoint-ref[@partner-role]', nsResolver).each(function() {72 result.endpoints.partnerRole.push(vkbeautify.xml($(this).first().html().trim(), 2));73 });74 // documents75 result.documents = [];76 processElement.xpath('ns:documents/ns:document', nsResolver).each(function() {77 var d = {};78 d.name = $(this).xpath('ns:name', nsResolver).text();79 d.type = $(this).xpath('ns:type', nsResolver).text();80 d.source = $(this).xpath('ns:source', nsResolver).text();81 result.documents.push(d);82 });83 // properties84 // TODO85 result.stats = {86 active: Number(processElement.xpath('ns:instance-summary/ns:instances[@state=\'ACTIVE\']/@count', nsResolver).val()),87 completed: Number(processElement.xpath('ns:instance-summary/ns:instances[@state=\'COMPLETED\']/@count', nsResolver).val()),88 error: Number(processElement.xpath('ns:instance-summary/ns:instances[@state=\'ERROR\']/@count', nsResolver).val()),89 failed: Number(processElement.xpath('ns:instance-summary/ns:instances[@state=\'FAILED\']/@count', nsResolver).val()),90 suspended: Number(processElement.xpath('ns:instance-summary/ns:instances[@state=\'SUSPENDED\']/@count', nsResolver).val()),91 terminated: Number(processElement.xpath('ns:instance-summary/ns:instances[@state=\'TERMINATED\']/@count', nsResolver).val()),92 inrecovery: Number(processElement.xpath('ns:instance-summary/ns:failures/ns:count', nsResolver).text() || 0)93 };94 return result;95 };96 /** public functions **/97 var ps = {};98 var updateStats = function(packages) {99 ps.summary = {};100 ps.summary.packages = 0;101 ps.summary.processes = 0;102 ps.summary.instances = 0;103 ps.summary.active = 0;104 ps.summary.completed = 0;105 ps.summary.suspended = 0;106 ps.summary.failed = 0;107 ps.summary.error = 0;108 ps.summary.inrecovery = 0;109 ps.summary.terminated = 0;110 packages.forEach(function(pa) {111 ps.summary.packages++;112 pa.processes.forEach(function(process) {113 ps.summary.processes++;114 ps.summary.active += process.stats.active;115 ps.summary.completed += process.stats.completed;116 ps.summary.suspended += process.stats.suspended;117 ps.summary.failed += process.stats.failed;118 ps.summary.error += process.stats.error;119 ps.summary.inrecovery += process.stats.inrecovery;120 ps.summary.terminated += process.stats.terminated;121 ps.summary.instances += Object.keys(process.stats).reduce(function (a,b) { 122 return a + process.stats[b];123 }, 0);124 });125 });126 };127 ps.getPackages = function() {128 var deferred = $q.defer();129 SoapService.callSOAP(PMAPI_ENDPOINT,130 {localName: 'listAllProcesses', namespaceURI: PMAPI_NS},131 {})132 .then(function(response) {133 var packages = {},134 els = response.xpath('//ns:process-info', nsResolver);135 for (var i = 0; i < els.length; i += 1) {136 var process = angular.element(els[i]);137 var packageName = process.xpath('ns:deployment-info/ns:package', nsResolver).text();138 packages[packageName] = packages[packageName] || _.extend(splitPackageName(packageName),139 { 140 deployDate: process.xpath('ns:deployment-info/ns:deploy-date', nsResolver).text(),141 processes: []142 });143 packages[packageName].processes.push(mapProcessInfo(process));144 }145 updateStats(_.values(packages));146 deferred.resolve(_.values(packages));147 }, function(msg, code) {148 deferred.reject(msg);149 $log.error(msg, code);150 });151 return deferred.promise;152 };153 /**154 * List the processes known to the engine.155 * @returns list of {@link ProcessInfoDocument}s (including instance summaries)156 */157 ps.getProcesses = function() {158 var deferred = $q.defer();159 SoapService.callSOAP(PMAPI_ENDPOINT,160 {localName: 'listAllProcesses', namespaceURI: PMAPI_NS},161 {})162 .then(function(response) {163 var processes = [],164 els = response.xpath('//ns:process-info', nsResolver),165 process,166 i;167 for (i = 0; i < els.length; i += 1) {168 process = angular.element(els[i]);169 processes.push(mapProcessInfo(process));170 }171 deferred.resolve(processes);172 }, function(msg, code) {173 deferred.reject(msg);174 $log.error(msg, code);175 });176 return deferred.promise;177 };178 /**179 * Get the process info for a process (includingthe instance summary).180 * @param pid name of the process181 * @returns {@link ProcessInfoDocument} with all details.182 */183 ps.getProcessInfo = function (pid) {184 var deferred = $q.defer();185 var pidQName = SoapService.parseQNameStr(pid);186 pidQName.prefix = 'pns';187 SoapService.callSOAP(PMAPI_ENDPOINT,188 {localName: 'getProcessInfo', namespaceURI: PMAPI_NS},189 {pid: pidQName})190 .then(function(response) {191 deferred.resolve(mapProcessInfo(response.xpath('//process-info')));192 }, function(fault) {193 deferred.reject(fault);194 });195 return deferred.promise;196 };197 /**198 * Retire a process.199 * @param pid identifier of the process to retire200 * @param {boolean} retired retired or not?201 * @return {@link ProcessInfoDocument} reflecting the modification202 */203 ps.setRetired = function (pid, retired) {204 var pidQName = SoapService.parseQNameStr(pid);205 pidQName.prefix = 'pns';206 return SoapService.callSOAP(PMAPI_ENDPOINT,207 {localName: 'setRetired', namespaceURI: PMAPI_NS},208 {pid: pidQName, retired: retired});209 };210 211 /**212 * Deploy a package213 * @param {string} packageName the package name.214 * @param {string} zip the package zip in Base64 encoding215 * @return {Promise} a promise for this request.216 */217 ps.deployPackage = function (packageName, zip) {218 return SoapService.callSOAP(DSAPI_ENDPOINT,219 {localName: 'deploy', namespaceURI: PMAPI_NS},220 {name: packageName,221 'package': '<dep:zip xmlns:dep="http://www.apache.org/ode/deployapi">' + zip + '</dep:zip>'});222 };223 if (POLLING_INTERVAL > 0) {224 $interval(ps.getPackages, POLLING_INTERVAL);225 }226 /**227 * Undeploy a package228 * @param {string} paid the package name.229 * @return {Promise} a promise for this request.230 */231 ps.undeployPackage = function (paid) {232 return SoapService.callSOAP(DSAPI_ENDPOINT,233 {localName: 'undeploy', namespaceURI: PMAPI_NS},234 {packageName: paid});235 };236 if (POLLING_INTERVAL > 0) {237 $interval(ps.getPackages, POLLING_INTERVAL);238 }239 return ps;...
BaseCampaignSchemaElementPage.CampaignDesigner.js
Source:BaseCampaignSchemaElementPage.CampaignDesigner.js
1/**2 * BaseCampaignSchemaElementPage edit page schema.3 * Parent: BaseProcessSchemaElementPropertiesPage.4 */5define("BaseCampaignSchemaElementPage", ["AcademyUtilities"], function() {6 return {7 attributes: {8 /**9 * Url of the academy page.10 */11 "AcademyUrl": {12 "dataValueType": this.Terrasoft.DataValueType.TEXT,13 "type": this.Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN14 }15 },16 properties: {17 /**18 * The container identifier for campaign element properties.19 * @protected20 * @virtual21 * @type {String}22 */23 propertiesContainerSelector: "#schema-designer-properties-ct"24 },25 methods: {26 /**27 * @inheritdoc Terrasoft.BaseProcessSchemaElementPropertiesPage#init28 * @overridden29 */30 init: function() {31 this.callParent(arguments);32 this.initAcademyUrl(this.onAcademyUrlInitialized, this);33 },34 /**35 *36 * @private37 */38 onAcademyUrlInitialized: function() {39 this.initInfoText();40 },41 /**42 * Initializes information text.43 * @private44 */45 initInfoText: function() {46 var academyUrl = this.get("AcademyUrl");47 var informationText = this.get("Resources.Strings.ProcessInformationText");48 informationText = this.Ext.String.format(informationText, academyUrl);49 this.set("Resources.Strings.ProcessInformationText", informationText);50 },51 /**52 * Returns code of the context help.53 * @return {String}54 * @protected55 */56 getContextHelpCode: this.Ext.emptyFn,57 /**58 * Initializes url to the academy.59 * @param {Function} callback The callback function.60 * @param {Object} scope The callback execution context.61 * @private62 */63 initAcademyUrl: function(callback, scope) {64 Terrasoft.AcademyUtilities.getUrl({65 contextHelpCode: this.getContextHelpCode(),66 callback: function(academyUrl) {67 this.set("AcademyUrl", academyUrl);68 this.Ext.callback(callback, scope);69 },70 scope: this71 });72 },73 /**74 * Saves validation results75 * @return Boolean76 */77 saveValidationResults: function() {78 var validationInfo = this.validationInfo;79 var processElement = this.get("ProcessElement");80 processElement.validationResults = [];81 Terrasoft.each(this.columns, function(column, columnName) {82 var columnValidationResult = validationInfo.get(columnName);83 if (columnValidationResult && !columnValidationResult.isValid) {84 this._saveValidationResult(columnValidationResult);85 }86 }, this);87 var customValidationResults = validationInfo.get("customValidationResults");88 Terrasoft.each(customValidationResults, this._saveValidationResult, this);89 var isElementValid = this.isElementValid(processElement.validationResults);90 processElement.setPropertyValue("isValidateExecuted", true, {91 silent: true92 });93 processElement.setPropertyValue("isValid", isElementValid, {94 silent: !isElementValid95 });96 return isElementValid;97 },98 /**99 * Adds properties page validation result to campaign schema element validationResults property.100 * @param {Object} validationResult Page validation result.101 * - isValid {Boolean} Validation result.102 * - invalidMessage {String} Control validation message.103 * - fullInvalidMessage {String} Full validation message text.104 * - validationType {Terrasoft.ValidationType} Validation type.105 * @private106 */107 _saveValidationResult: function(validationResult) {108 var processElement = this.get("ProcessElement");109 var validationType = validationResult.validationType || Terrasoft.ValidationType.ERROR;110 if (!validationResult.isValid) {111 processElement.validationResults.push({112 validationType: validationType,113 message: validationResult.fullInvalidMessage || validationResult.invalidMessage,114 propertyName: validationResult.propertyName,115 isCustomMessage: validationResult.isCustomMessage116 });117 }118 },119 /**120 * Returns lookup config for open lookup.121 * @return {Object} lookupConfig Resut config for open lookup.122 * @protected123 */124 getLookupConfig: function() {125 var config = {126 hideActions: true,127 settingsButtonVisible: false,128 multiSelect: false129 };130 return config;131 },132 /**133 * Displays default messageBox with specific message content.134 * @protected135 * @param {String} caption Caption of MeaasgeBox.136 * @param {String} message Message that displays inside message block.137 * @param {Array} currentButtons Collection of MessageBox buttons to display.138 * @param {Function} handler Callback function to call when messageBox will be closed.139 * @param {Object} scope Context.140 */141 showMessageBox: function(caption, message, currentButtons, handler, scope) {142 Terrasoft.ProcessSchemaDesignerUtilities.showProcessMessageBox({143 caption: caption,144 message: message,145 buttons: currentButtons,146 defaultButton: 0,147 handler: handler,148 scope: scope149 });150 },151 /**152 * Loads element properties page mask.153 * @protected154 */155 loadPropertiesPageMask: function() {156 return this.showBodyMask({157 selector: this.propertiesContainerSelector,158 opacity: 0.5,159 showHidden: true,160 clearMasks: true161 });162 },163 /**164 * @inheritdoc BaseProcessSchemaElementPropertiesPage#getLookupPageConfig165 * @overridden166 */167 getLookupPageConfig: function() {168 var config = this.callParent(arguments);169 config.hideActions = true;170 config.settingsButtonVisible = false;171 return config;172 },173 /**174 * @inheritdoc BaseProcessSchemaElementPropertiesPage#getIsSerializeToDBVisible175 * @overridden176 */177 getIsSerializeToDBVisible: function() {178 return false;179 },180 /**181 * @inheritdoc BaseProcessSchemaElementPropertiesPage#getIsLoggingVisible182 * @overridden183 */184 getIsLoggingVisible: function() {185 return false;186 }187 },188 diff: /**SCHEMA_DIFF*/[189 {190 "operation": "merge",191 "name": "TopContainer",192 "parentName": "HeaderContainer",193 "values": {194 "wrapClass": ["top-container-wrapClass", "control-width-15"]195 }196 },197 {198 "operation": "remove",199 "parentName": "ToolsContainer",200 "name": "ToolsButton"201 }202 ]/**SCHEMA_DIFF*/203 };...
DOMNodeHashTest.js
Source:DOMNodeHashTest.js
...32 c1.setAttribute('two', '2');33 var c2 = doc.createElement('c');34 c2.setAttribute('two', '2');35 c2.setAttribute('one', '1');36 dh1.processElement(c1, hash1);37 dh2.processElement(c2, hash2);38 test.equals(hash1.get(), hash2.get());39 test.done();40}41exports['should return same hash if qualified element names are equal'] = function(test) {42 var dh1 = new domtree.DOMNodeHash();43 var dh2 = new domtree.DOMNodeHash();44 var dh3 = new domtree.DOMNodeHash();45 var dh4 = new domtree.DOMNodeHash();46 var hash1 = new fnv132.Hash();47 var hash2 = new fnv132.Hash();48 var hash3 = new fnv132.Hash();49 var hash4 = new fnv132.Hash();50 var c1 = doc.createElementNS('urn:test', 'pfx1:c');51 var c2 = doc.createElementNS('urn:test', 'pfx2:c');52 var c3 = doc.createElementNS('urn:test', 'c');53 var c4 = doc.createElement('c');54 dh1.processElement(c1, hash1);55 dh2.processElement(c2, hash2);56 dh3.processElement(c3, hash3);57 dh4.processElement(c3, hash4);58 test.equals(hash1.get(), hash2.get());59 test.equals(hash1.get(), hash3.get());60 test.equals(hash1.get(), hash4.get());61 test.done();62}63exports['should return different hash if element namespace uris differ'] = function(test) {64 var dh1 = new domtree.DOMNodeHash();65 var dh2 = new domtree.DOMNodeHash();66 var dh3 = new domtree.DOMNodeHash();67 var hash1 = new fnv132.Hash();68 var hash2 = new fnv132.Hash();69 var hash3 = new fnv132.Hash();70 var c1 = doc.createElementNS('urn:test1', 'pfx:c');71 var c2 = doc.createElementNS('urn:test2', 'pfx:c');72 var c3 = doc.createElementNS('urn:test3', 'c');73 dh1.processElement(c1, hash1);74 dh2.processElement(c2, hash2);75 dh2.processElement(c3, hash3);76 test.notEqual(hash1.get(), hash2.get());77 test.notEqual(hash1.get(), hash3.get());78 test.done();79}80exports['should return same hash if qualified attribute names are equal'] = function(test) {81 var dh1 = new domtree.DOMNodeHash();82 var dh2 = new domtree.DOMNodeHash();83 var dh3 = new domtree.DOMNodeHash();84 var hash1 = new fnv132.Hash();85 var hash2 = new fnv132.Hash();86 var hash3 = new fnv132.Hash();87 var c1 = doc.createAttributeNS('urn:test', 'pfx1:c');88 var c2 = doc.createAttributeNS('urn:test', 'pfx2:c');89 var c3 = doc.createAttributeNS('urn:test', 'c');...
Preprocessor.js
Source:Preprocessor.js
...9import map from 'lodash/map';10import * as contains from './contains';11import * as has from './has';12import * as is from './is';13function processElement(refract) {14 if (refract.cache) {15 // This item has already been preprocessed!16 // You can force reprocessing by deleting `refract.cache`.17 return;18 }19 // First, set various things on the element20 has.defaultValue(refract);21 has.samples(refract);22 has.description(refract);23 is.arrayType(refract);24 is.enumType(refract);25 is.selectType(refract);26 is.objectType(refract);27 is.included(refract);28 is.inherited(refract);29 is.structured(refract);30 is.referenced(refract);31 // Then, see if it has children and process each of the children as well!32 if (refract.content) {33 if (refract.element === 'member' && refract.content.value) {34 // This is a member of an object35 processElement(refract.content.value);36 } else if (refract.content.length && refract.content[0].element) {37 // This is an array of items38 for (const item of refract.content) {39 processElement(item);40 }41 }42 }43 // This must be done *AFTER* all children are processed, because it44 // depends on values set in the loop above.45 contains.structuredElement(refract);46 // Then, see if it the element has any samples and process them as well!47 if (refract.attributes && !isEmpty(refract.attributes.samples)) {48 refract.attributes.samples = map(refract.attributes.samples, (sample) => {49 if (isArray(sample)) {50 return map(sample, (sampleElement) => {51 processElement(sampleElement);52 return sampleElement;53 });54 }55 if (isObject(sample)) {56 processElement(sample);57 return sample;58 }59 return sample;60 });61 }62 if (refract.attributes && refract.attributes.default) {63 processElement(refract.attributes.default);64 }65}66export class Preprocessor {67 constructor(refract) {68 this.refract = refract;69 }70 process() {71 processElement(this.refract);72 return this;73 }74 value() {75 return this.refract;76 }77 /*78 * Sorts inherited members either as the first members or the last members.79 * This sort is stable. Passing `head` as `true` puts inherited members first,80 * otherwise they go last.81 */82 sortInherited(head = true) {83 if (this.refract && this.refract.content && this.refract.content.length) {84 const inherited = [];85 const others = [];...
index.js
Source:index.js
...3 /*console.log('pre',pre);4 console.log('next',next);5 console.log('dom',dom);*/6 if(!pre || !next || !dom){7 return processElement(next);8 }9 let preType = typeof pre;10 let nextType = typeof next;11 if((preType === 'string' || preType === 'number') && (nextType === 'string' || nextType === 'number')){12 let text = String(next);13 if(text === String(pre)){14 console.log("unchange dom",dom);15 return dom;16 }else if(dom && dom.nodeType == 3){17 dom.textContent = text;18 return dom;19 }else return document.createTextNode(text);20 }21 if(nextType != preType){22 return processElement(next);23 }24 if(nextType === 'object'){25 if(pre.type != next.type){26 if(pre.type === 'function'){27 if(pre.type.prototype.componentWillUnmount) {28 pre.type.prototype.componentWillUnmount();29 }30 if(pre.type.prototype.componnentDidUnmount){31 pre.type.prototype.componentDidUnmount();32 }33 }34 return processElement(next);35 }36 if(typeof next.type === 'function'){37 if(pre.type.prototype.componentWillUnmount){38 pre.type.prototype.componentWillUnmount();39 }40 if(pre.type.prototype.componnentDidUnmount){41 pre.type.prototype.componentDidUnmount();42 }43 return processElement(next);44 }45 if(typeof next.type === 'string') {46 dom = diffAttrs(pre,next,dom);47 let preChildren = pre.children;48 let nextChildren = next.children;49 let domChildren = dom.childNodes;50 let childrenLength = Math.max(preChildren.length,nextChildren.length,domChildren.length);51 for( let i=0;i< childrenLength;i++ ){52 /*console.log(preChildren[i]);53 console.log(nextChildren[i]);54 console.log(domChildren[i]);*/55 let child = diff(preChildren[i],nextChildren[i],domChildren[i]);56 commit(dom,child,domChildren[i]);57 }...
util.js
Source:util.js
...7var _symbol = require('../symbol');8var _symbol2 = _interopRequireDefault(_symbol);9var _util = require('../../util');10function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }11var processElement = exports.processElement = function processElement(execution, item) {12 if (execution && item instanceof _expressions.SExpression) return item.run();13 if (execution && item instanceof _symbol2.default) return item.value;14 return item;15};16var executeElement = exports.executeElement = processElement.bind(processElement, true);17var processList = exports.processList = function processList(list) {18 if (list.length === 1 && (list[0].length !== undefined && typeof list[0] !== 'string' || list[0] instanceof _symbol2.default)) {19 list = list[0] instanceof _symbol2.default ? list[0].value : list[0];20 }21 if (list instanceof _expressions.SExpression) {22 list = list.run();23 }24 return (0, _util.toArray)(list).map(processElement.bind(null, !(list instanceof _expressions.QExpression)));25};
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 await page.click('text=Sign in');6 await page.waitForTimeout(10000);7 const element = await page.$('input[type="email"]');8 await page.evaluate(element => element.focus(), element);9 await page.keyboard.type('test');10 await browser.close();11})();
Using AI Code Generation
1const { chromium } = require('playwright');2const { processElement } = require('playwright/lib/server/dom.js');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const element = await page.$('input[name="q"]');8 const result = await processElement(element, 'focus');9 console.log(result);10 await browser.close();11})();
Using AI Code Generation
1const { processElement } = require('playwright/lib/client/elementHandler');2const { ElementHandle } = require('playwright/lib/client/elementHandle');3const { Page } = require('playwright/lib/client/page');4const page = new Page();5const element = new ElementHandle(page, 'elementId');6const result = await processElement(element, 'click');7console.log(result);8const { processElement } = require('playwright/lib/client/elementHandler');9const { ElementHandle } = require('playwright/lib/client/elementHandle');10const { Page } = require('playwright/lib/client/page');11const page = new Page();12const element = new ElementHandle(page, 'elementId');
Using AI Code Generation
1const { PlaywrightInternal } = require("playwright");2const { Page } = require("playwright");3const { ElementHandle } = require("playwright");4const { BrowserContext } = require("playwright");5const { Browser } = require("playwright");6const { ChromiumBrowserContext } = require("playwright");7const { WebKitBrowserContext } = require("playwright");8const { FirefoxBrowserContext } = require("playwright");9const { chromium } = require("playwright");10(async () => {11 const browser = await chromium.launch();12 const context = await browser.newContext();13 const page = await context.newPage();14 const elementHandle = await page.$("text=Get started");15 const internal = new PlaywrightInternal(page);16 const result = await internal.processElement(elementHandle, (element) => {17 return element.textContent;18 });19 console.log(result);20 await browser.close();21})();
Using AI Code Generation
1await page._client.send('DOM.processElement', { elementId: elementHandle._remoteObject.objectId });2await page._client.send('DOM.processElement', { elementId: elementHandle._remoteObject.objectId });3await page._client.send('DOM.processElement', { elementId: elementHandle._remoteObject.objectId });4await page._client.send('DOM.processElement', { elementId: elementHandle._remoteObject.objectId });5await page._client.send('DOM.processElement', { elementId: elementHandle._remoteObject.objectId });6await page._client.send('DOM.processElement', { elementId: elementHandle._remoteObject.objectId });7await page._client.send('DOM.processElement', { elementId: elementHandle._remoteObject.objectId });8await page._client.send('DOM.processElement', { elementId: elementHandle._remoteObject.objectId });9await page._client.send('DOM.processElement', { elementId: elementHandle._remoteObject.objectId });10await page._client.send('DOM.processElement', { elementId: elementHandle._remoteObject.objectId });11await page._client.send('DOM.processElement', { elementId: elementHandle._remoteObject.objectId });12await page._client.send('DOM.processElement', { elementId: elementHandle._remoteObject.objectId });
Using AI Code Generation
1const { processElement } = require('playwright/lib/server/frames');2const { Frame } = require('playwright/lib/server/supplements/frames');3const { processElement } = require('playwright/lib/server/frames');4const { Frame } = require('playwright/lib/server/supplements/frames');5const { processElement } = require('playwright/lib/server/frames');6const { Frame } = require('playwright/lib/server/supplements/frames');7const { processElement } = require('playwright/lib/server/frames');8const { Frame } = require('playwright/lib/server/supplements/frames');9const { processElement } = require('playwright/lib/server/frames');10const { Frame } = require('playwright/lib/server/supplements/frames');11const { processElement } = require('playwright/lib/server/frames');12const { Frame } = require('playwright/lib/server/supplements/frames');13const { processElement } = require('playwright/lib/server/frames');14const { Frame } = require('playwright/lib/server/supplements/frames');15const { processElement } = require('playwright/lib/server/frames');16const { Frame } = require('playwright/lib/server/supplements/frames');17const { processElement } = require('playwright/lib/server/frames');18const { Frame } = require('playwright/lib/server/supplements/frames');19const { processElement } = require('playwright/lib/server/frames');20const { Frame } = require('playwright/lib/server/supplements/frames');21const { processElement } = require('playwright/lib/server/frames');22const { Frame } = require('playwright/lib/server/supplements/frames');23const {
Using AI Code Generation
1const { processElement } = require('playwright/lib/client/selectorEngine');2const elementHandle = await page.$('button')3const selector = processElement(elementHandle);4console.log(selector)5const { processSelector } = require('playwright/lib/client/selectorEngine');6const selector = processSelector('button');7console.log(selector)8const { processSelector } = require('playwright/lib/client/selectorEngine');9const selector = processSelector('button');10console.log(selector)11const { processSelector } = require('playwright/lib/client/selectorEngine');12const selector = processSelector('button');13console.log(selector)14const { processSelector } = require('playwright/lib/client/selectorEngine');15const selector = processSelector('button');16console.log(selector)17const { processSelector } = require('playwright/lib/client/selectorEngine');18const selector = processSelector('button');19console.log(selector)20const { processSelector } = require('playwright/lib/client/selectorEngine');21const selector = processSelector('button');22console.log(selector)23const { processSelector } = require('playwright/lib/client/selectorEngine');
Using AI Code Generation
1const { processElement } = require('playwright/lib/client/selectorEngine');2processElement({3}, (element, done) => {4 done(element);5});6const { processSelector } = require('playwright/lib/client/selectorEngine');7processSelector({8}, (element, done) => {9 done(element);10});11const { processAll } = require('playwright/lib/client/selectorEngine');12processAll({13}, (element, done) => {14 done(element);15});16const { processAll } = require('playwright/lib/client/selectorEngine');17processAll({18}, (element, done) => {19 done(element);20});21const { processAll } = require('playwright/lib/client/selectorEngine');22processAll({23}, (element, done) => {24 done(element);25});26const { processAll } = require('playwright/lib/client/selectorEngine');27processAll({28}, (element, done) => {29 done(element);30});31const { processAll } = require('playwright/lib/client/selectorEngine');32processAll({33}, (element, done) => {34 done(element);35});36const { processAll } = require('playwright/lib/client/selectorEngine');37processAll({38}, (element, done) => {
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!