Skip to content

Instantly share code, notes, and snippets.

@pzel
Created June 30, 2011 11:10
Show Gist options
  • Save pzel/1056023 to your computer and use it in GitHub Desktop.
Save pzel/1056023 to your computer and use it in GitHub Desktop.
unable to fire event
zombie = require('zombie');
assert = require('assert');
vows = require('vows');
url = "http://localhost:4568/";
// Load the page from localhost
vows.describe('The tags page').addBatch({
'Presence' : {
topic : function() {
//The zombie callback is a function with three args:
// function(error, browser, status){...};
zombie.visit(url + "tags", this.callback);
},
'should be ok': function(e, b, s){
assert.equal(s, "200");
},
'should have the right title': function(e,b,s){
assert.equal(b.text("#header > h1"), "All tags");
}
},
'Adding a new tag': {
topic: function(){
zombie.visit(url+"tags", this.callback);
},
'after submitting tag name': {
topic : function(b) {
b.fill("tag[content]", "holograms").
pressButton("Add tag", this.callback);
},
'it should be successful' : function(b) {
assert.equal(b.response[0], "200");
},
'it should show the new tag' : function(b) {
assert.ok(b.querySelector(".info_for_tag"));
assert.match(b.text(".info_for_tag a"), /\s*holograms\s*/);
},
'after hovering on new tag' : {
topic : function(b) {
// This function does not work *error message below
b.fire("mouseOver", '.info_for_tag');
// This doesn't work either
// b.fire("click", '.info_for_tag a');
b.wait(this.callback);
},
'it should change class' : function(b){
console.log(b.response[2]);
assert.ok(b.querySelector(".unused_tag"));
}
}
}
}
}).export(module);
/* THE ERROR MESSAGE */
♢ The tags page
Presence
✓ should be ok
✓ should have the right title
Adding a new tag after submitting tag name
✓ it should be successful
✓ it should show the new tag
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Object .info_for_tag a has no method 'dispatchEvent'
at Browser.fire (/home/p/code/nejiro/node_modules/zombie/lib/zombie/browser.js:173:14)
at Object.<anonymous> (/home/p/code/nejiro/spec/js/ajax_test.js:42:23)
at run (/home/p/code/nejiro/node_modules/vows/lib/vows/suite.js:130:31)
at EventEmitter.<anonymous> (/home/p/code/nejiro/node_modules/vows/lib/vows/suite.js:203:40)
at EventEmitter.emit (events.js:81:20)
at /home/p/code/nejiro/node_modules/vows/lib/vows/context.js:32:52
at /home/p/code/nejiro/node_modules/vows/lib/vows/context.js:46:29
at Browser.<anonymous> (/home/p/code/nejiro/node_modules/zombie/lib/zombie/browser.js:148:18)
at Browser.<anonymous> (/home/p/code/nejiro/node_modules/zombie/lib/zombie/browser.js:9:60)
at Browser.emit (events.js:64:17)
@cjroebuck
Copy link

Hi, did you work around this error? I have the same error when trying to fire the click event on a DOM element, and dont know how to get it working...

@cjroebuck
Copy link

Just figured it out, you need to pass the actual DOM element to browser.fire, not a css selector string. So to fix your issue you would do:

var infoEl = b.querySelector('.info_for_tag');
b.fire("mouseOver", infoEl, this.callback);

@pzel
Copy link
Author

pzel commented Sep 28, 2011

Hi, thanks for pointing out the solution.
This code was one of many tentative attempts to select a nice js testing framework. I've since settled on cabypara-webkit. Are you actively using zombie in any real-life projects?

@cjroebuck
Copy link

Cool, how is capybara-webkit working out for you so far? Do you have the above test written in capybara-webkit that I can reference? I might have to take a look, as 've been persevering with zombie and it's taking a lot of time to work around it's limitations, also there's not much support when things go wrong unfortunately :(

@pzel
Copy link
Author

pzel commented Sep 29, 2011

It's very nice. There is much less slowness and fuss than with selenium, and you don't have to write tests in tedious js (like with zombie or phantom). Here is the capybara-webkit version of the above code, running on rspec.

@cjroebuck
Copy link

I'm writing my tests in coffeescript and using vows-bdd to run them, so it's not as tedious as js + vows. Is it possible to test a node.js app from capybara-webkit?

@pzel
Copy link
Author

pzel commented Sep 29, 2011

I think it should be, but you would probably have to write the tests themselves in ruby.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment