EzDevInfo.com

zombie

Insanely fast, full-stack, headless browser testing using node.js Zombie by assaf

How to install Zombie JS on Windows 7? (node.js headless browser)

I am having issues, could you point me in the right direction?

EDIT: This module (Contextify) will not install from npm on Windows. See https://github.com/brianmcd/contextify/issues/10 for more info.

This is because npm doesn't support C++ modules on Windows yet: https://github.com/brianmcd/contextify/issues/14#issuecomment-3577972

Generally I would like to run http://zombie.labnotes.org - for Windows they are suggesting:

On Windows you'll need Cygwin to get access to GCC, Python, etc. Read this for detailed instructions and troubleshooting: https://github.com/joyent/node/wiki/Building-node.js-on-Cygwin-(Windows)

The problem is - they say Cygwin description is outdated and suggest using Visual Studio... Either way I got both and I am taking my chances by using nodejs installer rather that building it from scratch (error doesn't seem related to it). And here are the steps I'm doing:

1) Installed node.js using installer: http://nodejs.org/#download

2) Got NPM package manager: https://github.com/isaacs/npm

3) Got Python 2.7, Visual Studio 2010 (as some sources indicated C++ compiler as necessary) and Cygwin...

4) As the installer fails at contextify I searched for it

Use the pre-built binary just download the ZIP file at https://github.com/Benvie/contextify/zipball/master , extract it into your node_modules folder, and then rename the folder to "contextify"

c:\Program Files (x86)\nodejs>node --version
v0.6.13

c:\Program Files (x86)\nodejs>npm install zombie
npm http GET https://registry.npmjs.org/zombie
npm http 304 https://registry.npmjs.org/zombie
npm http GET https://registry.npmjs.org/ws
npm http GET https://registry.npmjs.org/jsdom/0.2.10
npm http GET https://registry.npmjs.org/mime
npm http GET https://registry.npmjs.org/coffee-script
npm http 304 https://registry.npmjs.org/ws
npm http 304 https://registry.npmjs.org/mime
npm http 304 https://registry.npmjs.org/jsdom/0.2.10
npm http 304 https://registry.npmjs.org/coffee-script

> ws@0.4.10 preinstall c:\Program Files (x86)\nodejs\node_modules\zombie\node_mo
dules\ws
> make

        1 file(s) copied.
        1 file(s) copied.
npm http GET https://registry.npmjs.org/commander/0.5.0
npm http GET https://registry.npmjs.org/options
npm http 304 https://registry.npmjs.org/options
npm http 304 https://registry.npmjs.org/commander/0.5.0
npm http GET https://registry.npmjs.org/contextify
npm http GET https://registry.npmjs.org/request
npm http GET https://registry.npmjs.org/htmlparser
npm http GET https://registry.npmjs.org/cssom
npm http 304 https://registry.npmjs.org/contextify
npm http 304 https://registry.npmjs.org/htmlparser
npm http 304 https://registry.npmjs.org/request
npm http 304 https://registry.npmjs.org/cssom

> contextify@0.0.7 preinstall c:\Program Files (x86)\nodejs\node_modules\zombie\
node_modules\jsdom\node_modules\contextify
> node-waf clean || (exit 0); node-waf configure build

node-waf was unexpected at this time.

npm ERR! Error: ENOENT, chmod 'c:\Program Files (x86)\nodejs\node_modules\zombie
\node_modules\jsdom\node_modules\request\tests\squid.conf'
npm ERR! You may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <npm-@googlegroups.com>
npm ERR!
npm ERR! System Windows_NT 6.1.7600
npm ERR! command "c:\\Program Files (x86)\\nodejs\\\\node.exe" "c:\\Program File
s (x86)\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "zombie"
npm ERR! cwd c:\Program Files (x86)\nodejs
npm ERR! node -v v0.6.13
npm ERR! npm -v 1.1.9
npm ERR! path c:\Program Files (x86)\nodejs\node_modules\zombie\node_modules\jsd
om\node_modules\request\tests\squid.conf
npm ERR! fstream_path c:\Program Files (x86)\nodejs\node_modules\zombie\node_mod
ules\jsdom\node_modules\request\tests\squid.conf
npm ERR! fstream_type File
npm ERR! fstream_class FileWriter
npm ERR! fstream_finish_call chmod
npm ERR! code ENOENT
npm ERR! message ENOENT, chmod 'c:\Program Files (x86)\nodejs\node_modules\zombi
e\node_modules\jsdom\node_modules\request\tests\squid.conf'
npm ERR! errno {}
npm ERR! fstream_stack Object.oncomplete (c:\Program Files (x86)\nodejs\node_mod
ules\npm\node_modules\fstream\lib\writer.js:285:17)

