Skip to content

Commit c36b71a

Browse files
committed
Preventing failure to find text
In the event of Exceptions such as the StaleElementReferenceException then the text was obviously not found. Instead of throwing an exception though return false.
1 parent 3f47d02 commit c36b71a

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

nr_synthetics_formatter/nr-synthetics.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,18 @@ builder.selenium2.io.addLangFormatter({
5454
" } catch (err) { return false; }\n" +
5555
"}\n\n" +
5656
"function isElementSelected(el) { return $browser.findElement(el).isSelected(); }\n\n" +
57-
"function isTextPresentIn(text, sourceEl) {\n" +
58-
" return sourceEl.getText()\n" +
59-
" .then(function (wholetext) {\n" +
60-
" return wholetext.indexOf(text) != -1;\n" +
61-
" });\n" +
57+
"function isTextPresentIn(text, selector) {\n" +
58+
" return $browser.findElement(selector)\n" +
59+
" .getText()\n" +
60+
" .then(function (wholetext) {\n" +
61+
" return wholetext.indexOf(text) != -1;\n" +
62+
" })\n" +
63+
" .catch(function(err) {\n" +
64+
" return false;\n" +
65+
" });\n" +
6266
"}\n\n" +
6367
"function isTextPresent(text) {\n" +
64-
" return isTextPresentIn(text, $browser.findElement(By.tagName('html')));\n" +
68+
" return isTextPresentIn(text, By.tagName('html'));\n" +
6569
"}\n\n" +
6670
"/** BEGINNING OF SCRIPT **/\n\n" +
6771
"// Setting User Agent is not then-able, so we do this first (if defined and not default)\n" +
@@ -559,4 +563,4 @@ function scriptify_complex(logmsg, msg) {
559563
" return " + msg + "; })\n\n";
560564
}
561565

562-
if (builder && builder.loader && builder.loader.loadNextMainScript) { builder.loader.loadNextMainScript(); }
566+
if (builder && builder.loader && builder.loader.loadNextMainScript) { builder.loader.loadNextMainScript(); }

0 commit comments

Comments
 (0)