These are chat archives for rosshinkley/nightmare

21st
Dec 2016
Emil Shakirov
@vaihtovirta
Dec 21 2016 18:38

Hi all!

I'm curious, is it possible to use generator functions with use()?

I want to something like this, but I wasn't able to make it work:

var Nightmare = require('nightmare');
var nightmare = Nightmare();

login(nightmare) {
  return nightmare
    // some login related stuff
}]

var checkIfVerificationFormExists = function*(nightmare) {
  var exists = yield nightmare.exists("#some_selector");

  if (exists) {
    return nightmare.goto("/some-url")
  } 

  return nightmare;
}


nightmare
  .use(login())
  .use(checkIfVerificationFormExists())
  .use(someAnotherPluginFunction())
  .end()
  .then()
johnferro
@johnferro
Dec 21 2016 20:52
Part of the problem might be that the use function itself shouldn't be async but just returns a function that takes nightmare as its sole argument. See: https://github.com/rosshinkley/nightmare-examples/blob/master/docs/beginner/use.md