Skip to main content

A fully-automated testing rig #5

An article from ComputerMinds - Building with Drupal in the UK since 2005
22nd Jul 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 5: Fun with viewports, and THEN some

As I described previously, we nicely externalised our list of viewport sizes, making it really easy to set our viewports for mobile, tablet and desktop tests. Our content appearance tests put this to good use, taking screenshots of the content at mobile, tablet and desktop resolutions. The problem we very quickly ran into was that we frequently ended up with empty screenshots, or sometimes no screenshot at all. This is where the asynchronous fun began.

The official walkthrough for CasperJS' "step stack" gives a very brief introduction to the idea that navigation steps might not be atomic. What you don't necessarily realise though (I didn't!) is that things aren't necessarily atomic when it comes to browsing with PhantomJS, either. So when we first had blank screenshots returned, we went through the rookie mistake of just adding a casper.wait 500 between the resolution change and the capture. This, though, is not reliable.

The proper solution is based on the idea that a viewport change is somewhat like a navigation step; the page is redrawn, though it doesn't necessarily (for us) need to reload all the content. This means that CasperJS' casper.then -> … construct works well for making sure that all the elements are actually drawn in your page before you take that screenshot.

One caveat remains, however. Things like Google Maps can spend quite some time loading their content, so for such special cases a casper.wait 2500 is necessary to ensure everything is displayed correctly. The rest of the time, casper.then -> … seems to work really nicely for ensuring the page is loaded.

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.