Conditional scripting to handle when site is under maintenance

We have a site that is monitored with a New Relic “Scripted Browser” Synthetic.

The site occasionally enters “maintenance mode” for a short (unscheduled) window of time, typically late at night and/or on weekends. When you visit the site during those times, the entire site is replaced with a simple HTML maintenance page.

I would like to modify our script to detect the presence of this page, probably by searching for text in the page body like… “currently being updated” and short-circuit the script without triggering an alert. Note that we still need to be able to detect when the site is down or otherwise non-functional according to our normal script flow.

  1. maintenance mode (never alert)
  2. normal site - test scripted flow (alert if failure or site is down)

I can’t figure out how to do this. Any thoughts?

Hi @william.krick - I had the same issue and wrote a script which you can use as a template.

1 Like

I’m having trouble getting this to work because of the way that promises need to be chained.

Also, our maintenance page has the same URL as the real page, if it matters. We have to detect the maintenance page by searching the body text for a specific string.

EDIT. I managed to get it working using your example as a guide. Thank you.


Thanks for confirming you got this working :smiley:

Well… I got it working for a really simple example, but for my real script I’m still having trouble. I’ll keep you posted.

Oh ok! Sorry for misunderstanding - please do keep us up to date with your more complex script example. :slight_smile:

OK, I managed to sort out my maintenance page situation. The trick was to do the $browser.get() twice. Once to look for the maintenance text, and then again if it is not found. Here’s a working example…

var assert = require('assert');

var inMaintenanceMode = false;
// this is the string to search for to identify the maintenance page
var maintenanceText = ("Example Domain").toLowerCase();


  // search body for maintenance mode text 
  return $browser.findElement($driver.By.tagName("html")).getText().then(function(body){
    inMaintenanceMode = (body.toLowerCase().indexOf(maintenanceText) != -1);
  }).then(function() {
    // return early if site is in maintenance mode
    if (inMaintenanceMode) {
      console.log("site is in maintenance mode");
      return true;

    // If we got here, then site is not in maintenance mode. Run through normal script...

    // #### BEGIN NORMAL SCRIPT ####
    return $browser.get('').then(function(){
      // Check the H1 title matches "Example Domain"
      return $browser.findElement($driver.By.css('h1')).then(function(element){
        return element.getText().then(function(text){
          assert.equal('Example Domain', text, 'Page H1 title did not match');
      // Check that the external link matches ""
      return $browser.findElement($driver.By.css('div > p > a')).then(function(element){
        return element.getAttribute('href').then(function(link){
          assert.equal('', link, 'More information link did not match');
    // #### END NORMAL SCRIPT ####