-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rules): add 'missing-wait-message' rule
- Loading branch information
Showing
5 changed files
with
77 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Missing wait timeout message in `browser.wait()` (missing-wait-message) | ||
|
||
Ensure the timeout message is set when `browser.wait()` is called. | ||
|
||
## Rule details | ||
|
||
This rule triggers a warning if there is no message in case `browser.wait()` timeouts. | ||
Having explicit timeout messages helps in debugging and troubleshooting the test failures. | ||
|
||
The following patterns are considered warnings: | ||
|
||
```js | ||
browser.wait(EC.presenceOf(elm), 5000); | ||
browser.wait(EC.visibilityOf(elm), 5000); | ||
``` | ||
|
||
The following patterns are not warnings: | ||
|
||
```js | ||
browser.wait(EC.presenceOf(elm), 5000, "The user menu is not present"); | ||
browser.wait(EC.elementToBeClickable(elm), 5000, "The submit button has not become clickable. Watch for the modal popup not to be opened."); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict' | ||
|
||
/** | ||
* @fileoverview Missing wait timeout message in browser.wait() (missing-wait-message) | ||
* @author Alexander Afanasyev | ||
*/ | ||
|
||
module.exports = function (context) { | ||
return { | ||
'CallExpression': function (node) { | ||
var objectName = node.callee.object.name | ||
var propertyName = node.callee.property.name | ||
|
||
if (propertyName === 'wait' && objectName === 'browser' && node.arguments.length < 3) { | ||
context.report(node, 'No timeout message provided for browser.wait()') | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict' | ||
|
||
var rule = require('../../lib/rules/missing-wait-message') | ||
var RuleTester = require('eslint').RuleTester | ||
|
||
var eslintTester = new RuleTester() | ||
|
||
eslintTester.run('missing-wait-message', rule, { | ||
valid: [ | ||
'browser.wait(EC.presenceOf(elm), 5000, \'The user menu is not present\');', | ||
'browser.wait(EC.elementToBeClickable(elm), 5000, \'The submit button has not become clickable. Watch for the modal popup not to be opened\');' | ||
], | ||
|
||
invalid: [ | ||
{ | ||
code: 'browser.wait(EC.presenceOf(elm), 5000);', | ||
errors: [ | ||
{ | ||
message: 'No timeout message provided for browser.wait()' | ||
} | ||
] | ||
}, | ||
{ | ||
code: 'browser.wait(EC.visibilityOf(elm), 5000);', | ||
errors: [ | ||
{ | ||
message: 'No timeout message provided for browser.wait()' | ||
} | ||
] | ||
} | ||
] | ||
}) |