[-]
  
[-]
  
  
  
  
  
  
  
 
 
[-]
  
  
  
  
[-]
  
 [+]
  
[-]
Monitoring
  
 [+]
 [+]
 [+]
  
[-]
Monitoring guides
  
  
[-]
Templates
  
  
  
[-]
Cloud monitoring
 [+]
  
  
 [+]
Kubernetes
[-]
Network checks
 [-]
   
   
   
   
  [-]
    
   
   
   
   
   
   
   
   
   
   
  
  
  
[-]
 [+]
  
  
  
  
  
  
 [+]
 [+]
 [+]
 [+]
[-]
CounterMeasures
  
 [+]
 [+]
  
  
[-]
Panopta OnSight
 [+]
 [+]
[-]
SNMP
 [+]
  
[-]
Alerting
 [+]
 [+]
 [+]
 [+]
 [+]
[-]
Reporting
  
  
  
[-]
Maintenance
  
  
[-]
API
  
  
  
  
[-]
Users, Groups, and Authentication
 [+]
  
  
  
[-]
Billing and Payments
  
  
  
  
  
  
 
[-]
  
  
  
  
  
  
  
  
  
  
  
  
Updated on 8/1/2019
Online Help
Set up a JavaScript synthetic check environment
Direct link to topic in this publication:
This article describes how to set up an environment for JavaScript synthetic checks in Panopta.

On this page

Prerequisites

  1. Install Node.js and Node Package Manager (npm).
  2. Enter the following command to install the Selenium WebDriver package:
    Go
    npm install selenium-webdriver

  3. Install one or more browser drivers for the browser/s you wish to use for development and testing. The driver must be located somewhere in your system path so it can be executed by the WebDriver.
  4. Download the Panopta synthetics module and save it to your local directory.

Test template

You can use the following template to get started:

JavaScript
const {By, Key, until} = require('selenium-webdriver');
const {init_panopta_synthetics} = require('./panopta-synthetics');

(async function example() {
let driver = await init_panopta_synthetics('chrome');
try {

driver.ps_step('Opening initial page');

await driver.get('https://google.com');
var result = await driver.findElement(By.name('q'));

await result.sendKeys('webdriver', Key.RETURN);
driver.ps_pass_test()
} catch (err) {
driver.ps_fail_test(err);
} finally {
await driver.quit();

})();

With this template, Chrome will be used to run the tests. Other browsers can be selected (provided their prerequisites are installed) by changing the name of the browser you pass to init_panopta_synthetics(). You can also use no-browser for tests that do not require a browser to perform tests.

In addition to the normal Selenium WebDriver function, the following additional functions are available in the driver object:

Function
Description
ps_step(name)
Marks the beginning of a step in the test. The name of the step will be displayed in the final output as well as a description of the overall test failure if it fails at this step. This function also begins the timer for measuring the execution time of the test step.
ps_annotate(message)
Adds additional logging information to test step.
ps_pass_test()
Called to indicate that the test has successfully completed.
ps_fail_test(err)
Called to indicate that the test has failed. Takes an optional JavaScript exception object which, if provided, is used to build the description of why the test failed. 

When running a browser-based test, additional functions expose more detailed browser timing metrics for the most recent request:

Method Description
ps_get_dns_time()
Time needed to resolve the hostname of the request.
ps_get_connect_time()
Time needed to make the initial socket connection.
ps_get_connect_time_ssl()
Time needed to perform the SSL/TLS connection.
ps_get_request_time()
Total time to make the HTTP request.
ps_get_response_time() 
Total time needed to download the HTTP response.
ps_get_ttfb() 
Time from the initial request until the first byte of the response was returned.
ps_get_total_time()
Total time to process the most recent request.

Full test example

The following is an example JavaScript synthetic check code snippet. This simple test runs a Google query.

JavaScript
const {By, Key, until} = require('selenium-webdriver');
const {init_panopta_synthetics} = require('./panopta-synthetics');
(async function example() {
let driver = await init_panopta_synthetics('chrome');
try {
driver.ps_step('Opening initial page');
await driver.get('https://google.com');
var result = await driver.findElement(By.name('q'));
driver.ps_annotate('Running sample Google query');
await result.sendKeys('panopta', Key.RETURN);
driver.ps_pass_test()
} catch (err) {
driver.ps_fail_test(err);
} finally {
await driver.quit();
}
})();


Test execution

Tests can be run using node test.js --local. This will start the browser and execute the test, displaying information in the terminal about each step that is performed. Upon completion, a JSON block that the Panopta monitoring probe will interpret in production use, will be displayed. If you would like to turn this off, add --hide-results to the end of the command.

Additional node modules

The test scripts are run from Panopta's monitoring probes in a limited sandbox environment for security reasons. Additional modules can be used by your tests, but they need to be whitelisted in our environment in order to be imported. Please contact your account manager or email support@panopta.com to discuss any modules that your tests require.

Related documentation

  • Selenium WebDriver - The basic documentation for the JavaScript version of the Selenium web driver covers the basic usage and configuration support for different browsers.
  • Full Javascript API documentation - The most important components are:
    • WebDriver - the main object that represents the driver that Selenium is managing
    • WebElement - used for accessing information about specific DOM elements
    • By - mechanism for locating elements on the page via CSS, XPath, element name, id, etc.
  • This article describes various strategies on the best way write repeatable JavaScript tests.