Skip to content

Commit 5c62948

Browse files
committed
added 'message' parameter to all commands that are eventemitters
1 parent 4ac3167 commit 5c62948

21 files changed

+140
-29
lines changed

docs/saveElementScreenshot.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Author: maxgalbu
2828

2929
* **String** *elementSelector* - css/xpath selector for the element
3030
* **Function** *fileName* - file path where the screenshot is saved
31+
* **String** *[defaultMessage]* - message to display
3132

3233
<!-- End es6/commands/saveElementScreenshot.js -->
3334

docs/setValueAndTrigger.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Author: maxgalbu
1414
* **String** *selector* - jQuery selector for the element
1515
* **String** *value* - value of the element to be set
1616
* **Function** *[callback]* - function that will be called after the change event is triggered
17+
* **String** *[message]* - message to display
1718

1819
<!-- End es6/commands/setValueAndTrigger.js -->
1920

docs/waitForAttribute.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ See: https://github.com/beatfactor/nightwatch/issues/246#issuecomment-59461345
2525
* **String** *attribute* - attribute to be checked
2626
* **Function** *checker* - function that must return true if the attribute matches, false otherwise
2727
* **Integer** *[timeoutInMilliseconds]* - timeout of this wait commands in milliseconds
28+
* **String** *[defaultMessage]* - message to display
2829

2930
<!-- End es6/commands/waitForAttribute.js -->
3031

docs/waitForJqueryAjaxRequest.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Author: maxgalbu
1717
### Params:
1818

1919
* **Integer** *[timeoutInMilliseconds]* - timeout of this wait commands in milliseconds
20+
* **String** *[defaultMessage]* - message to display
2021

2122
<!-- End es6/commands/waitForJqueryAjaxRequest.js -->
2223

docs/waitForJqueryElement.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Author: maxgalbu
2020

2121
* **String** *elementSelector* - jquery selector for the element
2222
* **Integer** *[timeoutInMilliseconds]* - timeout of this wait commands in milliseconds
23+
* **String** *[defaultMessage]* - message to display
2324

2425
<!-- End es6/commands/waitForJqueryElement.js -->
2526

docs/waitForText.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ See: https://github.com/beatfactor/nightwatch/issues/246#issuecomment-59461345
2424
* **String** *elementSelector* - css/xpath selector for the element
2525
* **Function** *checker* - function that must return true if the element's text matches your requisite, false otherwise
2626
* **Integer** *[timeoutInMilliseconds]* - timeout of this wait commands in milliseconds
27+
* **String** *[defaultMessage]* - message to display
2728

2829
<!-- End es6/commands/waitForText.js -->
2930

docs/waitForTitle.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ See: https://github.com/beatfactor/nightwatch/issues/246#issuecomment-59461345
2323

2424
* **Function** *checker* - function that must return true if the title matches your requisite, false otherwise
2525
* **Integer** *[timeoutInMilliseconds]* - timeout of this wait commands in milliseconds
26+
* **String** *[defaultMessage]* - message to display
2627

2728
<!-- End es6/commands/waitForTitle.js -->
2829

es6/commands/saveElementScreenshot.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,19 @@
2323
* @author maxgalbu
2424
* @param {String} elementSelector - css/xpath selector for the element
2525
* @param {Function} fileName - file path where the screenshot is saved
26+
* @param {String} [defaultMessage] - message to display
2627
*/
2728

2829
import events from 'events';
2930
import easyimg from 'easyimage';
3031

3132
class SaveElementScreenshotAction extends events.EventEmitter {
32-
command(elementSelector, fileName) {
33+
command(elementSelector, fileName, defaultMessage) {
34+
if (defaultMessage && typeof defaultMessage !== 'string') {
35+
this.emit('error', "defaultMessage is not a string");
36+
return;
37+
}
38+
3339
this.api.getElementSize(elementSelector, sizeResult => {
3440
return this.api.getLocation(elementSelector, locationResult => {
3541
return this.api.saveScreenshot(fileName, () => {
@@ -51,8 +57,19 @@ class SaveElementScreenshotAction extends events.EventEmitter {
5157
y: location.y,
5258
gravity: 'North-West'
5359
}).then(
54-
file => this.emit("complete"),
55-
err => (console.error(err), this.emit("complete"))
60+
file => {
61+
let message = `Saved screenshot for <${elementSelector}> to ${fileName}`;
62+
if (defaultMessage) {
63+
message = defaultMessage;
64+
}
65+
66+
this.client.assertion(result, 'expression false', 'expression true', message, true);
67+
return this.emit("complete");
68+
},
69+
err => {
70+
this.emit('error', `SaveElementScreenshotAction: could not save screenshot (error is ${err})`);
71+
return this.emit("complete");
72+
}
5673
);
5774

5875
}

es6/commands/setValueAndTrigger.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* @param {String} selector - jQuery selector for the element
1010
* @param {String} value - value of the element to be set
1111
* @param {Function} [callback] - function that will be called after the change event is triggered
12+
* @param {String} [message] - message to display
1213
*/
1314

1415
//=include ../getMultipleSelectors.js

es6/commands/waitForAttribute.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import events from 'events';
1919
* @param {String} attribute - attribute to be checked
2020
* @param {Function} checker - function that must return true if the attribute matches, false otherwise
2121
* @param {Integer} [timeoutInMilliseconds] - timeout of this wait commands in milliseconds
22+
* @param {String} [defaultMessage] - message to display
2223
*/
2324

2425
class WaitForAttribute extends events.EventEmitter {
@@ -40,7 +41,7 @@ class WaitForAttribute extends events.EventEmitter {
4041
}
4142
}
4243

43-
command(elementSelector, attribute, checker, timeoutInMilliseconds) {
44+
command(elementSelector, attribute, checker, timeoutInMilliseconds, defaultMessage) {
4445
//Save the origian locate strategy, because if this command is used with
4546
//page objects, the "checker" function of this command is wrapped with another
4647
//function which resets the locate strategy after the function is called,
@@ -56,10 +57,16 @@ class WaitForAttribute extends events.EventEmitter {
5657
if (typeof timeoutInMilliseconds !== 'number') {
5758
timeoutInMilliseconds = this.defaultTimeoutInMilliseconds;
5859
}
60+
if (defaultMessage && typeof defaultMessage !== 'string') {
61+
this.emit('error', "defaultMessage is not a string");
62+
return;
63+
}
5964

6065
this.check(elementSelector, attribute, checker, (result, loadedTimeInMilliseconds) => {
6166
let message = "";
62-
if (result) {
67+
if (defaultMessage) {
68+
message = defaultMessage;
69+
} else if (result) {
6370
message = `waitForAttribute: ${elementSelector}@${attribute}. Expression was true after ${loadedTimeInMilliseconds - this.startTimeInMilliseconds}.`;
6471
} else {
6572
message = `waitForAttribute: ${elementSelector}@${attribute}. Expression wasn't true in ${timeoutInMilliseconds} ms.`;

0 commit comments

Comments
 (0)