npm ERR! Error: ENOENT, lstat 'c:\Program Files (x86)\nodejs\node_modules\zombie
\node_modules\jsdom\node_modules\htmlparser\runtests.html'
npm ERR! You may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <npm-@googlegroups.com>
npm ERR!
npm ERR! System Windows_NT 6.1.7600
npm ERR! command "c:\\Program Files (x86)\\nodejs\\\\node.exe" "c:\\Program File
s (x86)\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "zombie"
npm ERR! cwd c:\Program Files (x86)\nodejs
npm ERR! node -v v0.6.13
npm ERR! npm -v 1.1.9
npm ERR! path c:\Program Files (x86)\nodejs\node_modules\zombie\node_modules\jsd
om\node_modules\htmlparser\runtests.html
npm ERR! fstream_path c:\Program Files (x86)\nodejs\node_modules\zombie\node_mod
ules\jsdom\node_modules\htmlparser\runtests.html
npm ERR! fstream_type File
npm ERR! fstream_class FileWriter
npm ERR! code ENOENT
npm ERR! message ENOENT, lstat 'c:\Program Files (x86)\nodejs\node_modules\zombi
e\node_modules\jsdom\node_modules\htmlparser\runtests.html'
npm ERR! errno {}
npm ERR! fstream_stack Object.oncomplete (c:\Program Files (x86)\nodejs\node_mod
ules\npm\node_modules\fstream\lib\writer.js:204:26)
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     c:\Program Files (x86)\nodejs\npm-debug.log
npm not ok

c:\Program Files (x86)\nodejs>

What steps do I need to make in order to make it operational?

If building nodejs from sources to install a package is required then please say it loud :)

Thanks for helping!


Source: (StackOverflow)

what browser does zombie.js use?

So I came across zombie.js, is this a headless browser?

If so, what browser engine does it use?

Could I rely on it for doing lot of automated tests? Basically, I am restricted to a single server, so I would like to squeeze as many browser tests as possible.

Currently, I am relying on Selenium FirefoxDriver to run my tests. How would zombie.js compare in performance and efficiency to Selenium Webdriver browser instances running? However, there's limitation to how many browser instances I can run in parallel.


Source: (StackOverflow)

Advertisements

How to use browser.wait() in zombie.js?

I've got a Web application that continuously polls for data from the server using Ajax requests. I would like to implement an integration test for it using zombie.js.

What I am trying to do is to wait until the Ajax poll loop receives data from the server. The data should be received after 20 seconds, so I use browser.wait(done, callback) to check if the data is there, and set waitFor to a maximum timeout of one minute.

However, browser.wait() always returns almost immediately, even if my done callback returns false.

In the zombie API documentation, I read the following about browser.wait():

... it can't wait forever, especially not for timers that may fire repeatedly (e.g. checking page state, long polling).

I guess that's the reason for the behavior I see, but I don't really understand what's going on. Why can't I wait for one minute until my poll loop receives data from the server? Why can't browser.wait() wait for timers that may fire repeatedly? What do I need to do to implement my test?


Source: (StackOverflow)

Node.js - why do I get leaks when testing with mocha and zombie?

I've tried to make zombie work with mocha, but unless I use the mocha --ignore-leaks command options, my test always fails with the error:

Error: global leaks detected: k, i, name, chars, char

My test looks exactly like the one explained in this thread: Mocha and ZombieJS

I wish I could have posted my question there, but as a newbie, I cannot comment on the thread, only ask a new question.

