Node.js WD Example

Node.js wd is supported by Gridlastic, run your tests in the cloud at blazing speed on real browsers. We also support other javascript frameworks like WebdriverIO and Protractor AngularJS.

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!

var webdriver = require('wd');
var browser = webdriver.remote('https://USERNAME:ACCESS_KEY@HUB_SUBDOMAIN.gridlastic.com/wd/hub');
var desired = {
  browserName: 'chrome'
  , version: 'latest'
  , platform: 'WIN10'
  , platformName: 'windows'
  , video: 'True'
};
  
browser.init(desired, function(err, sessionID) {
console.log("Video: " + VIDEO_URL + sessionID);
  browser.get("https://www.google.com/ncr", function() {
    browser.title(function(err, title) {
      browser.elementByName('q', function(err, el) {
        el.sendKeys("webdriver", function() {
          browser.elementByName("btnG", function(err,el) {
            el.click(function() {
              browser.quit();
            })
          })
        })
      })
    })
  })
});

Note: starting from selenium version 3.9.1 you must also include "platformName": "windows" in the request when testing with firefox and IE.

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.