Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Using PhantomJS to QA your analytics implementation

1,318 views

Published on

Adobe Analytics implementation headless testing using PhantomJS

Published in: Technology

Using PhantomJS to QA your analytics implementation

  1. 1. PhantomJS and Analytics MeasureCamp London 19 Sep 2015
  2. 2. Spiders and robots Until a few years ago spiders and bots could only read the HTML. They could not execute Javascript.
  3. 3. Spiders and robots Until a few years ago spiders and bots could only read the HTML. They could not execute Javascript. Now they can:
  4. 4. Spiders and robots Until a few years ago spiders and bots could only read the HTML. They could not execute Javascript. Now they can: • Access the DOM
  5. 5. Spiders and robots Until a few years ago spiders and bots could only read the HTML. They could not execute Javascript. Now they can: • Access the DOM • Interpret Javascript
  6. 6. Spiders and robots Until a few years ago spiders and bots could only read the HTML. They could not execute Javascript. Now they can: • Access the DOM • Interpret Javascript • Fill login forms
  7. 7. Just like you and me
  8. 8. Headless testing Increasingly testing requires writing code • Test Driven Development • Extreme Programming An automated test goes through the pages, executes the relevant tests and produces a bug report
  9. 9. Introducing
  10. 10. Introducing A scriptable WebKit chrome-less browser
  11. 11. Simulate user behaviour and more PhantomJS can respond to different stages of the page load • Page initialised • Page load start • Page load finished • Page closed • Page not found
  12. 12. Simulate user behaviour and more PhantomJS can respond to HTTP requests • Resource requested • Resource received • Resource error • HTTP status text and codes
  13. 13. Simulate user behaviour and more PhantomJS can respond to alerts and messages • Javascript alert sent • Javascript console sent • Javascript prompt
  14. 14. Simulate user behaviour and more PhantomJS can also • Scan and manipulate the DOM • Catch Javascript errors in the page analysed
  15. 15. Simulate user behaviour and more PhantomJS can also • Scan and manipulate the DOM • Catch Javascript errors in the page analysed • It can do screenshots
  16. 16. With PhantomJS you can write a spider to audit your analytics implementation
  17. 17. Continuously
  18. 18. http://www.phantomjs.org PhantomJS 2 available!
  19. 19. // Set the start URL var page = require("webpage").create(); var url = "http://www.adobe.com"; //var url = "http://www.webtrends.com"; var links; page.viewPortSize={ width: 1280, height: 800 }; page.clipRect={ top:0, left:0, width:1280, height:800 } phantom.onError=function(){}; page.onError=function(){}; page.onLoadStarted=function(){}; page.onResourceReceived=function(responseData){}; Source code
  20. 20. page.onResourceRequested=function(requestData,networkRequest){ if(requestData.url.match(//b/ss//)) console.log(requestData.url);//Adobe Analytics if(requestData.url.match(/dcs.gif/)) console.log(requestData.url);//Webtrends }; page.onLoadFinished=function(status){ if(status=="success"){ var links = page.evaluate(function(){ var a=document.createElement("a"); return [].map.call(document.querySelectorAll("a[href]"), function(link){ a.href=link.getAttribute("href"); return a.href; }); }); console.log(links.join("n")); }else{ //log error }; //check next page }; Source code
  21. 21. page.open(url,function (status){ if(status=="success"){ }else{ //log error }; phantom.exit(); }); Source code
  22. 22. Alban Gérôme email: albangerome@yahoo.fr twitter: @albangerome All pictures from this deck taken by myself in Barcelona

×