Last active
January 18, 2019 16:45
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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