Do you have any idea why I get these leaks? I'm using mocha 1.0.3 and zombie 1.0.0.


Source: (StackOverflow)

Zombie.js "assert is not defined" for multiple visits?

I'm setting up integration testing with Zombie.js and Mocha, and running into the puzzling problem that only the first browser.visit() call seems to succeed. My specs look like this:

browser = new Browser site: "http://localhost:101010"

describe '/docs', ->
  ['app', 'server', 'timetable', 'util'].forEach (file) ->
    describe "/#{file}.html", -> it "documents #{file}.coffee", (done) ->
      browser.visit "/docs/#{file}.html", ->
        browser.text('title').should.equal "#{file}.coffee"
        do done

The first of those tests, which loads /docs/app.html, passes without incident. However, all subsequent tests fail, producing a stacktrace like the following:

 ReferenceError: assert is not defined
  at Object.HTML5Parser.phases.inBody.startTagBody (/home/$USER/projects/timetable/node_modules/zombie/node_modules/html5/lib/html5/parser.js:1828:4)
  at Object.HTML5Parser.phases.base.processStartTag (/home/$USER/projects/timetable/node_modules/zombie/node_modules/html5/lib/html5/parser.js:65:40)
  at EventEmitter.Parser.do_token (/home/$USER/projects/timetable/node_modules/zombie/node_modules/html5/lib/html5/parser.js:2436:21)
  at EventEmitter.<anonymous> (/home/$USER/projects/timetable/node_modules/zombie/node_modules/html5/lib/html5/parser.js:2457:30)
  at EventEmitter.emit (events.js:117:20)
  at EventEmitter.emitToken (/home/$USER/projects/timetable/node_modules/zombie/node_modules/html5/lib/html5/tokenizer.js:99:9)
  at emit_current_token (/home/$USER/projects/timetable/node_modules/zombie/node_modules/html5/lib/html5/tokenizer.js:873:3)
  at tag_name_state (/home/$USER/projects/timetable/node_modules/zombie/node_modules/html5/lib/html5/tokenizer.js:400:4)
  at EventEmitter.<anonymous> (/home/$USER/projects/timetable/node_modules/zombie/node_modules/html5/lib/html5/tokenizer.js:941:10)
  at EventEmitter.emit (events.js:95:17)
  at EventEmitter.HTML5Tokenizer.pump (/home/$USER/projects/timetable/node_modules/zombie/node_modules/html5/lib/html5/tokenizer.js:932:11)
  at EventEmitter.HTML5Tokenizer.tokenize (/home/$USER/projects/timetable/node_modules/zombie/node_modules/html5/lib/html5/tokenizer.js:89:23)
  at EventEmitter.Parser.parse (/home/$USER/projects/timetable/node_modules/zombie/node_modules/html5/lib/html5/parser.js:2391:17)
  at HtmlToDom.appendHtmlToElement (/home/$USER/projects/timetable/node_modules/zombie/node_modules/jsdom/lib/jsdom/browser/htmltodom.js:91:50)
  at Object.innerHTML (/home/$USER/projects/timetable/node_modules/zombie/node_modules/jsdom/lib/jsdom/browser/index.js:481:17)
  at Object.core.HTMLDocument.write (/home/$USER/projects/timetable/node_modules/zombie/node_modules/jsdom/lib/jsdom/level2/html.js:406:22)
  at Object.exports.jsdom (/home/$USER/projects/timetable/node_modules/zombie/node_modules/jsdom/lib/jsdom.js:70:9)
  at History._createDocument (/home/$USER/projects/timetable/node_modules/zombie/lib/zombie/history.js:174:22)
  at /home/$USER/projects/timetable/node_modules/zombie/lib/zombie/history.js:126:30
  at /home/$USER/projects/timetable/node_modules/zombie/lib/zombie/resources.js:147:16
  at Request._callback (/home/$USER/projects/timetable/node_modules/zombie/lib/zombie/resources.js:335:16)
  at Request.self.callback (/home/$USER/projects/timetable/node_modules/zombie/node_modules/request/main.js:120:22)
  at Request.EventEmitter.emit (events.js:98:17)
  at Request.<anonymous> (/home/$USER/projects/timetable/node_modules/zombie/node_modules/request/main.js:633:16)
  at Request.EventEmitter.emit (events.js:95:17)
  at IncomingMessage.<anonymous> (/home/$USER/projects/timetable/node_modules/zombie/node_modules/request/main.js:595:14)
  at IncomingMessage.EventEmitter.emit (events.js:117:20)
  at _stream_readable.js:872:14
  at process._tickCallback (node.js:415:13)

