Back to Resources

Blog

Posted February 28, 2017

New Relic Synthetics Monitoring Using Selenium

quote

What is New Relic Synthetics Monitoring? It allows us to simulate user behavior on development, staging, and production websites using Selenium, and 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 (a.k.a. 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 website1. 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:

  • Ping monitors check that your site is accessible.

  • Simple Browser monitors send a virtual browser to your site to ensure it’s working for real end-users.

  • Scripted Browsers navigate your website and assure particular resources are present using Selenium scripting

  • 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, navigating to a particular link, and wait for a specific page element to load and add an assertion. For a detailed guide to all available functions, see this Synthetics Scripted Browser reference. Let’s me show you how to configure a scripted monitor.

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

Select the locations from which you want your monitor to run (select Washington, DC, 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 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.

Greg Sypolt (@gregsypolt) is a Senior Engineer at Gannett – USA Today Network and co-founder of Quality Element. He has spent most of his career working as a developer in test— concentrating on automated testing for web browsers, APIs, mobile, and more. He is focused on the research, creation, and deployment of automated test strategies, testing frameworks, tools, and continuous integration. He’s passionate about #TestAutomation #TestCoverage #ContinuousIntegration #DevOps

Published:
Feb 28, 2017
Share this post
Copy Share Link
© 2023 Sauce Labs Inc., all rights reserved. SAUCE and SAUCE LABS are registered trademarks owned by Sauce Labs Inc. in the United States, EU, and may be registered in other jurisdictions.