Even after substituting the fancy ampersands on your homepage, and requiring nightmare your example still does not run:<p><pre><code> var Nightmare = require('nightmare');
new Nightmare()
.goto('http://yahoo.com')
.type('input[title="Search"]', 'github nightmare')
.click('.searchsubmit')
.run();
</code></pre>
yields:<p><pre><code> node yahoo.js
phantom stdout: TypeError: 'null' is not an object (evaluating 'element.value = text')
phantom stdout: phantomjs://webpage.evaluate():3
phantomjs://webpage.evaluate():4
phantomjs://webpage.evaluate():4
stream.js:94
throw er; // Unhandled stream error in pipe.
^
TypeError: undefined is not a function
at next (/private/tmp/night/node_modules/nightmare/lib/index.js:56:23)
at f (/private/tmp/night/node_modules/nightmare/node_modules/once/once.js:16:25)
at Proto.apply (/private/tmp/night/node_modules/nightmare/node_modules/phantom/node_modules/dnode/node_modules/dnode-protocol/index.js:123:13)
at Proto.handle (/private/tmp/night/node_modules/nightmare/node_modules/phantom/node_modules/dnode/node_modules/dnode-protocol/index.js:99:19)
at D.dnode.handle (/private/tmp/night/node_modules/nightmare/node_modules/phantom/node_modules/dnode/lib/dnode.js:140:21)
at D.dnode.write (/private/tmp/night/node_modules/nightmare/node_modules/phantom/node_modules/dnode/lib/dnode.js:128:22)
at SockJSConnection.ondata (stream.js:51:26)
at SockJSConnection.EventEmitter.emit (events.js:107:17)
at Session.didMessage (/private/tmp/night/node_modules/nightmare/node_modules/phantom/node_modules/shoe/node_modules/sockjs/lib/transport.js:220:25)
at WebSocketReceiver.didMessage (/private/tmp/night/node_modules/nightmare/node_modules/phantom/node_modules/shoe/node_modules/sockjs/lib/trans-websocket.js:102:40)
</code></pre>
The examples in the githubs pages readme don't run either.
I am too lazy to debug this.
Quick example of how we use this at Segment... for each integration (<a href="https://segment.io/integrations" rel="nofollow">https://segment.io/integrations</a>) we need to create a vector logo. This got a bit tedious after the first 50 :) so we built nightmare + nightmare-swiftly so that our chat bot could "auto-generate" vector logos: <a href="https://cloudup.com/cEA-dTd3glM" rel="nofollow">https://cloudup.com/cEA-dTd3glM</a><p>Hope it's helpful!
Could I accomplish multi-page form automation doing something like:<p><pre><code> .goto(page1)
// page 1
.type('selector', 'value')
.click('selector')
.wait()
// page 2
.type('selector', 'value')
.click('selector')
.wait()
</code></pre>
etc. ?<p>If so, that seems super easy and more straightforward than vanilla Shadow or even Casper.
I've been wanting to programmatically get my transaction details from my bank for a while. I knew about phantomJS but never got around to trying it out. When I saw this I decided to give it a shot, and within half an hour I was able to log into my bank's website (a complicated multi-step process that I had failed to achieve with just POST requests).<p>Nice tool, thanks. The debugging could use a bit of work - whenever something went wrong it just spit out a bunch of "null is not an object" messages from phantom. Overall it was very easy to use though.
I am one of the founders of a startup that sells a similar, proprietary library for Python and Java: <a href="http://heliumhq.com" rel="nofollow">http://heliumhq.com</a>. Maybe some of the people reading this will find it interesting.
It's a polished website... and I know what javascript is, but they didn't do a good job of explaining what it is.<p>Browser automation? Is this a test suite of some sort, something like selenium? Or is it more like Mechanize?
I do like the work they've done with Phantom but the API is horrendous and I found myself wrapping the parts I used. Nightmare looks more complete and probably better tested than my wrapper. Well done.
Looks like an interesting library. I have no use for it right now but maybe one day. Definitely can see why this would be useful for some people though.<p>Their website has some serious style. It looks cool and original. Which raises a meta-issue that has been bugging me for a while. This is the bar you have to meet for even an open source project nowadays. It's not enough for you to pour your blood sweat and tears into something and then give it away for free. You then have to create slick looking site to market it and get people's attention.
obligatory self-promotion, for those interested in an easy to use PhantomJs: <a href="https://PhantomJsCloud.com" rel="nofollow">https://PhantomJsCloud.com</a>
I use Ubuntu Linux, and I've got PhantomJS installed. Whether I use Nightmare, Nightmarejs, or Phantomjs on the command line this is what I get:
ReferenceError: Can't find variable: Nightmare<p><pre><code> nightmare.js:1
</code></pre>
Should there be more instructions for installing? I believe the brew command is something for Mac users only...
Shameless plug: I maintain Node-huxley (<a href="https://github.com/chenglou/node-huxley" rel="nofollow">https://github.com/chenglou/node-huxley</a>), which accomplishes what this project does, but without the need for writing automation code. Also compares previous/next screenshots for you automatically.
I currently only have experience using CasperJS which also wraps-around PhantomJS. This has different goals (simpler) and therefore a simpler API, though. The use case at Segment (automatically generating vector logos from a given graphic) is even cooler though, I think! Thanks for sharing!
Nice work!<p>Can you please provide an example for using `evaluate()` to get the page's content?<p>I tried this, but didn't get anything:<p><pre><code> new Nightmare()
.goto('http://yahoo.com')
.evaluate(function (page) { return this.content; }, function (res) {console.log(res);})
.run();</code></pre>
And, if you want a very very thin wrapper around Phantom (essentially a phantom script manager), feel free to have a look at this instead:<p><a href="https://github.com/andrey-p/ectoplasm-js" rel="nofollow">https://github.com/andrey-p/ectoplasm-js</a><p>Pardon the shameless plug.
What is the project's background image (<a href="http://www.nightmarejs.org/nightmarejs.org/images/ground.jpg" rel="nofollow">http://www.nightmarejs.org/nightmarejs.org/images/ground.jpg</a>)?
As someone entirely unfamiliar with both Nightmare and PhantomJS, what is the typical use case? It isn't obvious to me from the examples or FAQs. Why prefer these over something like Selenium?
Very nice. FYI best practices are to have a CTA or indicator on your site to scroll down, so no one leaves thinking the whole site is just an image and title.
so... how does one query the DOM? It looks it has been left out of the api. Does this mean that Nightmare is only able to do brainless automation without checking browser results?
Ordinarily I would file a website bug, but this happens so often I'm mentioning it here to hopefully stop others from doing it, too.<p><i>Please</i> don't use fancy quotes or the fancy apostrophe for code examples on your webpage. It looks out-of-place with the rest of the fixed width font and, most importantly, it stops folks from being able to copy-and-paste your examples into their terminal or editor.
the problem with Phantom.js is that compared to an actual browser it still falls short. I've given up on Phantom.js all together because it is actually not a true replacement for Selenium running on an actual browser. I found it far more reliable to have Firefox running on Xvfb for when I'm testing without worrying about Phantom.js behaving wildly.