I am new to Nightwatch.js and am moving some tests over from the WD.js library. One nifty feature of WD.js is .waitForConditionInBrowser(), which waits for an arbitrary JavaScript snippet to be truthy. I am however unable to figure out how to interact with the JavaScript this way in Nightwatch.js, or if it's even possible (after perusing the docs). Here is an example of what I want to do:
Let's say I am loading a page where after about 3 seconds my_js_var becomes 5. In WD.js, it would look like this (wait max. 5 seconds):
.get(my_page_url)
.waitForConditionInBrowser('my_js_var === 5', 5000)
// continue if my_js_var === 5 within 5 s
I even tried doing something more dirty in Nightwatch, but I am probably misunderstanding how interaction with page JS works at all:
.url(my_page_url)
.pause(5000)
.execute(function() {
return (my_js_var === 5);
})
// continue if my_js_var === 5 within 5 s
But it just continues no matter what is returned, and it's unclear where the result goes to.
Is there a proper waitFor function in Nightwatch, and if not, how do I run basic assertions on evaluated JavaScript code?