Skip to content

Commit 06be654

Browse files
committed
Improved logging function, now logs last step
1 parent 474f324 commit 06be654

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

nr_synthetics_formatter/nr-synthetics.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,23 @@ builder.selenium2.io.addLangFormatter({
3636
" browser = $browser.manage(),\n" +
3737
" startTime = Date.now(),\n" +
3838
" stepStartTime = Date.now(),\n" +
39-
" lastMsg = '',\n" +
40-
" VARS = {};\n\n" +
41-
"var log = function(thisStep, msg) {\n" +
42-
" if (thisStep > 0) {\n" +
43-
" var lastStep = thisStep - 1;\n" +
44-
" var lastStepTimeElapsed = Date.now() - (startTime + stepStartTime);\n" +
45-
" console.log('Step ' + lastStep + ': ' + lastMsg + ' FINISHED. It took ' + lastStepTimeElapsed + 'ms to complete.');\n" +
46-
" $util.insights.set('Step ' + lastStep + ': ' + lastMsg, lastStepTimeElapsed);\n" +
47-
" }\n" +
48-
" stepStartTime = Date.now() - startTime;\n" +
49-
" console.log('Step ' + thisStep + ': ' + msg + ' STARTED at ' + stepStartTime + 'ms.');\n" +
50-
" lastMsg = msg;\n" +
51-
" };\n\n" +
39+
" prevMsg = '',\n" +
40+
" prevStep = 0,\n" +
41+
" lastStep = 9999,\n" +
42+
" VARS = {};\n\n" +
43+
"var log = function(thisStep, thisMsg) {\n" +
44+
" if (thisStep > 1 || thisStep == lastStep) {\n" +
45+
" var prevStepTimeElapsed = Date.now() - (startTime + stepStartTime);\n" +
46+
" console.log('Step ' + prevStep + ': ' + prevMsg + ' FINISHED. It took ' + prevStepTimeElapsed + 'ms to complete.');\n" +
47+
" $util.insights.set('Step ' + prevStep + ': ' + prevMsg, prevStepTimeElapsed);\n" +
48+
" }\n" +
49+
" if (thisStep > 0 && thisStep != lastStep) {\n" +
50+
" stepStartTime = Date.now() - startTime;\n" +
51+
" console.log('Step ' + thisStep + ': ' + thisMsg + ' STARTED at ' + stepStartTime + 'ms.');\n" +
52+
" prevMsg = thisMsg;\n" +
53+
" prevStep = thisStep;\n" +
54+
" }\n" +
55+
"};\n\n" +
5256
"function isAlertPresent() {\n" +
5357
" try {\n" +
5458
" var thisAlert = $browser.switchTo().alert();\n" +
@@ -66,7 +70,6 @@ builder.selenium2.io.addLangFormatter({
6670
" return isTextPresentIn(text, $browser.findElement(By.tagName('html')));\n" +
6771
"}\n\n" +
6872
"/** BEGINNING OF SCRIPT **/\n\n" +
69-
"log(0, 'init');\n\n" +
7073
"// Setting User Agent is not then-able, so we do this first (if defined and not default)\n" +
7174
"if (UserAgent && (0 !== UserAgent.trim().length) && (UserAgent != 'default')) {\n" +
7275
" $browser.addHeader('User-Agent', UserAgent);\n" +
@@ -76,8 +79,10 @@ builder.selenium2.io.addLangFormatter({
7679
"$browser.getCapabilities().then(function () { })\n\n",
7780
end:
7881
".then(function() {\n" +
82+
" log(lastStep, '');\n" +
7983
" console.log('Browser script execution SUCCEEDED.');\n" +
8084
"}, function(err) {\n" +
85+
" log(lastStep, '');\n" +
8186
" console.log ('Browser script execution FAILED.');\n" +
8287
" throw(err);\n" +
8388
"});\n\n" +

0 commit comments

Comments
 (0)