The thing is, evaluate()
returns Promise , which is a Javascript subject, not a nightmare.
Thus, Promise has then
and catch
methods, among other things, but obviously does not have a wait
method.
I believe this , and this resource will help you understand the concept a little better.
Apply the concept to your scenario, the code will look like this:
describe('test google search results', function() { this.timeout(15000); it('should find the nightmare github link first', function(done) { var nightmare = Nightmare({show: true}) nightmare .goto('http://google.com') .wait(1000) .type('form[action*="/search"] [name=q]', 'github nightmare') .click('form[action*="/search"] [type=submit]') .wait(1000)//.wait('#rcnt') .evaluate(function () { return document.querySelector('div.rc h3.r a').href }) .then(function(link) { console.log("TESTING 1"); expect(link).to.equal('https://github.com/segmentio/nightmare'); nightmare.evaluate(function () { return document.querySelector('div.rc h3.r a').href }) .end() .then(function(link) { console.log("TESTING 2"); expect(link).to.equal('https://github.com/segmentio/nightmare'); done(); }) }).catch(function(error) { done(new Error(error)) }) }); });
Notice that the second call to evaluate
is inside the first callback then
.
source share