Is Zombie's browser.visit() not intended to be called more than once, or is there some other issue here?

Editing to note versions:

  • Node.js v0.10.1
  • Mocha v1.8.1
  • Chai v1.5.0
  • Zombie.js v1.4.1

Source: (StackOverflow)

Problems with web site scraping using zombie.js

I need to do some web scraping. After playing around with different web testing framework, of which most where either too slow (Selenium) or too buggy for my needs (env.js), I decided that zombie.js looks most promising, as it uses a solid set of libraries for HTML parsing and DOM manipulation. However, it seems to me like it doesn't even support basic event-based Javascript code like in the following web page:

<html>
  <head>
    <title>test</title>
    <script type="text/javascript">

      console.log("test script executing...");
      console.log("registering callback for event DOMContentLoaded on " + document);

      document.addEventListener('DOMContentLoaded', function(){
        console.log("DOMContentLoaded triggered");
      }, false);

      function loaded() {
        console.log("onload triggered");
      }

    </script>
  </head>

  <body onload="loaded();">
    <h1>Test</h1>
  </body>
</html>

I then decided to trigger those events manually like this:

zombie = require("zombie");

zombie.visit("http://localhost:4567/", { debug: true }, function (err, browser, status) {

  doc = browser.document;
  console.log("firing DOMContentLoaded on " + doc);
  browser.fire("DOMContentLoaded", doc, function (err, browser, status) {

    body = browser.querySelector("body");
    console.log("firing load on " + body);
    browser.fire("load", body, function (err, browser, status) {

      console.log(browser.html());

    });
  });

});

