Best JavaScript code snippet using playwright-internal
scorm_12.js
Source:scorm_12.js
1// This file is part of Moodle - http://moodle.org/2//3// Moodle is free software: you can redistribute it and/or modify4// it under the terms of the GNU General Public License as published by5// the Free Software Foundation, either version 3 of the License, or6// (at your option) any later version.7//8// Moodle is distributed in the hope that it will be useful,9// but WITHOUT ANY WARRANTY; without even the implied warranty of10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11// GNU General Public License for more details.12//13// You should have received a copy of the GNU General Public License14// along with Moodle. If not, see <http://www.gnu.org/licenses/>.15//16// SCORM 1.2 API Implementation17//18function SCORMapi1_2(def, cmiobj, cmiint, cmistring256, cmistring4096, scormdebugging, scormauto, scormid, cfgwwwroot, sesskey, scoid, attempt, viewmode, cmid, currentorg, autocommit) {19 var prerequrl = cfgwwwroot + "/mod/scorm/prereqs.php?a=" + scormid + "&scoid=" + scoid + "&attempt=" + attempt + "&mode=" + viewmode + "¤torg=" + currentorg + "&sesskey=" + sesskey;20 var datamodelurl = cfgwwwroot + "/mod/scorm/datamodel.php";21 var datamodelurlparams = "id=" + cmid + "&a=" + scormid + "&sesskey=" + sesskey + "&attempt=" + attempt + "&scoid=" + scoid;22 // Standard Data Type Definition23 CMIString256 = cmistring256;24 CMIString4096 = cmistring4096;25 CMITime = '^([0-2]{1}[0-9]{1}):([0-5]{1}[0-9]{1}):([0-5]{1}[0-9]{1})(\.[0-9]{1,2})?$';26 CMITimespan = '^([0-9]{2,4}):([0-9]{2}):([0-9]{2})(\.[0-9]{1,2})?$';27 CMIInteger = '^\\d+$';28 CMISInteger = '^-?([0-9]+)$';29 CMIDecimal = '^-?([0-9]{0,3})(\.[0-9]*)?$';30 CMIIdentifier = '^[\\u0021-\\u007E]{0,255}$';31 CMIFeedback = CMIString256; // This must be redefined32 CMIIndex = '[._](\\d+).';33 // Vocabulary Data Type Definition34 CMIStatus = '^passed$|^completed$|^failed$|^incomplete$|^browsed$';35 CMIStatus2 = '^passed$|^completed$|^failed$|^incomplete$|^browsed$|^not attempted$';36 CMIExit = '^time-out$|^suspend$|^logout$|^$';37 CMIType = '^true-false$|^choice$|^fill-in$|^matching$|^performance$|^sequencing$|^likert$|^numeric$';38 CMIResult = '^correct$|^wrong$|^unanticipated$|^neutral$|^([0-9]{0,3})?(\.[0-9]*)?$';39 NAVEvent = '^previous$|^continue$';40 // Children lists41 cmi_children = 'core,suspend_data,launch_data,comments,objectives,student_data,student_preference,interactions';42 core_children = 'student_id,student_name,lesson_location,credit,lesson_status,entry,score,total_time,lesson_mode,exit,session_time';43 score_children = 'raw,min,max';44 comments_children = 'content,location,time';45 objectives_children = 'id,score,status';46 correct_responses_children = 'pattern';47 student_data_children = 'mastery_score,max_time_allowed,time_limit_action';48 student_preference_children = 'audio,language,speed,text';49 interactions_children = 'id,objectives,time,type,correct_responses,weighting,student_response,result,latency';50 // Data ranges51 score_range = '0#100';52 audio_range = '-1#100';53 speed_range = '-100#100';54 weighting_range = '-100#100';55 text_range = '-1#1';56 // The SCORM 1.2 data model57 // Set up data model for each sco58 var datamodel = {};59 for(scoid in def){60 datamodel[scoid] = {61 'cmi._children':{'defaultvalue':cmi_children, 'mod':'r', 'writeerror':'402'},62 'cmi._version':{'defaultvalue':'3.4', 'mod':'r', 'writeerror':'402'},63 'cmi.core._children':{'defaultvalue':core_children, 'mod':'r', 'writeerror':'402'},64 'cmi.core.student_id':{'defaultvalue':def[scoid]['cmi.core.student_id'], 'mod':'r', 'writeerror':'403'},65 'cmi.core.student_name':{'defaultvalue':def[scoid]['cmi.core.student_name'], 'mod':'r', 'writeerror':'403'},66 'cmi.core.lesson_location':{'defaultvalue':def[scoid]['cmi.core.lesson_location'], 'format':CMIString256, 'mod':'rw', 'writeerror':'405'},67 'cmi.core.credit':{'defaultvalue':def[scoid]['cmi.core.credit'], 'mod':'r', 'writeerror':'403'},68 'cmi.core.lesson_status':{'defaultvalue':def[scoid]['cmi.core.lesson_status'], 'format':CMIStatus, 'mod':'rw', 'writeerror':'405'},69 'cmi.core.entry':{'defaultvalue':def[scoid]['cmi.core.entry'], 'mod':'r', 'writeerror':'403'},70 'cmi.core.score._children':{'defaultvalue':score_children, 'mod':'r', 'writeerror':'402'},71 'cmi.core.score.raw':{'defaultvalue':def[scoid]['cmi.core.score.raw'], 'format':CMIDecimal, 'range':score_range, 'mod':'rw', 'writeerror':'405'},72 'cmi.core.score.max':{'defaultvalue':def[scoid]['cmi.core.score.max'], 'format':CMIDecimal, 'range':score_range, 'mod':'rw', 'writeerror':'405'},73 'cmi.core.score.min':{'defaultvalue':def[scoid]['cmi.core.score.min'], 'format':CMIDecimal, 'range':score_range, 'mod':'rw', 'writeerror':'405'},74 'cmi.core.total_time':{'defaultvalue':def[scoid]['cmi.core.total_time'], 'mod':'r', 'writeerror':'403'},75 'cmi.core.lesson_mode':{'defaultvalue':def[scoid]['cmi.core.lesson_mode'], 'mod':'r', 'writeerror':'403'},76 'cmi.core.exit':{'defaultvalue':def[scoid]['cmi.core.exit'], 'format':CMIExit, 'mod':'w', 'readerror':'404', 'writeerror':'405'},77 'cmi.core.session_time':{'format':CMITimespan, 'mod':'w', 'defaultvalue':'00:00:00', 'readerror':'404', 'writeerror':'405'},78 'cmi.suspend_data':{'defaultvalue':def[scoid]['cmi.suspend_data'], 'format':CMIString4096, 'mod':'rw', 'writeerror':'405'},79 'cmi.launch_data':{'defaultvalue':def[scoid]['cmi.launch_data'], 'mod':'r', 'writeerror':'403'},80 'cmi.comments':{'defaultvalue':def[scoid]['cmi.comments'], 'format':CMIString4096, 'mod':'rw', 'writeerror':'405'},81 // deprecated evaluation attributes82 'cmi.evaluation.comments._count':{'defaultvalue':'0', 'mod':'r', 'writeerror':'402'},83 'cmi.evaluation.comments._children':{'defaultvalue':comments_children, 'mod':'r', 'writeerror':'402'},84 'cmi.evaluation.comments.n.content':{'defaultvalue':'', 'pattern':CMIIndex, 'format':CMIString256, 'mod':'rw', 'writeerror':'405'},85 'cmi.evaluation.comments.n.location':{'defaultvalue':'', 'pattern':CMIIndex, 'format':CMIString256, 'mod':'rw', 'writeerror':'405'},86 'cmi.evaluation.comments.n.time':{'defaultvalue':'', 'pattern':CMIIndex, 'format':CMITime, 'mod':'rw', 'writeerror':'405'},87 'cmi.comments_from_lms':{'mod':'r', 'writeerror':'403'},88 'cmi.objectives._children':{'defaultvalue':objectives_children, 'mod':'r', 'writeerror':'402'},89 'cmi.objectives._count':{'mod':'r', 'defaultvalue':'0', 'writeerror':'402'},90 'cmi.objectives.n.id':{'pattern':CMIIndex, 'format':CMIIdentifier, 'mod':'rw', 'writeerror':'405'},91 'cmi.objectives.n.score._children':{'pattern':CMIIndex, 'mod':'r', 'writeerror':'402'},92 'cmi.objectives.n.score.raw':{'defaultvalue':'', 'pattern':CMIIndex, 'format':CMIDecimal, 'range':score_range, 'mod':'rw', 'writeerror':'405'},93 'cmi.objectives.n.score.min':{'defaultvalue':'', 'pattern':CMIIndex, 'format':CMIDecimal, 'range':score_range, 'mod':'rw', 'writeerror':'405'},94 'cmi.objectives.n.score.max':{'defaultvalue':'', 'pattern':CMIIndex, 'format':CMIDecimal, 'range':score_range, 'mod':'rw', 'writeerror':'405'},95 'cmi.objectives.n.status':{'pattern':CMIIndex, 'format':CMIStatus2, 'mod':'rw', 'writeerror':'405'},96 'cmi.student_data._children':{'defaultvalue':student_data_children, 'mod':'r', 'writeerror':'402'},97 'cmi.student_data.mastery_score':{'defaultvalue':def[scoid]['cmi.student_data.mastery_score'], 'mod':'r', 'writeerror':'403'},98 'cmi.student_data.max_time_allowed':{'defaultvalue':def[scoid]['cmi.student_data.max_time_allowed'], 'mod':'r', 'writeerror':'403'},99 'cmi.student_data.time_limit_action':{'defaultvalue':def[scoid]['cmi.student_data.time_limit_action'], 'mod':'r', 'writeerror':'403'},100 'cmi.student_preference._children':{'defaultvalue':student_preference_children, 'mod':'r', 'writeerror':'402'},101 'cmi.student_preference.audio':{'defaultvalue':def[scoid]['cmi.student_preference.audio'], 'format':CMISInteger, 'range':audio_range, 'mod':'rw', 'writeerror':'405'},102 'cmi.student_preference.language':{'defaultvalue':def[scoid]['cmi.student_preference.language'], 'format':CMIString256, 'mod':'rw', 'writeerror':'405'},103 'cmi.student_preference.speed':{'defaultvalue':def[scoid]['cmi.student_preference.speed'], 'format':CMISInteger, 'range':speed_range, 'mod':'rw', 'writeerror':'405'},104 'cmi.student_preference.text':{'defaultvalue':def[scoid]['cmi.student_preference.text'], 'format':CMISInteger, 'range':text_range, 'mod':'rw', 'writeerror':'405'},105 'cmi.interactions._children':{'defaultvalue':interactions_children, 'mod':'r', 'writeerror':'402'},106 'cmi.interactions._count':{'mod':'r', 'defaultvalue':'0', 'writeerror':'402'},107 'cmi.interactions.n.id':{'pattern':CMIIndex, 'format':CMIIdentifier, 'mod':'w', 'readerror':'404', 'writeerror':'405'},108 'cmi.interactions.n.objectives._count':{'pattern':CMIIndex, 'mod':'r', 'defaultvalue':'0', 'writeerror':'402'},109 'cmi.interactions.n.objectives.n.id':{'pattern':CMIIndex, 'format':CMIIdentifier, 'mod':'w', 'readerror':'404', 'writeerror':'405'},110 'cmi.interactions.n.time':{'pattern':CMIIndex, 'format':CMITime, 'mod':'w', 'readerror':'404', 'writeerror':'405'},111 'cmi.interactions.n.type':{'pattern':CMIIndex, 'format':CMIType, 'mod':'w', 'readerror':'404', 'writeerror':'405'},112 'cmi.interactions.n.correct_responses._count':{'pattern':CMIIndex, 'mod':'r', 'defaultvalue':'0', 'writeerror':'402'},113 'cmi.interactions.n.correct_responses.n.pattern':{'pattern':CMIIndex, 'format':CMIFeedback, 'mod':'w', 'readerror':'404', 'writeerror':'405'},114 'cmi.interactions.n.weighting':{'pattern':CMIIndex, 'format':CMIDecimal, 'range':weighting_range, 'mod':'w', 'readerror':'404', 'writeerror':'405'},115 'cmi.interactions.n.student_response':{'pattern':CMIIndex, 'format':CMIFeedback, 'mod':'w', 'readerror':'404', 'writeerror':'405'},116 'cmi.interactions.n.result':{'pattern':CMIIndex, 'format':CMIResult, 'mod':'w', 'readerror':'404', 'writeerror':'405'},117 'cmi.interactions.n.latency':{'pattern':CMIIndex, 'format':CMITimespan, 'mod':'w', 'readerror':'404', 'writeerror':'405'},118 'nav.event':{'defaultvalue':'', 'format':NAVEvent, 'mod':'w', 'readerror':'404', 'writeerror':'405'}119 };120 }121 var cmi, nav;122 function initdatamodel(scoid){123 prerequrl = cfgwwwroot + "/mod/scorm/prereqs.php?a=" + scormid + "&scoid=" + scoid + "&attempt=" + attempt + "&mode=" + viewmode + "¤torg=" + currentorg + "&sesskey=" + sesskey;124 datamodelurlparams = "id=" + cmid + "&a=" + scormid + "&sesskey=" + sesskey + "&attempt=" + attempt + "&scoid=" + scoid;125 //126 // Datamodel inizialization127 //128 cmi = new Object();129 cmi.core = new Object();130 cmi.core.score = new Object();131 cmi.objectives = new Object();132 cmi.student_data = new Object();133 cmi.student_preference = new Object();134 cmi.interactions = new Object();135 // deprecated evaluation attributes136 cmi.evaluation = new Object();137 cmi.evaluation.comments = new Object();138 // Navigation Object139 nav = new Object();140 for (element in datamodel[scoid]) {141 if (element.match(/\.n\./) == null) {142 if ((typeof eval('datamodel["' + scoid + '"]["' + element + '"].defaultvalue')) != 'undefined') {143 eval(element + ' = datamodel["' + scoid + '"]["' + element + '"].defaultvalue;');144 } else {145 eval(element + ' = "";');146 }147 }148 }149 eval(cmiobj[scoid]);150 eval(cmiint[scoid]);151 if (cmi.core.lesson_status == '') {152 cmi.core.lesson_status = 'not attempted';153 }154 }155 //156 // API Methods definition157 //158 var Initialized = false;159 function LMSInitialize (param) {160 scoid = scorm_current_node ? scorm_current_node.scoid : scoid;161 initdatamodel(scoid);162 errorCode = "0";163 if (param == "") {164 if (!Initialized) {165 Initialized = true;166 errorCode = "0";167 if (scormdebugging) {168 LogAPICall("LMSInitialize", param, "", errorCode);169 }170 return "true";171 } else {172 errorCode = "101";173 }174 } else {175 errorCode = "201";176 }177 if (scormdebugging) {178 LogAPICall("LMSInitialize", param, "", errorCode);179 }180 return "false";181 }182 function LMSFinish (param) {183 errorCode = "0";184 if (param == "") {185 if (Initialized) {186 Initialized = false;187 result = StoreData(cmi,true);188 if (nav.event != '') {189 if (nav.event == 'continue') {190 setTimeout('mod_scorm_launch_next_sco();',500);191 } else {192 setTimeout('mod_scorm_launch_prev_sco();',500);193 }194 } else {195 if (scormauto == 1) {196 setTimeout('mod_scorm_launch_next_sco();',500);197 }198 }199 if (scormdebugging) {200 LogAPICall("LMSFinish", "AJAXResult", result, 0);201 }202 result = ('true' == result) ? 'true' : 'false';203 errorCode = (result == 'true') ? '0' : '101';204 if (scormdebugging) {205 LogAPICall("LMSFinish", "result", result, 0);206 LogAPICall("LMSFinish", param, "", 0);207 }208 // trigger TOC update209 var callback = M.mod_scorm.connectPrereqCallback;210 YUI().use('io-base', function(Y) {211 Y.on('io:complete', callback.success, Y);212 Y.io(prerequrl);213 });214 return result;215 } else {216 errorCode = "301";217 }218 } else {219 errorCode = "201";220 }221 if (scormdebugging) {222 LogAPICall("LMSFinish", param, "", errorCode);223 }224 return "false";225 }226 function LMSGetValue (element) {227 errorCode = "0";228 if (Initialized) {229 if (element != "") {230 expression = new RegExp(CMIIndex,'g');231 elementmodel = String(element).replace(expression,'.n.');232 if ((typeof eval('datamodel["' + scoid + '"]["' + elementmodel + '"]')) != "undefined") {233 if (eval('datamodel["' + scoid + '"]["' + elementmodel + '"].mod') != 'w') {234 element = String(element).replace(expression, "_$1.");235 elementIndexes = element.split('.');236 subelement = 'cmi';237 i = 1;238 while ((i < elementIndexes.length) && (typeof eval(subelement) != "undefined")) {239 subelement += '.' + elementIndexes[i++];240 }241 if (subelement == element) {242 errorCode = "0";243 if (scormdebugging) {244 LogAPICall("LMSGetValue", element, eval(element), 0);245 }246 return eval(element);247 } else {248 errorCode = "0"; // Need to check if it is the right errorCode249 }250 } else {251 errorCode = eval('datamodel["' + scoid + '"]["' + elementmodel + '"].readerror');252 }253 } else {254 childrenstr = '._children';255 countstr = '._count';256 if (elementmodel.substr(elementmodel.length - childrenstr.length,elementmodel.length) == childrenstr) {257 parentmodel = elementmodel.substr(0,elementmodel.length - childrenstr.length);258 if ((typeof eval('datamodel["' + scoid + '"]["' + parentmodel + '"]')) != "undefined") {259 errorCode = "202";260 } else {261 errorCode = "201";262 }263 } else if (elementmodel.substr(elementmodel.length - countstr.length,elementmodel.length) == countstr) {264 parentmodel = elementmodel.substr(0,elementmodel.length - countstr.length);265 if ((typeof eval('datamodel["' + scoid + '"]["' + parentmodel + '"]')) != "undefined") {266 errorCode = "203";267 } else {268 errorCode = "201";269 }270 } else {271 errorCode = "201";272 }273 }274 } else {275 errorCode = "201";276 }277 } else {278 errorCode = "301";279 }280 if (scormdebugging) {281 LogAPICall("LMSGetValue", element, "", errorCode);282 }283 return "";284 }285 function LMSSetValue (element,value) {286 errorCode = "0";287 if (Initialized) {288 if (element != "") {289 expression = new RegExp(CMIIndex,'g');290 elementmodel = String(element).replace(expression,'.n.');291 if ((typeof eval('datamodel["' + scoid + '"]["' + elementmodel + '"]')) != "undefined") {292 if (eval('datamodel["' + scoid + '"]["' + elementmodel + '"].mod') != 'r') {293 expression = new RegExp(eval('datamodel["' + scoid + '"]["' + elementmodel + '"].format'));294 value = value + '';295 matches = value.match(expression);296 if (matches != null) {297 //Create dynamic data model element298 if (element != elementmodel) {299 elementIndexes = element.split('.');300 subelement = 'cmi';301 for (i = 1; i < elementIndexes.length - 1; i++) {302 elementIndex = elementIndexes[i];303 if (elementIndexes[i + 1].match(/^\d+$/)) {304 if ((typeof eval(subelement + '.' + elementIndex)) == "undefined") {305 eval(subelement + '.' + elementIndex + ' = new Object();');306 eval(subelement + '.' + elementIndex + '._count = 0;');307 }308 if (elementIndexes[i + 1] == eval(subelement + '.' + elementIndex + '._count')) {309 eval(subelement + '.' + elementIndex + '._count++;');310 }311 if (elementIndexes[i + 1] > eval(subelement + '.' + elementIndex + '._count')) {312 errorCode = "201";313 }314 subelement = subelement.concat('.' + elementIndex + '_' + elementIndexes[i + 1]);315 i++;316 } else {317 subelement = subelement.concat('.' + elementIndex);318 }319 if ((typeof eval(subelement)) == "undefined") {320 eval(subelement + ' = new Object();');321 if (subelement.substr(0,14) == 'cmi.objectives') {322 eval(subelement + '.score = new Object();');323 eval(subelement + '.score._children = score_children;');324 eval(subelement + '.score.raw = "";');325 eval(subelement + '.score.min = "";');326 eval(subelement + '.score.max = "";');327 }328 if (subelement.substr(0,16) == 'cmi.interactions') {329 eval(subelement + '.objectives = new Object();');330 eval(subelement + '.objectives._count = 0;');331 eval(subelement + '.correct_responses = new Object();');332 eval(subelement + '.correct_responses._count = 0;');333 }334 }335 }336 element = subelement.concat('.' + elementIndexes[elementIndexes.length - 1]);337 }338 //Store data339 if (errorCode == "0") {340 if (autocommit && !(SCORMapi1_2.timeout)) {341 SCORMapi1_2.timeout = Y.later(60000, API, 'LMSCommit', [""], false);342 }343 if ((typeof eval('datamodel["' + scoid + '"]["' + elementmodel + '"].range')) != "undefined") {344 range = eval('datamodel["' + scoid + '"]["' + elementmodel + '"].range');345 ranges = range.split('#');346 value = value * 1.0;347 if ((value >= ranges[0]) && (value <= ranges[1])) {348 eval(element + '=value;');349 errorCode = "0";350 if (scormdebugging) {351 LogAPICall("LMSSetValue", element, value, errorCode);352 }353 return "true";354 } else {355 errorCode = eval('datamodel["' + scoid + '"]["' + elementmodel + '"].writeerror');356 }357 } else {358 if (element == 'cmi.comments') {359 cmi.comments = cmi.comments + value;360 } else {361 eval(element + '=value;');362 }363 errorCode = "0";364 if (scormdebugging) {365 LogAPICall("LMSSetValue", element, value, errorCode);366 }367 return "true";368 }369 }370 } else {371 errorCode = eval('datamodel["' + scoid + '"]["' + elementmodel + '"].writeerror');372 }373 } else {374 errorCode = eval('datamodel["' + scoid + '"]["' + elementmodel + '"].writeerror');375 }376 } else {377 errorCode = "201"378 }379 } else {380 errorCode = "201";381 }382 } else {383 errorCode = "301";384 }385 if (scormdebugging) {386 LogAPICall("LMSSetValue", element, value, errorCode);387 }388 return "false";389 }390 function LMSCommit (param) {391 if (SCORMapi1_2.timeout) {392 SCORMapi1_2.timeout.cancel();393 SCORMapi1_2.timeout = null;394 }395 errorCode = "0";396 if (param == "") {397 if (Initialized) {398 result = StoreData(cmi,false);399 // trigger TOC update400 var callback = M.mod_scorm.connectPrereqCallback;401 YUI().use('io-base', function(Y) {402 Y.on('io:complete', callback.success, Y);403 Y.io(prerequrl);404 });405 if (scormdebugging) {406 LogAPICall("Commit", param, "", 0);407 }408 if (scormdebugging) {409 LogAPICall("LMSCommit", "AJAXResult", result, 0);410 }411 result = ('true' == result) ? 'true' : 'false';412 errorCode = (result == 'true') ? '0' : '101';413 if (scormdebugging) {414 LogAPICall("LMSCommit", "result", result, 0);415 LogAPICall("LMSCommit", "errorCode", errorCode, 0);416 }417 return result;418 } else {419 errorCode = "301";420 }421 } else {422 errorCode = "201";423 }424 if (scormdebugging) {425 LogAPICall("LMSCommit", param, "", 0);426 }427 return "false";428 }429 function LMSGetLastError () {430 if (scormdebugging) {431 LogAPICall("LMSGetLastError", "", "", errorCode);432 }433 return errorCode;434 }435 function LMSGetErrorString (param) {436 if (param != "") {437 var errorString = new Array();438 errorString["0"] = "No error";439 errorString["101"] = "General exception";440 errorString["201"] = "Invalid argument error";441 errorString["202"] = "Element cannot have children";442 errorString["203"] = "Element not an array - cannot have count";443 errorString["301"] = "Not initialized";444 errorString["401"] = "Not implemented error";445 errorString["402"] = "Invalid set value, element is a keyword";446 errorString["403"] = "Element is read only";447 errorString["404"] = "Element is write only";448 errorString["405"] = "Incorrect data type";449 if (scormdebugging) {450 LogAPICall("LMSGetErrorString", param, errorString[param], 0);451 }452 return errorString[param];453 } else {454 if (scormdebugging) {455 LogAPICall("LMSGetErrorString", param, "No error string found!", 0);456 }457 return "";458 }459 }460 function LMSGetDiagnostic (param) {461 if (param == "") {462 param = errorCode;463 }464 if (scormdebugging) {465 LogAPICall("LMSGetDiagnostic", param, param, 0);466 }467 return param;468 }469 function AddTime (first, second) {470 var sFirst = first.split(":");471 var sSecond = second.split(":");472 var cFirst = sFirst[2].split(".");473 var cSecond = sSecond[2].split(".");474 var change = 0;475 FirstCents = 0; //Cents476 if (cFirst.length > 1) {477 FirstCents = parseInt(cFirst[1],10);478 }479 SecondCents = 0;480 if (cSecond.length > 1) {481 SecondCents = parseInt(cSecond[1],10);482 }483 var cents = FirstCents + SecondCents;484 change = Math.floor(cents / 100);485 cents = cents - (change * 100);486 if (Math.floor(cents) < 10) {487 cents = "0" + cents.toString();488 }489 var secs = parseInt(cFirst[0],10) + parseInt(cSecond[0],10) + change; //Seconds490 change = Math.floor(secs / 60);491 secs = secs - (change * 60);492 if (Math.floor(secs) < 10) {493 secs = "0" + secs.toString();494 }495 mins = parseInt(sFirst[1],10) + parseInt(sSecond[1],10) + change; //Minutes496 change = Math.floor(mins / 60);497 mins = mins - (change * 60);498 if (mins < 10) {499 mins = "0" + mins.toString();500 }501 hours = parseInt(sFirst[0],10) + parseInt(sSecond[0],10) + change; //Hours502 if (hours < 10) {503 hours = "0" + hours.toString();504 }505 if (cents != '0') {506 return hours + ":" + mins + ":" + secs + '.' + cents;507 } else {508 return hours + ":" + mins + ":" + secs;509 }510 }511 function TotalTime() {512 total_time = AddTime(cmi.core.total_time, cmi.core.session_time);513 return '&' + underscore('cmi.core.total_time') + '=' + encodeURIComponent(total_time);514 }515 function CollectData(data,parent) {516 var datastring = '';517 for (property in data) {518 if (typeof data[property] == 'object') {519 datastring += CollectData(data[property],parent + '.' + property);520 } else {521 element = parent + '.' + property;522 expression = new RegExp(CMIIndex,'g');523 // get the generic name for this element (e.g. convert 'cmi.interactions.1.id' to 'cmi.interactions.n.id')524 elementmodel = String(element).replace(expression,'.n.');525 // ignore the session time element526 if (element != "cmi.core.session_time") {527 // check if this specific element is not defined in the datamodel,528 // but the generic element name is529 if ((eval('typeof datamodel["' + scoid + '"]["' + element + '"]')) == "undefined"530 && (eval('typeof datamodel["' + scoid + '"]["' + elementmodel + '"]')) != "undefined") {531 // add this specific element to the data model (by cloning532 // the generic element) so we can track changes to it533 eval('datamodel["' + scoid + '"]["' + element + '"]=CloneObj(datamodel["' + scoid + '"]["' + elementmodel + '"]);');534 }535 // check if the current element exists in the datamodel536 if ((typeof eval('datamodel["' + scoid + '"]["' + element + '"]')) != "undefined") {537 // make sure this is not a read only element538 if (eval('datamodel["' + scoid + '"]["' + element + '"].mod') != 'r') {539 elementstring = '&' + underscore(element) + '=' + encodeURIComponent(data[property]);540 // check if the element has a default value541 if ((typeof eval('datamodel["' + scoid + '"]["' + element + '"].defaultvalue')) != "undefined") {542 // check if the default value is different from the current value543 if (eval('datamodel["' + scoid + '"]["' + element + '"].defaultvalue') != data[property]544 || eval('typeof(datamodel["' + scoid + '"]["' + element + '"].defaultvalue)') != typeof(data[property])) {545 // append the URI fragment to the string we plan to commit546 datastring += elementstring;547 // update the element default to reflect the current committed value548 eval('datamodel["' + scoid + '"]["' + element + '"].defaultvalue=data[property];');549 }550 } else {551 // append the URI fragment to the string we plan to commit552 datastring += elementstring;553 // no default value for the element, so set it now554 eval('datamodel["' + scoid + '"]["' + element + '"].defaultvalue=data[property];');555 }556 }557 }558 }559 }560 }561 return datastring;562 }563 function CloneObj(obj){564 if(obj == null || typeof(obj) != 'object') {565 return obj;566 }567 var temp = new obj.constructor(); // changed (twice)568 for(var key in obj) {569 temp[key] = CloneObj(obj[key]);570 }571 return temp;572 }573 function StoreData(data,storetotaltime) {574 if (storetotaltime) {575 if (cmi.core.lesson_status == 'not attempted') {576 cmi.core.lesson_status = 'completed';577 }578 if (cmi.core.lesson_mode == 'normal') {579 if (cmi.core.credit == 'credit') {580 if (cmi.student_data.mastery_score !== '' && cmi.core.score.raw !== '') {581 if (parseFloat(cmi.core.score.raw) >= parseFloat(cmi.student_data.mastery_score)) {582 cmi.core.lesson_status = 'passed';583 } else {584 cmi.core.lesson_status = 'failed';585 }586 }587 }588 }589 if (cmi.core.lesson_mode == 'browse') {590 if (datamodel[scoid]['cmi.core.lesson_status'].defaultvalue == '' && cmi.core.lesson_status == 'not attempted') {591 cmi.core.lesson_status = 'browsed';592 }593 }594 datastring = CollectData(data,'cmi');595 datastring += TotalTime();596 } else {597 datastring = CollectData(data,'cmi');598 }599 var myRequest = NewHttpReq();600 //alert('going to:' + "<?php p($CFG->wwwroot) ?>/mod/scorm/datamodel.php" + "id=<?php p($id) ?>&a=<?php p($a) ?>&sesskey=<?php echo sesskey() ?>"+datastring);601 result = DoRequest(myRequest,datamodelurl,datamodelurlparams + datastring);602 results = String(result).split('\n');603 errorCode = results[1];604 return results[0];605 }606 this.LMSInitialize = LMSInitialize;607 this.LMSFinish = LMSFinish;608 this.LMSGetValue = LMSGetValue;609 this.LMSSetValue = LMSSetValue;610 this.LMSCommit = LMSCommit;611 this.LMSGetLastError = LMSGetLastError;612 this.LMSGetErrorString = LMSGetErrorString;613 this.LMSGetDiagnostic = LMSGetDiagnostic;614}615M.scorm_api = {};616M.scorm_api.init = function(Y, def, cmiobj, cmiint, cmistring256, cmistring4096, scormdebugging, scormauto, scormid, cfgwwwroot, sesskey, scoid, attempt, viewmode, cmid, currentorg, autocommit) {617 window.API = new SCORMapi1_2(def, cmiobj, cmiint, cmistring256, cmistring4096, scormdebugging, scormauto, scormid, cfgwwwroot, sesskey, scoid, attempt, viewmode, cmid, currentorg, autocommit);...
12779.js
Source:12779.js
...24 });25 });26 describe('logApiCall', () => {27 it('logs the first call without the start marker', () => {28 underTest.logApiCall('svc1.api1');29 expect(fakeConsole.log).toHaveBeenCalledWith('svc1.api1');30 });31 it('logs the second call with the start marker', () => {32 underTest.logApiCall('svc1.api1');33 fakeConsole.log.calls.reset();34 underTest.logApiCall('svc2.api2');35 expect(fakeConsole.log).toHaveBeenCalledWith('[START]svc2.api2');36 });37 it('logs the stage and the api call if the stage is defined', () => {38 underTest.logStage('stage1');39 fakeConsole.log.calls.reset();40 underTest.logApiCall('svc1.api1');41 expect(fakeConsole.log).toHaveBeenCalledWith('[START]stage1\tsvc1.api1');42 });43 it('ignores arguments that are not arrays', () => {44 underTest.logApiCall('svc1.api1', 12345);45 expect(fakeConsole.log).toHaveBeenCalledWith('svc1.api1');46 });47 it('ignores arguments that are empty arrays', () => {48 underTest.logApiCall('svc1.api1', []);49 expect(fakeConsole.log).toHaveBeenCalledWith('svc1.api1');50 });51 it('ignores hash arguments that do not end with ID or Name', () => {52 underTest.logApiCall('svc1.api1', [{ a: 'b' }]);53 expect(fakeConsole.log).toHaveBeenCalledWith('svc1.api1');54 });55 it('logs xxxName arguments', () => {56 underTest.logApiCall('svc1.api1', [{ a: 'b', FunctionName: 'Fun1' }]);57 expect(fakeConsole.log).toHaveBeenCalledWith('svc1.api1\tFunctionName=Fun1');58 });59 it('logs xxxId arguments', () => {60 underTest.logApiCall('svc1.api1', [{ a: 'b', RestApiId: 'Api1' }]);61 expect(fakeConsole.log).toHaveBeenCalledWith('svc1.api1\tRestApiId=Api1');62 });63 it('logs pathXXX arguments', () => {64 underTest.logApiCall('svc1.api1', [{ a: 'b', pathPart: '/XXX' }]);65 expect(fakeConsole.log).toHaveBeenCalledWith('svc1.api1\tpathPart=/XXX');66 });67 it('logs multiple args matching', () => {68 underTest.logApiCall('svc1.api1', [{ a: 'b', FunctionName: 'Fun1', RestApiId: 'YYY' }]);69 expect(fakeConsole.log).toHaveBeenCalledWith('svc1.api1\tFunctionName=Fun1\tRestApiId=YYY');70 });71 });...
array-logger-spec.js
Source:array-logger-spec.js
...22 underTest.logStage('first');23 expect(underTest.getStageLog(true)).toEqual(['first', 'second']);24 });25 it('logs calls to APIs', () => {26 underTest.logApiCall('method1', 'arg1');27 underTest.logApiCall('method2', 'arg2');28 underTest.logApiCall('method1', 'arg1');29 expect(underTest.getApiCallLog()).toEqual(['method1', 'method2', 'method1']);30 });31 it('can return unique API log calls', () => {32 underTest.logApiCall('method1', 'arg1');33 underTest.logApiCall('method2', 'arg2');34 underTest.logApiCall('method1', 'arg2');35 expect(underTest.getApiCallLog(true)).toEqual(['method1', 'method2']);36 });37 it('can filter API calls by service', () => {38 underTest.logApiCall('Api1.method1', 'arg1');39 underTest.logApiCall('Api1.method2', 'arg2');40 underTest.logApiCall('Api2.method3', 'arg2');41 underTest.logApiCall('Api1.method1', 'arg2');42 expect(underTest.getApiCallLogForService('Api1')).toEqual(['Api1.method1', 'Api1.method2', 'Api1.method1']);43 });44 it('can return unique API calls for service', () => {45 underTest.logApiCall('Api1.method1', 'arg1');46 underTest.logApiCall('Api1.method2', 'arg2');47 underTest.logApiCall('Api2.method3', 'arg2');48 underTest.logApiCall('Api1.method1', 'arg2');49 expect(underTest.getApiCallLogForService('Api1', true)).toEqual(['Api1.method1', 'Api1.method2']);50 });51 it('can return a combined log', () => {52 underTest.logStage('creating stuff');53 underTest.logApiCall('Api1.method1', 'arg1');54 underTest.logStage('creating stuff');55 underTest.logStage('deleting stuff');56 underTest.logApiCall('Api1.method1', 'arg1');57 expect(underTest.getCombinedLog()).toEqual([58 ['stage', 'creating stuff'],59 ['call', 'Api1.method1', 'arg1'],60 ['stage', 'creating stuff'],61 ['stage', 'deleting stuff'],62 ['call', 'Api1.method1', 'arg1']63 ]);64 });...
Using AI Code Generation
1const { logApiCall } = require('playwright/lib/server/trace/recorder');2logApiCall('method', 'params');3const { logApiCall } = require('playwright/lib/server/trace/recorder');4logApiCall('method', 'params');5const { logApiCall } = require('playwright/lib/server/trace/recorder');6logApiCall('method', 'params');7const { logApiCall } = require('playwright/lib/server/trace/recorder');8logApiCall('method', 'params');9const { logApiCall } = require('playwright/lib/server/trace/recorder');10logApiCall('method', 'params');11const { logApiCall } = require('playwright/lib/server/trace/recorder');12logApiCall('method', 'params');13const { logApiCall } = require('playwright/lib/server/trace/recorder');14logApiCall('method', 'params');15const { logApiCall } = require('playwright/lib/server/trace/recorder');16logApiCall('method', 'params');17const { logApiCall } = require('playwright/lib/server/trace/recorder');18logApiCall('method', 'params');19const { logApiCall } = require('playwright/lib/server/trace/recorder');20logApiCall('method', 'params');21const { logApiCall } = require('playwright/lib/server/trace/recorder');22logApiCall('method', 'params');
Using AI Code Generation
1const { logApiCall } = require('@playwright/test/lib/server/apiLogger');2logApiCall('test', 'test', 'test');3const { logApiCall } = require('@playwright/test/lib/server/apiLogger');4logApiCall('test', 'test', 'test');5const { logApiCall } = require('@playwright/test/lib/server/apiLogger');6logApiCall('test', 'test', 'test');7const { logApiCall } = require('@playwright/test/lib/server/apiLogger');8logApiCall('test', 'test', 'test');9const { logApiCall } = require('@playwright/test/lib/server/apiLogger');10logApiCall('test', 'test', 'test');11const { logApiCall } = require('@playwright/test/lib/server/apiLogger');12logApiCall('test', 'test', 'test');13const { logApiCall } = require('@playwright/test/lib/server/apiLogger');14logApiCall('test', 'test', 'test');15const { logApiCall } = require('@playwright/test/lib/server/apiLogger');16logApiCall('test', 'test', 'test');17const { logApiCall } = require('@playwright/test/lib/server/apiLogger');18logApiCall('test', 'test', 'test');19const { logApiCall } = require('@playwright/test/lib/server/apiLogger');20logApiCall('test', 'test', 'test');21const { logApiCall } = require('@playwright/test/lib/server/apiLogger');22logApiCall('test', 'test', 'test');23const { logApiCall } = require('@playwright/test/lib/server/apiLogger');24logApiCall('test', '
Using AI Code Generation
1const { logApiCall } = require('playwright/lib/utils/logger');2logApiCall('My custom message', 'My custom data');3const { logApiCall } = require('playwright/lib/utils/logger');4logApiCall('My custom message', 'My custom data');5const { logApiCall } = require('playwright/lib/utils/logger');6logApiCall('My custom message', 'My custom data');7const { logApiCall } = require('playwright/lib/utils/logger');8logApiCall('My custom message', 'My custom data');9const { logApiCall } = require('playwright/lib/utils/logger');10logApiCall('My custom message', 'My custom data');11const { logApiCall } = require('playwright/lib/utils/logger');12logApiCall('My custom message', 'My custom data');13const { logApiCall } = require('playwright/lib/utils/logger');14logApiCall('My custom message', 'My custom data');15const { logApiCall } = require('playwright/lib/utils/logger');16logApiCall('My custom message', 'My custom data');17const { logApiCall } = require('playwright/lib/utils/logger');18logApiCall('My custom message', 'My custom data');19const { logApiCall } = require('playwright/lib/utils/logger');20logApiCall('My custom message', 'My custom data');21const { logApiCall } = require('playwright/lib/utils/logger');22logApiCall('My custom message', 'My custom data');23const { logApiCall } = require('playwright/lib/utils/logger');24logApiCall('My custom message', 'My custom data');25const { logApiCall } = require('playwright/lib/utils/logger');26logApiCall('My custom message', 'My custom data');27const { logApiCall } = require('playwright/lib/utils/logger');28logApiCall('My custom message', 'My custom data');29const { logApiCall } = require('playwright/lib/utils
Using AI Code Generation
1const { logApiCall } = require('playwright-core/lib/server/trace/recorder');2logApiCall('myMethod', 'myParam', 'myResult');3const { test } = require('@playwright/test');4test('test', async ({ page }) => {5});6const { test } = require('@playwright/test');7const { logApiCall } = require('playwright-core/lib/server/trace/recorder');8test('test', async ({ page }) => {9});10const { test } = require('@playwright/test');11test('test', async ({ page }) => {12});13const { test } = require('@playwright/test');14const { logApiCall } = require('playwright-core/lib/server/trace/recorder');15test('test', async ({ page }) => {16});17const { test } = require('@playwright/test');18test('test', async ({ page }) => {19});20const { test } = require('@playwright/test');21const { logApiCall } = require('playwright-core/lib/server/trace/recorder');22test('test', async ({ page }) => {23});24const { test } = require('@playwright/test');25test('test', async ({ page }) => {26});27const { test } = require('@playwright/test');28const { logApiCall } = require('playwright-core/lib/server/trace/recorder');29test('test', async ({ page }) => {
Using AI Code Generation
1const { logApiCall } = require('playwright/lib/utils/DebugLogger');2const fs = require('fs');3const logFile = fs.createWriteStream('log.txt');4logApiCall('method', 'params', 'result', logFile);5const { debug } = require('playwright/lib/utils/DebugLogger');6debug();
Using AI Code Generation
1const { logApiCall } = require('@playwright/test/lib/utils/trace');2logApiCall({ method: 'context.route', args: ['**/*'], returnValue: { route: 'route' } });3logApiCall({ method: 'context.route', args: ['**/*'], returnValue: { route: 'route' } });4logApiCall({ method: 'context.route', args: ['**/*'], returnValue: { route: 'route' } });5logApiCall({ method: 'context.route', args: ['**/*'], returnValue: { route: 'route' } });6logApiCall({ method: 'context.route', args: ['**/*'], returnValue: { route: 'route' } });7logApiCall({ method: 'context.route', args: ['**/*'], returnValue: { route: 'route' } });8logApiCall({ method: 'context.route', args: ['**/*'], returnValue: { route: 'route' } });9logApiCall({ method: 'context.route', args: ['**/*'], returnValue: { route: 'route' } });10logApiCall({ method: 'context.route', args: ['**/*'], returnValue: { route: 'route' } });11logApiCall({ method: 'context.route', args: ['**/*'], returnValue: { route: 'route' } });12logApiCall({ method: 'context.route', args: ['**/*'], returnValue: { route: 'route' } });13logApiCall({ method: 'context.route', args: ['**/*'], returnValue: { route: 'route' } });14logApiCall({ method: 'context.route', args: ['**/*'], returnValue: { route: 'route' } });15logApiCall({ method: 'context.route', args: ['**/*'], returnValue: { route: 'route' } });16logApiCall({ method: 'context.route', args: ['**/*'], returnValue: { route: 'route' } });17logApiCall({ method: 'context.route', args: ['**/*'], returnValue: { route: 'route' } });18logApiCall({ method: 'context.route', args: ['**/*'], returnValue: { route: 'route' } });19logApiCall({ method: 'context.route', args: ['**/*'], returnValue: { route: 'route' } });
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!!