Advertisement
Guest User

CasperJS new relic dashboard

a guest
Nov 4th, 2015
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. casper = require("casper").create({
  2.         verbose: true,
  3.         logLevel: 'debug',
  4.         viewportSize: {
  5.             width: 1920,
  6.             height: 1080
  7.         },
  8.         pageSettings: {
  9.             javascriptEnabled: true,
  10.             userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36'
  11.         }
  12. });
  13.  
  14. casper.start('https://login.newrelic.com/login', function () {
  15.  
  16.     this.capture(content_dir + 'others/newrelic_login-page.png', {  // works
  17.         top: 0,
  18.         left: 0,
  19.         width: casper.evaluate(function () {
  20.             return document.body.scrollWidth;
  21.         }),
  22.         height: casper.evaluate(function () {
  23.             return document.body.scrollHeight;
  24.         })
  25.     }, {
  26.         format: 'png',
  27.         quality: 100
  28.     });
  29.  
  30.     this.fill('form', {
  31.         'login[email]': '***',
  32.         'login[password]': '***'
  33.     }, false);
  34. });
  35.  
  36. casper.thenEvaluate(function () {
  37.     document.querySelector('input[value="Sign in"]').click();
  38. });
  39.  
  40. /**
  41.  * New relic dashboard
  42.  */
  43. casper.thenOpen('https://rpm.newrelic.com/accounts/123456/applications', function(){
  44.     var self = this;
  45.  
  46.     this.wait(8000, function () {
  47.         casper.evaluate(function () {
  48.             localStorage.setItem('kioskNoir', 'false');
  49.         });
  50.  
  51.         self.capture(content_dir + 'others/newrelic_dashboard.png', {
  52.             top: 0,
  53.             left: 0,
  54.             width: casper.evaluate(function () {
  55.                 return document.body.scrollWidth;
  56.             }),
  57.             height: casper.evaluate(function () {
  58.                 return document.body.scrollHeight;
  59.             })
  60.         }, {
  61.             format: 'png',
  62.             quality: 100
  63.         });
  64.     });
  65. });
  66.  
  67. /**
  68.  * New relic Dashboard Crakrevenue
  69.  */
  70. casper.thenOpen('https://insights.newrelic.com/accounts/123456/dashboards/12345?kiosk=true', function () {
  71.     casper.evaluate(function () {
  72.         localStorage.setItem('kioskNoir', 'false');
  73.     });
  74.     this.wait(8000, function () {
  75.  
  76.         this.capture(content_dir + 'others/newrelic_dashboard_product.png', {
  77.             top: 0,
  78.             left: 0,
  79.             width: casper.evaluate(function () {
  80.                 return document.body.scrollWidth;
  81.             }),
  82.             height: casper.evaluate(function () {
  83.                 return document.body.scrollHeight;
  84.             })
  85.         }, {
  86.             format: 'png',
  87.             quality: 100
  88.         });
  89.     });
  90. });
  91.  
  92. casper.on("resource.error", function(resourceError){
  93.     console.log('Unable to load resource (#' + resourceError.id + 'URL:' + resourceError.url + ')');
  94.     console.log('Error code: ' + resourceError.errorCode + '. Description: ' + resourceError.errorString);
  95. });
  96. //Start casperJS
  97. casper.run();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement