@@ -33,15 +33,26 @@ builder.selenium2.io.addLangFormatter({
3333 "/** HELPER FUNCTIONS **/\n\n" +
3434 "var assert = require('assert'),\n" +
3535 " By = $driver.By,\n" +
36- " startTime = new Date(),\n" +
3736 " thisStep = 0,\n" +
37+ " startTime = Date.now(),\n" +
38+ " stepStartTime = Date.now(),\n" +
39+ " totalElapsedTime = 0,\n" +
40+ " lastMsg = '',\n" +
3841 " VARS = {};\n" +
42+ "\n" +
3943 "var log = function(msg) {\n" +
40- " var elapsedSecs = (new Date() - startTime) / 1000.0;\n" +
41- " console.log('Step ' + thisStep + ': ' + elapsedSecs.toFixed(1) + 's: ' + msg);\n" +
42- " thisStep++;\n" +
43- "};\n" +
44- "// 1st log is sometimes ignored for some reason, so this is a dummy\n" +
44+ " totalElapsedTime = Date.now() - startTime;\n" +
45+ " if (thisStep > 0) {\n" +
46+ " var lastStepTimeElapsed = totalElapsedTime - stepStartTime;\n" +
47+ " console.log('Step ' + thisStep + ': ' + lastMsg + ' FINISHED. It took ' + lastStepTimeElapsed + 'ms to complete.');\n" +
48+ " $util.insights.set('Step ' + thisStep + ': ' + lastMsg, lastStepTimeElapsed);\n" +
49+ " }\n" +
50+ " thisStep++;\n" +
51+ " stepStartTime = Date.now() - startTime;\n" +
52+ " console.log('Step ' + thisStep + ': ' + msg + ' STARTED at ' + stepStartTime + 'ms.');\n" +
53+ " lastMsg = msg;\n" +
54+ " };\n" +
55+ "\n" +
4556 "log('init');\n" +
4657 "function isAlertPresent() {\n" +
4758 " try {\n" +
@@ -53,8 +64,7 @@ builder.selenium2.io.addLangFormatter({
5364 "function isTextPresentIn(text, sourceEl) {\n" +
5465 " return sourceEl.getText()\n" +
5566 " .then(function (wholetext) {\n" +
56- " log(\"Assert Text Present: '\" + text +\"'\");\n" +
57- " assert.notEqual(wholetext.indexOf(text), -1, \"Text Not Found: '\" + text + \"'\");\n" +
67+ " return wholetext.indexOf(text) != -1;\n" +
5868 " });\n" +
5969 "}\n\n" +
6070 "function isTextPresent(text) {\n" +
@@ -64,19 +74,20 @@ builder.selenium2.io.addLangFormatter({
6474 "// Setting User Agent is not then-able, so we do this first (if defined and not default)\n" +
6575 "if ((typeof UserAgent !== 'undefined') && (UserAgent != 'default')) {\n" +
6676 " $browser.addHeader('User-Agent', UserAgent);\n" +
67- " log('Setting User-Agent to ' + UserAgent);\n" +
77+ " console. log('Setting User-Agent to ' + UserAgent);\n" +
6878 "}\n\n" +
6979 "// Get browser capabilities and do nothing with it, so that we start with a then-able command\n" +
7080 "$browser.getCapabilities().then(function () { })\n\n" ,
7181 end :
7282 ".then(function() {\n" +
73- " log('Browser script execution SUCCEEDED.');\n" +
83+ " console. log('Browser script execution SUCCEEDED.');\n" +
7484 "}, function(err) {\n" +
75- " log ('Browser script execution FAILED.');\n" +
85+ " console. log ('Browser script execution FAILED.');\n" +
7686 " throw(err);\n" +
7787 "});\n\n" +
7888 "/** END OF SCRIPT **/" ,
79- lineForType : {
89+
90+ lineForType : {
8091 "get" :
8192 ".then(function () {\n" +
8293 " log('{stepTypeName} {url}');\n" +
@@ -91,7 +102,7 @@ builder.selenium2.io.addLangFormatter({
91102 "close" :
92103 "" ,
93104 "print" :
94- ".then(function () { log(' {text}' ); })\n\n" ,
105+ ".then(function () { console. log({text}); })\n\n" ,
95106 "pause" :
96107 function ( step ) { return scriptify ( "$browser.sleep( " + step . waitTime + ")" ) ; } ,
97108 "switchToFrame" :
@@ -363,7 +374,7 @@ builder.selenium2.io.addLangFormatter({
363374 " log('{stepTypeName} {negNot}{value}');\n" +
364375 " {getter}.then(function (bool) {\n" +
365376 " if ({posNot}bool) {\n" +
366- " log('{negNot}{stepTypeName} failed');\n" +
377+ " console. log('{negNot}{stepTypeName} failed');\n" +
367378 " $browser.takeScreenshot();\n" +
368379 " }\n" +
369380 " });\n" +
@@ -507,4 +518,4 @@ function scriptify(msg) {
507518 "})\n\n" ;
508519}
509520
510- if ( builder && builder . loader && builder . loader . loadNextMainScript ) { builder . loader . loadNextMainScript ( ) ; }
521+ if ( builder && builder . loader && builder . loader . loadNextMainScript ) { builder . loader . loadNextMainScript ( ) ; }
0 commit comments