Which works for this particular test page. My problem is a more general one, though: I want to be able to scrape more complex, AJAX-based sites like a friends list on Facebook (something like http://www.facebook.com/profile.php?id=100000028174850&sk=friends&v=friends). It is no problem to log into the site using zombie, but some content like those lists seem to be completely loaded dynamically using AJAX, and I don't know how to trigger the event handlers that initiate the loading.

There are several questions I have regarding this problem:

  • Has somebody already implemented a similarly complex scraper without using a browser remote-controlling solution like Selenium?
  • Is there some reference on the loading process of a complex Javascript-based page?
  • Can somebody provide advice on how to debug a real browser to see what I might need to execute to trigger the Facebook event handlers?
  • Any other ideas about this topic?

Again, please do not point me to solutions involving controlling a real browser like Selenium, as I know about those. What is however welcome are suggestions for a real in-memory renderer like WebKit accessible from the Ruby scripting language, but preferrably with the possibility to set cookies and preferrably also load raw HTML instead of triggering real HTTP requests.


Source: (StackOverflow)

Performance of phantom.js vs zombie.js

I'm evaluating phantom.js and zombie.js. I expected the trade-off to be that phantom has wider documents support (since it uses a real renderer) while zombie is faster (since no rendering engine is used). However zombie seems much slower in the test I did. Does this make sense?

I am thinking maybe zombie waits for the full page to load before visit() returns (including running all scripts and loadsing css) while phantom returns immediatelly after start() (I used casperjs) allowing me to continue without waiting for the full page.

Phantom.js

casper.userAgent("Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.98 Safari/534.13");
casper.test.begin('bing search', 2, function(test) {   
    casper.start('http://www.bing.com/', function() {                        
        this.waitUntilVisible('#sb_form_q', function() { 
              this.sendKeys('#sb_form_q', "book", true);
              this.click('#sb_form_go');
              this.waitUntilVisible('#count', function() {        
                  var val = this.evaluate(function() {
                     return document.getElementById('count').innerText
                  });
                  console.log(val)
              });
           });
    }).run(function() {
        test.done();
    });
});

Zombie.js

var Browser = require("zombie");
var browser = new Browser()

browser.userAgent = "Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.98 Safari/534.13"

browser.visit("http://www.bing.com/", function () {
  browser.fill("#sb_form_q", "book");
           browser.pressButton("#sb_form_go");
             function resultArrived(window) {
               return window.document.querySelector("#count")
             }

             browser.wait(resultArrived, function() {
               console.log(browser.document.querySelector("#count").innerHTML)               
             })
 })

Source: (StackOverflow)

Setup/teardown of express.js application with mocha

I'm trying to create a standalone test suite using mocha, that in a perfect world would start up my express.js application, use zombie to render a page, check a bunch of stuff and then teardown/kill the express.js application.

Is there an easy/best way to do this?

NB. I could just have the express application server running prior to running the tests, but what good are Yaks if you're not going to shave them.


Source: (StackOverflow)

Mocha and ZombieJS

I'm starting a nodejs project and would like to do BDD with Mocha and Zombiejs. Unfortunately I'm new to just about every buzzword in that sentence. I can get Mocha and Zombiejs running tests fine, but I can't seem to integrate the two - is it possible to use Mocha to run Zombiejs tests, and if so, how would that look?

Just looking for "hello world" to get me started, but a tutorial/example would be even better.

Thanks!


Source: (StackOverflow)

How to activate javascript links with zombie.js

I am trying to get get zombie.js to activate a link that uses javascript. The page I am testing it on is:

 <html>
  <body>
  <div id="test123">
  START_TEXT
  </div>
  <a rel='nofollow' href="javascript:go()">GO</a><br/>
  <script type="text/javascript">
  go = function() {
  var el = document.getElementById("test123");
  el.innerHTML = "CHANGED";
  }
  </script>
  </body>
  </html>

The Script I am using is:

var zombie = require("zombie");
var browser = new zombie.Browser;

browser.visit( "http://localhost:8000/testpage.html",
        function() {
                browser.clickLink("GO", function(e, browser, status) {
                        var temp = browser.text("div#test123");
                        console.log("content:", temp);
                  });
});

I get the error message:

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
Error: Cannot load resource: javascript:go()
    at History._resource (/home/julian/temp/node_modules/zombie/lib/zombie/history.coffee:75:15)
    at History._pageChanged (/home/julian/temp/node_modules/zombie/lib/zombie/history.coffee:60:21)
    at History._assign (/home/julian/temp/node_modules/zombie/lib/zombie/history.coffee:213:19)
    at Object.location (/home/julian/temp/node_modules/zombie/lib/zombie/history.coffee:51:24)
    at Object.click (/home/julian/temp/node_modules/zombie/lib/zombie/jsdom_patches.coffee:31:59)
    at Object.dispatchEvent (/home/julian/temp/node_modules/zombie/node_modules/jsdom/lib/jsdom/level2/html.js:480:47)
    at /home/julian/temp/node_modules/zombie/lib/zombie/eventloop.coffee:130:16
    at EventLoop.perform (/home/julian/temp/node_modules/zombie/lib/zombie/eventloop.coffee:121:7)
    at EventLoop.dispatch (/home/julian/temp/node_modules/zombie/lib/zombie/eventloop.coffee:129:19)
    at Browser.dispatchEvent (/home/julian/temp/node_modules/zombie/lib/zombie/browser.coffee:220:30)

When I use

browser.evaluate("go()")

it works. What am I missing?


Source: (StackOverflow)

Node.js module that inspects DOM elements

I'm using zombie.js, a headless browser mostly for testing purposes. It creates a browser object that once the function visit() is called allows you to play with the DOM of a given page. However, I wasn't able to get it to that extent. It looks like there is an issue with the parser used in zombie. Here is the error:

User/murf/Documents/workspace/node_code/node_modules/zombie/node_modules/html5/lib/html5/tokenizer.js:62

Has anyone found a similar issue? If so, is there a way to go around it? Or maybe is there is another node module that does similar work? Any idea is greatly appreciated.

Thanks


Source: (StackOverflow)

Can I make Behat/ZombieJS/Mink simulate a click on a "non-link" element, to fire JS listeners?

I am using Behat for testing, with the ZombieJS driver, and everything is working very well so far, but there is one thing that bothers me, I can't seem to figure out how to get Behat to simulate a click on a non-link element. I guess this comes from Mink being a "cross-browser" driver, and it doesn't really make sense to click on non-link elements. For my use case though, I need it, because there are several elements on the page that have javascript event listeners attached to them, and I want to test these functionalities.

I tried using

Then I follow "div.sa"

But it fails with the expected error:

01. Link with id|title|alt|text "div.sa" not found.

Since it's not a link element. There is a similar step in Behat:

I press "button.class"

But this one is only for buttons.

Is there a way I could get Behat click on elements that are not tags?


Source: (StackOverflow)

Windows 8 : `node-gyp rebuild` Exit status 1 installing contextify as dependency of zombie

I'm trying to install zombie js, and get this error:

> contextify@0.1.8 install
C:\Users\User\Documents\ArbeitPhilipp\clieman\billing\node_modules\zombie\node_modules\jsdom\node_modules\contextify
> node-gyp rebuild

Das System kann den angegebenen Pfad nicht finden.

C:\Users\User\Documents\ArbeitPhilipp\clieman\billing\node_modules\zombie\node_modules\jsdom\node_modules\contextify>node "C:\Program Files (x86)\nodejs\nod
e_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild
gyp ERR! configure error
gyp ERR! stack Error: spawn ENOENT
gyp ERR! stack     at errnoException (child_process.js:980:11)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:771:34)
gyp ERR! System Windows_NT 6.2.9200
gyp ERR! command "node" "C:\\Program Files (x86)\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd
C:\Users\User\Documents\ArbeitPhilipp\clieman\billing\node_modules\zombie\node_modules\jsdom\node_modules\contextify
gyp ERR! node -v v0.10.24
gyp ERR! node-gyp -v v0.12.2
gyp ERR! not ok

