Reputation: 2109
I wanted to get screenshot of my web app using nightmare. When there is no error while running the code and exits are clean, no phantomjs instances are left behind.
var Nightmare = require('nightmare');
var Screenshot = require('nightmare-screenshot');
var nightmare = new Nightmare();
var url = process.argv[2];
var url = process.argv[3];
nightmare
.goto(url)
.wait('#selector')
.use(Screenshot.screenshotSelector(path, '#selector'))
.run(function (err, nightmare) {
if (err)
console.log('Error');
else
console.log('Done.');
nightmare.teardownInstance();
nightmare.end();
});
However, when there is some error like web is not running, selector is not present. The instance of phantomjs remain unexited.
$ ps -ax | grep phantom
6065 ttys004 0:00.00 grep phantom
6050 ttys005 0:02.87 phantomjs --load-images=true --ignore-ssl-errors=true --ssl-protocol=any --web-security=true /.../node_modules/phantom/shim.js 13201 127.0.0.1
How could I properly exit its instance even when there is any error?
Upvotes: 1
Views: 554
Reputation: 635
Presently, the .wait(elem)
keeps on looping to check if the element is present or not every 250ms. You can report this to the developer to add passing additional parameter to stop the checks after a specific timeout to exit gracefully.
Alternatively, you can fix the issue by manually checking the presence of the element for a certain timeout and then exiting the process.
you can use wait(fn)
for performing the check.
Upvotes: 1