Reputation: 473933
Recently, I've noticed that one of our tests has the following line:
browser.actions().sendKeys(protractor.Key.RETURN);
The intent is understandable, but it would actually do nothing since perform()
was not called. For some reason, the test itself was passing which indicates a problem in the logic of the test and the following expectations.
How can I spot this kind of problems as early as possible and, ideally, prevent this protractor/WebDriverJS usage violation to be committed into the repository?
Upvotes: 1
Views: 141
Reputation: 5113
I expect this could be achieved via a (scriptable) editor plugin or linter rule.
That said, surely the best way to evaluate the test script is to run it for real - but also to ensure that all test actions have a corresponding assertion / validation.
Your Key.RETURN
must presumably have some effect on the DOM, or initiate some action, the result of which can be detected (page changes, data changes, etc.) and which is probably meaningful and easier to read than a static analysis rule.
Upvotes: 1
Reputation: 473933
One option would be to use static code analysis - there is an ESLint
linting utility that has a set of different plugins. Nowadays, there is a eslint-plugin-protractor
plugin that, aside from other protractor-specific violations, would catch browser.actions()
without perform()
.
Here is the output of a ESLint
run in this case:
/Users/user/job/app/specs/test.spec.js
36:13 error No perform() called on browser.actions() protractor/missing-perform
Upvotes: 1