//>>built // wrapped by build app define("dojox/robot/recorder", ["dijit","dojo","dojox"], function(dijit,dojo,dojox){ dojo.provide("dojox.robot.recorder"); dojo.experimental("dojox.robot.recorder"); // summary: // Generates a doh test as you interact with a Web page. // To record a test, click inside the document body and press CTRL-ALT-ENTER. // To finish recording a test and to display the autogenerated code, press CTRL-ALT-ENTER again. // (function(){ // CONSTANTS // consolidate keypresses into one typeKeys if they occur within 1 second of each other var KEYPRESS_MAXIMUM_DELAY = 1000; // consolidate mouse movements if they occur within .5 seconds of each other var MOUSEMOVE_MAXIMUM_DELAY = 500; // absolute longest wait between commands // anything longer gets chopped to 10 var MAXIMUM_DELAY = 10000; // stack of commands recorded from dojo.connects var commands = []; // number to write next to test name // goes up after each recording var testNumber = 0; // time user started test var startTime = null; // time since last user input // robot commands work on deltas var prevTime = null; var start = function(){ // summary: // Starts recording the user's input. // alert("Started recording."); commands = []; startTime = new Date(); prevTime = new Date(); } var addCommand = function(name, args){ // summary: // Add a command to the stack. // // name: // doh.robot function to call. // // args: // arguments array to pass to the doh.robot // // omit start/stop record if(startTime == null || name=="doh.robot.keyPress" && args[0]==dojo.keys.ENTER && eval("("+args[2]+")").ctrl && eval("("+args[2]+")").alt){ return; } var dt = Math.max(Math.min(Math.round((new Date()).getTime() - prevTime.getTime()),MAXIMUM_DELAY),1); // add in dt // is usually args[1] but there are exceptions if(name == "doh.robot.mouseMove"){ args[2]=dt; }else{ args[1]=dt; } commands.push({name:name,args:args}); prevTime = new Date(); } var _optimize = function(){ // make the stack more human-readable and remove any odditites var c = commands; // INITIAL OPTIMIZATIONS // remove starting ENTER press if(c[0].name == "doh.robot.keyPress" && (c[0].args[0] == dojo.keys.ENTER || c[0].args[0] == 77)){ c.splice(0,1); } // remove ending CTRL + ALT keypresses in IE for(var i = c.length-1; (i >= c.length-2) && (i>=0); i-- ){ if(c[i].name == "doh.robot.keyPress" && c[i].args[0]==dojo.keys.ALT || c[i].args[0]==dojo.keys.CTRL){ c.splice(i,1); } } // ITERATIVE OPTIMIZATIONS for(i = 0; i