Reputation: 11
I'm trying to get two screenshots of two different pages with Nightmare.js. On the first page, I need to login, after that, the page fires a popup with some information about the user.
The problem is that I can't get the second screenshot even though the login was successful.
Here is my code:
var Nightmare = require('nightmare');
var vo = require('vo');
var urls = [];
urls.push('http://www.somepage1.com/');
urls.push('http://subdomine.somepage2.com/user');
var sizes = [];
sizes.push({width: 1024, height: 768});
var login = {
user: 'xxx',
password: 'xxx'
};
var navigate = function(nightmare) {
return function(nightmare) {
nightmare
.wait()
.type('#user', login.usuario) // Substitute with your username
.type('#password', login.password) // Substitute with your password
.click('#btnLogin')
.wait(10000);
};
};
for(u in urls) {
var nightmare = new Nightmare();
var size = sizes[0];
var filename = 'screen-' + String("0" + u).slice(-2) + '-' + size.width + '.png';
var url = urls[u];
nightmare
.viewport(size.width, size.height)
.goto(url)
.wait()
.use(navigate(nightmare))
.screenshot(filename)
.run(function(err, nightmare){
console.log('Done.');
});
}
It needs to run in NodeJS.
Upvotes: 1
Views: 557