Skip to content

Instantly share code, notes, and snippets.

@gustavomdsantos
Last active January 18, 2019 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gustavomdsantos/317806f3f3e90a3f56b79780e9676978 to your computer and use it in GitHub Desktop.
Save gustavomdsantos/317806f3f3e90a3f56b79780e9676978 to your computer and use it in GitHub Desktop.
nightmare-initializer: Aplica o workaround para o 'navigation error' do Nightmare, quando a aplicação Web faz redirect de página.
const Nightmare = require('nightmare');
var NightmareInitializer = {};
NightmareInitializer.initialize = function (URLToTest, callback) {
var nightmare = Nightmare({ show: true, width: 1024, height: 768 });
auth = {
username: 'john',
password: 'doe'
};
/* Faz login no webapp para iniciar os testes. */
var _fazLogin = function (nightmare, auth, callback) {
nightmare
.wait('input#username')
.type('input#username', auth.username)
.type('input#password', auth.password)
.click('button#botaoEnviar');
return callback(nightmare);
};
nightmare
.goto(URLToTest)
// "Empty evaluate", soluciona 'navigation error' no Nightmare ao abrir o webapp
// https://github.com/segmentio/nightmare/issues/1070#issuecomment-300267828
.evaluate(() => { })
.then(() => _fazLogin(nightmare, auth, callback))
.catch(error => {
return _fazLogin(nightmare, auth, callback);
});
}
module.exports = NightmareInitializer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment