Skip to main content

A fully-automated testing rig #7

An article from ComputerMinds - Building with Drupal in the UK since 2005
5th Aug 2014

Nathan Page

Developer
Hey, you seem to look at this article a lot! Why not Bookmark this article so you can find it easily in the future?

##Part 7: When this.mouse.click doesn't work

mouse.click and mouse.move are a really helpfuls function in CasperJS, but we have at times found that they just don't work. Mostly, that's been because the element isn't there to click on. Do make sure that it's actually there! Make sure you're using the right selector, too. Try a casper.capture() to see whether it's there, but be wary of timings to ensure that you get a capture for the moment that you want to be performing the mouse action.

If all else fails, and in one test script nothing at all would work, then just use jQuery. It's available natively in the site we're working on anyway, though you can import it if you need to.

Something like this might help get the job done:


casper.then-> 
   test.evaluate-> 
       jQuery("path:nth-child(2) span").mouseover() 

#####Dropdowns

It's worth noting that dropdowns, in general, don't work with this form of 'fake' mouse interaction. CasperJS' click action only really moves a pretend cursor inside a virtual browser, and can't actually provide a 'genuine' mouse click. The same applies to jQuery, though jQuery has ways of making most other interactions work.

We've been using custom dropdowns a lot in this project, for which mouse interaction doesn't work at all. The only way around most of this has been to fill and submit the form manually.

Hi, thanks for reading

ComputerMinds are the UK’s Drupal specialists with offices in Bristol and Coventry. We offer a range of Drupal services including Consultancy, Development, Training and Support. Whatever your Drupal problem, we can help.