Skip to main content

Running Selenium WD Automation Scripts on LambdaTest Selenium Grid

LambdaTest Selenium Automation Grid is a cloud-based scalable Selenium testing platform which enables you to run your automation scripts on 2000+ different browsers and operating systems. You can now run your JavaScript Selenium automated test cases on a scalable Selenium infrastructure that is running real browsers and real operating systems.

This post will help you in getting started with configuring and running your JavaScript based automation test scripts on LambdaTest Selenium cloud platform using WD. This topic will help you to:

  • Run a sample Selenium WD test using JavaScript on LambdaTest Automation.
  • Comprehend and configure Selenium test suite with respect to your capabilities.
  • Select the specific browsers to run your test on.
  • Explore advanced features of LambdaTest.
  • Run your test cases in parallel to reduce build times.
  • Test your locally hosted pages.

Prerequisites For Running Selenium WD Automation Scripts#

All the code samples in this documentation can be found in the WD LambdaTest Repository on Image GitHub. You can either download or clone the repository to quickly run your tests.

Before getting started with Automated Scripts using Selenium WD automation on LambdaTest Automation, you need to:

  • The first step is to download and install node.js and node package manager or npm. You should be having nodejs v6 or newer. Click here to download.
  • Make sure to use the latest version of JavaScript.
  • Make sure you have WD installed in your system, you can install it using the below command through npm:

npm install wd

  • Download Selenium JavaScript bindings from the official Selenium website.
  • Once you download the JavaScript bindings, extract the ZIP file which you’ve downloaded. After extracting the file, you need to add Selenium Java bindings which is a JAR file and all the dependent libraries to your classpath.

Installing Selenium Dependencies For Node.js#

Next step is to install Selenium dependencies for Node.js using npm. Here’s the command to run:

npm i selenium-webdriver

  • Download LambdaTest tunnel binary file if you wish to test your locally hosted or privately hosted projects.

Follow our documentation on LambdaTest tunnel to know it all. OS specific instructions to download and setup tunnel binary can be found at the following links.

Download the binary file of:

Getting Started With Selenium WD & LambdaTest#

Running Selenium WD test scripts on LambdaTest Selenium Grid is as easy as changing a few lines of code. To start with, you would have to invoke Selenium remote webdriver instead of local browser webdriver. In addition, since we are using remote webdriver, we have to define which browser environment we want to run the test. We do that by passing browser environment details to LambdaTest Selenium Grid via desired capabilities class. You can use LambdaTest Capabilities Generator to select & pass those browser environment specifications.

Let’s check out a sample Selenium WD code running LambdaTest Selenium Grid. This is a simple Selenium WD automation script that test a sample to-do list app. The code marks two list items as done, add a list item and then finally give the total number of pending items as output.

You can also find this code at our GitHub repository for WD.

//single_test.jsmodule.exports = {  name: 'Google\'s Search Functionality',  run : function (browser) {    return browser      .get("")      .elementByName('q')      .sendKeys('lambdatest\n')      .sleep(5000)      .title()        .should.become('lambdatest - Google Search');  }};

Below is the export.config file where we will be declaring the desired capabilities.

//single.conf.jsuser= process.env.LT_USERNAME || "<your username>",key=  process.env.LT_ACCESS_KEY || "<your accessKey>", exports.config = {   seleniumHost: '',  seleniumPort: 80,   test: '../tests/single_test.js',   capabilities: [{    browserName: 'chrome',    platform: 'win10',    version: '67',    name: "single-test",    build: "WD Selenium Sample"  }]}

Now, let’s create lambdatest.js.

//lambdatest.jsvar chai = require("chai"),    chaiAsPromised = require("chai-as-promised"),    wd = require('wd'),    colors = require('colors'),    child_process = require('child_process') chai.use(chaiAsPromised);chai.should();chaiAsPromised.transferPromiseness = wd.transferPromiseness; wd.addPromiseChainMethod(  'onQuit', function(done) {    if(done) done();    return this;  }); function runOnlambdatest(caps, test, done){  console.log("Starting Test: " + + '\n');  var browser = wd.promiseChainRemote(config.seleniumHost, config.seleniumPort, username, accessKey);   // optional extra logging  browser.on('status', function(info) {    console.log(info.cyan);  });  browser.on('command', function(eventType, command, response) {    console.log(' > ' +, command, (response || '').grey);  });  browser.on('http', function(meth, path, data) {    console.log(' > ' + meth.yellow, path, (data || '').grey);  }); { return browser.quit(); }).onQuit(done).done();} var config_file = process.argv[2] || 'conf.js'var config = require(config_file).config;var test = require(config.test); var username = process.env.LT_USERNAME || config.user;var accessKey = process.env.LT_ACCESS_KEY || config.key; for(var i in config.capabilities){  var caps = config.capabilities[i];  if(caps["tunnel"]){    console.log("Connecting local");  }  else {    runOnlambdatest(caps, test);  }}

Now, finally create package.json file.

//package.json{  "name": "wd-lambdatest-sample",  "version": "0.1.0",  "readme": "WD Integration with [lambdatest](",  "description": "Selenium examples for WD and lambdatest Automate",  "repository": {    "type": "git",    "url": "git+"  },  "keywords": [    "wd",    "lambdatest",    "wd-lambdatest-sample",    "webdriver",    "selenium"  ],  "author": "lambdatest",  "bugs": {    "url": ""  },  "homepage": "",  "scripts": {    "test": "npm run single && npm run parallel",    "single": "node scripts/lambdatest.js ../conf/single.conf.js",    "parallel": "node scripts/lambdatest.js ../conf/parallel.conf.js"  },  "dependencies": {    "chai": "^3.5.0",    "chai-as-promised": "^5.2.0",    "colors": "^1.1.2",    "wd": "^1.11.1"  }}

The Selenium WebDriver test would open a URL, mark the first two items in the list as done, add an item in the list, and return the total number of pending item. Your results would be displayed on the test console (or command-line interface if you are using terminal/cmd) and on LambdaTest dashboard. LambdaTest Dashboard will help you view all your text logs, screenshots and video recording for your entire Selenium tests.

Execute The Tests Using Selenium WD Automation#

Running A Single Test#

You would need to execute the below command in your terminal/cmd.

//Running First Testnpm installnpm run single

Running Multiple Tests In Parallel#

Parallel testing is one of the most in-demand features of LambdaTest Selenium Grid. By parallel testing, you can run more than one test case, simultaneously. So you can execute a single test scenario across different browsers or could run different test scenarios across the same browser but with different browser versions. Wondering how many parallel test cases can you run? That depends entirely on the number of concurrent session under your opted plan.

Run the below command for parallel testing.

//Running Tests In Parallelnpm run parallel

Parallel Testing Sample Code#

//parallel.conf.jsuser= process.env.LT_USERNAME || "<your username>",key=  process.env.LT_ACCESS_KEY || "<your accessKey>",
exports.config = {
  seleniumHost: '',  seleniumPort: 80,
  test: '../tests/single_test.js',
  commonCapabilities: {    name: "parallel-test",    build: "wd-lambdatest-sample"  },
  capabilities: [{    browserName: 'chrome',    platform: 'win10',    version: '67',  },{    browserName: 'firefox',    platform: 'win10',    version: '60',  },{    browserName: 'safari',    platform: 'macos 10.13',    version: '11',  }]}// Code to support common capabilitiesexports.config.capabilities.forEach(function(caps){  for(var i in exports.config.commonCapabilities) caps[i] = caps[i] || exports.config.commonCapabilities[i];});


To prevent over-exploitation of the platform, we have added a capacity constraint on the number of tests that can be queued at our platform. Your maximum queue capacity will be dependent upon the number of concurrent sessions your LambdaTest account is eligible for. Below formula will help you calculate the maximum capacity for your queue.

Maximum Queuing Capacity: Maximum number of parallel tests that can be queued = n + 150

Here, n = number of concurrent sessions.

For example, if you have opted for pricing where you can avail up to 10 concurrent sessions. Then the maximum number of parallel test cases that can be queued will be equal to 10 + 150 i.e. 160 parallel test cases. Queuing allows you to manage your test pipeline in a hassle-free manner. LambdaTest would automatically schedule and execute test cases for you.

LambdaTest Queuing Policy

Here you can get more information about LambdaTest Queuing Policy.

Queuing Timeout: There is also a limit on how long a test case can stay in the queue. If your test case stays in the queue for more than 15 minutes, the test case would be timed out and would not be executed.

Last updated on