Javascript Code Example

This javascript code example demonstrates a simple selenium test and video recording using Node.js. We also support other javascript frameworks like Mocha, Protractor.

The Gridlastic hub endpoint and the video url used in this code example is displayed after launching your Gridlastic selenium grid. See documention Selenium Grid Configuration Parameters where to find these credentials and replace with your own.

Get a free account and launch your Gridlastic selenium grid, then run this code locally and test your grid!


const {Builder, By, Key, until} = require('selenium-webdriver');

(async function example() {
  let driver = await new Builder()
  .usingServer('https://USERNAME:ACCESS_KEY@YOUR_HUB_SUBDOMAIN.gridlastic.com/wd/hub')
  .withCapabilities({
                      browserName: 'chrome',
                      browserVersion: 'latest',
                      platformName: 'linux',
                      'gridlastic:options': {
                         video: true
                      }
                    })
  .build();

driver.manage().window().maximize();

  try {
  driver.getSession().then(function(session) {
  console.log("Video: " + VIDEO_URL + session.getId());
  });

    await driver.get('https://www.gridlastic.com/?demo');
    driver.sleep(5000); // for demo purposes
  } finally {
    await driver.quit();
  }
})();


NOTE: Gridlastic auto scaling requires all 3 test environment parameters platform, browser and browser version to be specified in each request in order to launch test nodes to fulfill test demand. Video recording is optional. See test environments for capabilities options.
It is important to ensure that ".quit()" is always called for proper test execution and creation of video recordings of failed tests.