Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

New Relic Synthetics Monitoring Using Selenium

DZone's Guide to

New Relic Synthetics Monitoring Using Selenium

It allows us to simulate user behavior on development, staging, and production websites and to monitor web application performance.

· Performance Zone
Free Resource

Transform incident management with machine learning and analytics to help you maintain optimal performance and availability while keeping pace with the growing demands of digital business with this eBook, brought to you in partnership with BMC.

What is New Relic synthetics monitoring? It allows us to simulate user behavior on development, staging, and production websites using Selenium, as well as allows us to monitor web application performance. New Relic synthetics monitoring collects various data points from load times, load size, failures, https status codes, downtimes, and more when running Selenium on your web application. The data gives more insight into how your web application is performing by testing from various locations around the world and repeating the test every minute or x minutes. The goal of synthetics monitoring is to catch problems before your customers do.

The Ins and Outs of Synthetics Monitoring

Continuously monitoring the performance of web applications helps ensure that web services are in place and working correctly and error-free by running automated tests on a set schedule. The monitors are virtual Chrome browsers executing Selenium tests once a minute in Washington, D.C., or every 15 minutes from Portland, Oregon. You have control over how frequently and from what locations your Selenium tests will be executed. With every execution, the monitor is recording each check in detail and collecting performance data on your web application for each selected location. It captures aggregate numbers, including an overview, results, detailed statistics for each page resource, and downtime incidents (AKA violations). Let's take a closer look at some of the monitoring dashboard sections...

The Synthetics Overview page gives you enough metrics to immediately realize how your website is performing. You can look up trends for load time, availability (uptime), slowest results, and failures. You can jump straight into the slowest results and failures for a deeper analysis.

The Synthetics Results page allows you to view individual monitor results. The default page setting sorts the list of identified slowest network timing (page load) for all geographic locations being monitored. The network timing graph below gives us a snapshot of how a page was performing and trending over a period (time picker filter — last 3 days).

The Synthetics Resources page allows us to understand the load time impact of each resource on your website. We can review and investigate the load time of resources such as CSS, Javascript, images, HTML, and more. You can look into a specific resource by drilling into detailed metrics collected at run-time to pinpoint the performance issue. This page also collects performance information for time spent by third-party resources, and HTTP response codes for each resource.

Use the Synthetics Failures page to locate and troubleshoot downtime incidents or other errors. It provides a list of violation incidents that occurred when executing monitoring type.

The central focus of this article is Scripted Browser Synthetics, but it is important to know there are four types of Synthetics monitors available to you:

  1. Ping monitors check that your site is accessible.
  2. Simple browser monitors send a virtual browser to your site to ensure it’s working for real end-users.
  3. Scripted browsers navigate your website and assure particular resources are present using Selenium scripting.
  4. API monitors for your API endpoints to ensure your app server works as well as your website.

Configure and Develop a Selenium Scripted Browser Test

Using scripted browsers, you can build complex monitoring workflows using the Selenium JavaScript Webdriver bindings. For instance, log into the application, navigate to a particular link, and wait for a specific page element to load and add an assertion. Let me show you how to configure a scripted monitor.

It starts by selecting monitoring type (i.e., Scripted Browser) and specifying a monitor name (i.e., Sitename.com Scripted Browser):

Select the locations from which you want your monitor to run (select Washington, D,C,, USA and Portland, OR, USA):

Choose a frequency to determine how often each location will run your Selenium monitor (select 5 minutes):

Set a notification method to alert your team when performance violations occur:


Now you're ready to write your Selenium script:

var assert = require('chai').assert;

// Script-wide timeout for all wait and waitAndFind functions (in ms)
var DEFAULT_ELEMENT_TIMEOUT = 190000; //3 mins
var DEFAULT_PAGELOAD_TIMEOUT = 240000; //4 mins
var navLinks = ["css-locator-1", "css-locator-2"];

//sets element load timeout to 3 mins
$browser.manage().timeouts().implicitlyWait(DEFAULT_ELEMENT_TIMEOUT);
//sets page load timoeout to 4 mins
$browser.manage().timeouts().pageLoadTimeout(DEFAULT_PAGELOAD_TIMEOUT);

//Test all the main Nav page performances
$browser.get("http://www.sitename.com").then(function() {
 return $browser.findElement($driver.By.className("site-theme-example"));
}).then(function() {
 //Verifies the nav list has loaded
 return $browser.findElement($driver.By.className("site-nav-list-example"));
}).then(function() {
 //loops through the navLinks array
 navLinks.forEach(function(val, i, arr) {
  //finds and navigates to each navLink page
  return $browser.findElement($driver.By.className(navLinks[i])).click().then(function() {
   //verifies that the nav list loaded before moving on
   return $browser.findElement($driver.By.className("site-nav-list-example")).then(function() {
    //verifies that the page logo footer at bottom of page has loaded
    return $browser.findElement($driver.By.className("site-footer-logo"));
   })
  })
 })
});

Conclusion

We want our web application to operate error-free all the time, and we want users to continue returning. New Relic Synthetics monitoring allows us to monitor our website performance proactively in real time, and receive instant alerts when things go wrong. Then, we can make things right by troubleshooting the detailed data collected, logs, and the captured screenshot when a failure has been encountered on the site to determine how to fix the issue.

Evolve your approach to Application Performance Monitoring by adopting five best practices that are outlined and explored in this e-book, brought to you in partnership with BMC.

Topics:
performance ,new relic ,selenium ,monitoring

Published at DZone with permission of Greg Sypolt, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}