Skip to content

Commit ed55125

Browse files
committed
Fixed switchToFrame, AlertPresent and logging
1 parent 69be227 commit ed55125

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

nr_synthetics_formatter.zip

-7 Bytes
Binary file not shown.

nr_synthetics_formatter/nr-synthetics.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@ builder.selenium2.io.addLangFormatter({
5050
" prevStep = thisStep;\n" +
5151
" }\n" +
5252
"};\n\n" +
53-
"function isAlertPresent() {\n" +
54-
" try {\n" +
55-
" var thisAlert = $browser.switchTo().alert();\n" +
56-
" return true;\n" +
57-
" } catch (err) { return false; }\n" +
58-
"}\n\n" +
5953
"/** BEGINNING OF SCRIPT **/\n\n" +
6054
"console.log('Starting synthetics script: {scriptName}');\n" +
6155
"console.log('Default timeout is set to ' + (DefaultTimeout/1000) + ' seconds');\n" +
@@ -99,7 +93,7 @@ lineForType: {
9993
"pause":
10094
function(step) { return scriptify("$browser.sleep( " + step.waitTime + ")"); },
10195
"switchToFrame":
102-
function(step) { return scriptify("$browser.switchTo().frame('" + thisstepentifier + "')"); },
96+
function(step) { return scriptify("$browser.switchTo().frame('" + step.identifier + "')"); },
10397
"switchToFrameByIndex":
10498
function(step) { return scriptify("$browser.switchTo().frame('" + step.index + "')"); },
10599
"switchToWindow":
@@ -438,7 +432,7 @@ lineForType: {
438432
value: "{name}"
439433
},
440434
"AlertPresent": {
441-
getter: "isAlertPresent()",
435+
getter: "$browser.switchTo().alert().then(function () { return true; }).thenCatch(function (e) { return false; })",
442436
getterFinish: "})\n\n",
443437
value: "alert"
444438
}
@@ -544,16 +538,18 @@ function print_nr_unsupported(thing) {
544538
}
545539

546540
function scriptify(msg) {
541+
var msg_fixed = msg.replace(/'/g, '"');
547542
return commentstep() +
548543
".then(function() {\n" +
549-
" log(" + thisstep + ", \'" + msg + "\');\n" +
544+
" log(" + thisstep + ", \'" + msg_fixed + "\');\n" +
550545
" return " + msg + "; })\n\n";
551546
}
552547

553548
function scriptify_complex(logmsg, msg) {
549+
var logmsg_fixed = logmsg.replace(/'/g, '"');
554550
return commentstep() +
555551
".then(function() {\n" +
556-
" log(" + thisstep + ", \'" + logmsg + "\');\n" +
552+
" log(" + thisstep + ", \'" + logmsg_fixed + "\');\n" +
557553
" return " + msg + "; })\n\n";
558554
}
559555

0 commit comments

Comments
 (0)