Nightwatch "Expect" API assertions are not working
See original GitHub issueI’m submitting a … (check one with “x”)
[x] bug report
[ ] feature request
[ ] support request => Please do not submit support request here, instead use https://groups.google.com/d/forum/nightwatch-cucumber
Current behavior The step using “Expect” assertions API always succeeds.
Expected/desired behavior The step using “Expect” assertions API should fail in case of not met condition.
Reproduction of the problem
Scenario: Home page greets politely
Then the page should contain text "Hello World!"
Then(/^the page should contain text "(.*?)"$/, (text) => {
return client.expect.element('body').text.to.contain(text);
});
What is the expected behavior? Nightwatch “Expect” assertions API should work the same as “Assert” API
What is the motivation / use case for changing the behavior? “Expect” API is very easy to use and favored by Nightwatch team.
Please tell us about your environment:
-
nightwatch-cucumber version: 7.0.7
-
nightwatch version: 0.9.12
-
cucumber version: 2.0.0-rc.6
-
Node.js version: 6.9.4
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Nightwatch assertions | Developer Guide
The expect assertions use a subset of the Expect api from the Chai framework and at this point are available for elements, cookies,...
Read more >expect.element().to.not.be.present throws error when using ...
Describe the bug When testing assertion that element is not present on page, error is thrown when element is not found.
Read more >Expect Assertions not working in Nightwatch - Stack Overflow
All other Nightwatch commands and assertions are working, but when I try to use Expect assertions I get an error: .expect.element(.
Read more >Fixing 'expect' assertions in Nightwatch.js | by Simon W - ITNEXT
Now all of your expect API assertions will be functions, rather than property accessors! That original test snippet will now look like this:...
Read more >Chapter 5.1 - Expect and Assert - Test Automation University
Chapter 1 - Installing & Configuring Nightwatch.js · Chapter 2 - Test Runners · Chapter 3.1 - Finding Elements · Chapter 3.2 -...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hi @mucsi96 !
I’ve investigated this issue as well. So you are right, that Nightwatch assertions do not throw exceptions. But the difference between “assert” and “expect” APIs is that the later does not return client’s api (promisified one) after adding command to CommandQueue.
Having in mind above findings, I was able to use below workaround:
“perform” fits perfectly here because even in Nightwatch API docs it is written that it:
On the other hand, it would be much better to have ability to assert using Expect API in some terser way. Before closing this issue, I will spend some more time on investigation whether I could come up with any terser approach. If you have any ideas, please share.
Thanks!
Hi @mucsi96 , I found one more issue related to the same expect api and raised a pull request. Could you please review it?