I work on Windows 8 (64x)

Node: v0.10.24 (32)

npm: 1.3.21

Python: 2.7 (32)

Way to Python is in PATH (C:\Python27\python.exe;) PYTHONPATH : C:\Python27\ PYTHON : C:\Python27\python.exe

npm install --verbose contextify 2>&1 | grep gyp

gives as output:

C:\Users\User\Documents\ArbeitPhilipp\clieman\billing\node_modules\contextify>node    "C:\Program Files (x86)\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\n
ode_modules\node-gyp\bin\node-gyp.js" rebuild
gyp npm verb unsafe-perm in lifecycle true
npm ERR! contextify@0.1.8 install: `node-gyp rebuild`
npm ERR!     node-gyp rebuild

I've already read all issues to this topic, but no found desicion has helped me.

I would appreciate any help very much!


Source: (StackOverflow)

Prevent zombie.js from loading only external resources

I am using zombie.js to load a page from a local express server during a test. Unfortunately, there is a script element which calls out to Google Analytics. I would like to block this external script (gracefully) without preventing other (local) scripts from loading, if possible.

I know that { runScripts : false } is available with calls to browser.visit(). However, that refuses to load any and all scripts on the page, not just those living on other hosts. Is this possible?


Source: (StackOverflow)

zombie.js browser.fire not working with Backbone.Events

The browser.fire method does not seem to trigger event handlers attached through Backbone.Events. (it works fine for other cases such as clicking anchor tags/buttons)

See this gist for a test case on documentClouds site: https://gist.github.com/1256944

If the first thing you do when going to the url is click the 'Open' button you get an alert, but also the 'overlay' class is added to the body element - this is what im checking for.

You can see from the test that when using browser.fire 'click', that the prompt isn't shown, and the overlay class is not seen.

However, when triggering the click event using jQuery's click() method (via browser.evaluate), then the overlay class is seen...


Source: (StackOverflow)