-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuser-extensions-min.js
1 lines (1 loc) · 7.87 KB
/
user-extensions-min.js
1
var selbench={name:"selbench",seleniumEnv:"ide",globalContext:this};(function(a){a.fn={};a.unwrapObject=function(b){if(typeof(b)==="undefined"||b==null){return b}if(b.wrappedJSObject){return b.wrappedJSObject}return b}}(selbench));(function(b){function a(){this.error=function(c){this.logit("error",c)};this.warn=function(c){this.logit("warn",c)};this.info=function(c){this.logit("info",c)};this.debug=function(c){this.logit("debug",c)};this.trace=function(c){this.logit("debug",c)};this.logit=function(c,d){LOG[c]("["+b.name+"] "+d)};this.genStackTrace=function(h){var j=h||new Error();var c=[];if(!j.stack){c.push("No stack trace, (Firefox only)")}else{var g=/^\s*[A-Za-z0-9\-_\$]+\(/;var d=j.stack.split("\n");for(var f=0;f<d.length;f++){if(d[f].match(g)){c.push(d[f])}}if(!h){c.shift()}}return c};this.logStackTrace=function(e){var d=this.genStackTrace(e);if(!e){d.shift()}this.warn("__Stack Trace__");for(var c=0;c<d.length;c++){this.warn("@@ "+d[c])}};this.descCaller=function(){var c=this.genStackTrace(new Error());if(c.length==0){return"no client function"}c.shift();if(c.length==0){return"no caller function"}c.shift();if(c.length==0){return"undefined caller function"}return"caller: "+c[0]}}b.LOG=new a()}(selbench));(function(a){a.fn.interceptAfter=function(c,e,d){var b=c[e];c[e]=function(){var f=Array.prototype.slice.call(arguments);b.apply(this,f);return d.apply(this,f)}};a.fn.interceptStack=[];a.fn.interceptPush=function(c,f,b,e){var d={targetObj:c,targetFnName:f,savedFn:c[f],attrs:e};a.fn.interceptStack.push(d);c[f]=b};a.fn.interceptPop=function(){var b=a.fn.interceptStack.pop();b.targetObj[b.targetFnName]=b.savedFn};a.fn.interceptOnce=function(b,d,c){a.fn.interceptPush(b,d,function(){a.fn.interceptPop();var e=Array.prototype.slice.call(arguments);c.apply(this,e)})}}(selbench));(function(a){a.seleniumEnv="server";a.globalContext.serverPatchApplied=a.globalContext.serverPatchApplied||false;if(!a.globalContext.serverPatchApplied){a.LOG.info("Applying testCase server patch for "+a.name);a.fn.interceptAfter(Selenium.prototype,"reset",b);a.globalContext.serverPatchApplied=true}function b(){if(!(typeof htmlTestRunner==="undefined"||htmlTestRunner===null)){htmlTestRunner.currentTest.commands=c(htmlTestRunner.currentTest.htmlTestCase.getCommandRows());a.globalContext.testCase=htmlTestRunner.currentTest;a.globalContext.testCase.debugContext=htmlTestRunner.currentTest;Object.defineProperties(a.globalContext.testCase,{_nextCommandRowIndex:{writable:true},debugIndex:{enumerable:true,get:function(){return this._nextCommandRowIndex},set:function(e){this._nextCommandRowIndex=e}},nextCommandRowIndex:{enumerable:true,get:function(){return this._nextCommandRowIndex},set:function(e){this._nextCommandRowIndex=e}}})}function c(g){var e=[];for(var f=0;f<g.length;++f){e.push(d(g[f]))}return e}function d(f){var e=f.getCommand();if(f.hasOwnProperty("trElement")){e.type="command"}else{e.type="comment"}return e}}}(selbench));function $w(){return selenium.browserbot.getCurrentWindow()}function $d(){return selenium.browserbot.getDocument()}(function($$){$$.fn.interceptAfter(Selenium.prototype,"reset",function(){$$.LOG.debug("In SelBench tail intercept :: selenium.reset()");$$.seleniumTestLoop=($$.seleniumEnv=="server")?HtmlRunnerTestLoop:editor.selDebugger.runner.IDETestLoop;try{compileSelbenchCommands()}catch(err){throw new Error("In "+err.fileName+" @"+err.lineNumber+": "+err)}storedVars.emitted=""});function compileSelbenchCommands(){for(var i=0;i<testCase.commands.length;i++){if(testCase.commands[i].type=="command"){var curCmd=testCase.commands[i].command;var aw=curCmd.indexOf("AndWait");if(aw!==-1){curCmd=curCmd.substring(0,aw)}switch(curCmd){case"emit":case"assertEmitted":case"resetEmitted":case"timer":case"timerElapsed":case"alert":case"log":case"clearLog":assertNotAndWaitSuffix(i)}}}function assertNotAndWaitSuffix(cmdIdx){assertCmd(cmdIdx,(aw===-1),", AndWait suffix is not valid for SelBench commands")}}Selenium.prototype.doExpectError=function(target){$$.expectedError=$$.evalWithVars(target);$$.fn.interceptOnce($$.seleniumTestLoop.prototype,"resume",$$.handleAsExpectError)};Selenium.prototype.doEmit=function(target){if(storedVars.emitted){storedVars.emitted+="~"}storedVars.emitted+=$$.evalWithVars(target)};Selenium.prototype.doAssertEmitted=function(target,value){var expectedValue=$$.evalWithVars(target);if(expectedValue instanceof Array){expectedValue=expectedValue.join("~")}if(expectedValue!=storedVars.emitted){var errmsg=" expected: "+expectedValue+"\nbut found: "+storedVars.emitted;throw new Error(errmsg)}};Selenium.prototype.doResetEmitted=function(){storedVars.emitted=""};Selenium.prototype.doAlert=function(expr){alert($$.evalWithVars(expr))};Selenium.prototype.doLog=function(expr,level){if(!level){level="info"}if(!$$.LOG[level]){throw new Error("'"+level+"' is not a valid logging level")}$$.LOG[level]($$.evalWithVars(expr))};Selenium.prototype.doClearLog=function(){if($$.seleniumEnv!="ide"){$$.LOG.warn("clearLog command ignored in non-IDE environment");return}editor.getUserLog().clear()};Selenium.prototype.doDeleteVar=function(name){$$.LOG.warn("The deleteVar command has been deprecated as of SelBench 1.0.1 and will be removed in future releases. Please use deleteVars instead.");delete storedVars[name]};Selenium.prototype.doDeleteVars=function(namesSpec){var names=namesSpec.split(",");for(var i=0;i<names.length;i++){delete storedVars[names[i].trim()]}};function notifyFatal(msg){$$.LOG.error("SelBench error "+msg);throw new Error(msg)}function notifyFatalCmdRef(idx,msg){notifyFatal(fmtCmdRef(idx)+msg)}function assertCmd(idx,cond,msg){if(!cond){notifyFatalCmdRef(idx,msg)}}function assertNotAndWaitSuffix(idx){var aw=testCase.commands[idx].command.indexOf("AndWait");assertCmd(idx,(aw===-1),", AndWait suffix is not valid for SelBench commands")}function fmtCmdRef(idx){return("@"+(idx+1)+": "+fmtCommand(testCase.commands[idx]))}function fmtCommand(cmd){var c=cmd.command;if(cmd.target){c+="|"+cmd.target}if(cmd.value){c+="|"+cmd.value}return"["+c+"]"}$$.evalWithVars=function(expr){return eval("with (storedVars) {"+expr+"}")};function getIdeLogLevel(){return parseInt(editor.getOptions().logLevel)}var timers={};Selenium.prototype.doStartTimer=function(name,description){timers[name]=new Timer(description)};Selenium.prototype.doTimerElapsed=function(name,script){if(script){storedVars._elapsed=timers[name].elapsed();$$.evalWithVars(script)}else{$$.LOG.info(timers[name].elapsed())}};function Timer(desc,logLevel){var msStart=+new Date();this.elapsed=function(){var msElapsed=+new Date()-msStart;var msg=formatDuration(msElapsed)+" elapsed: "+(desc||"");if(logLevel){$$.LOG[logLevel](msg)}return msg}}var SEC=1;var MIN=60*SEC;var HOUR=60*MIN;var DAY=24*HOUR;function formatDuration(millis){var sec=millis/1000;var fmt="";if(sec>DAY){fmt=(sec/DAY).toFixed()+" day ";sec%=DAY}if(sec>(1.5*HOUR)||fmt.length>0){fmt+=(sec/HOUR).toFixed()+" hour ";sec%=HOUR}if(sec>(1.5*MIN)||fmt.length>0){fmt+=(sec/MIN).toFixed()+" min ";sec%=MIN}return fmt+sec.toFixed(3)+" sec"}}(selbench));(function(a){a.expectedError=null;a.handleAsExpectError=function(){try{selenium.browserbot.runScheduledPollers();this._executeCurrentCommand();if(this.result.failed){if(b(this.result)){a.LOG.info("The expected verify-failure is confirmed : "+this.result.failureMessage);this.continueTest()}else{a.LOG.error("Expected error : "+a.expectedError);this.continueTestWhenConditionIsTrue()}}else{this._handleCommandError(new Error("Command succeeded, while expecting error : "+a.expectedError));this.testComplete()}}catch(c){if(b(c)){a.LOG.info("The expected error is confirmed : "+c.message);this.continueTest()}else{a.LOG.error("Expected error : "+a.expectedError);a.LOG.error("but encountered : "+c.message);if(!this._handleCommandError(c)){this.testComplete()}else{this.continueTest()}}}function b(f){var d=(f.constructor.name=="AssertResult")?f.failureMessage:d=f.message;if(a.expectedError instanceof RegExp){return(d.match(a.expectedError))}return(d.indexOf(a.expectedError)!=-1)}}}(selbench));