Skip to main content

Getting Started With Selenium Automation Testing Using LambdaTest


LambdaTest Selenium Automation Grid enables you to perform end-to-end automation tests on a secure, reliable, and scalable Selenium infrastructure. You can perform automated cross browser testing with Selenium scripts on 2000+ browsers and operating systems environments, giving you higher test coverage and at significantly less built times. LambdaTest will help you evaluate how well your web application renders when accessed through a variety of different browsers. You can perform automated cross-browser testing of your locally hosted web pages using LambdaTest Tunnel. You could also run a single test across multiple browser/OS configurations simultaneously. This post will help you to quickly get started with running your automation test scripts on LambdaTest Selenium automation grid.

Here are all the languages and frameworks supported by LambdaTest online Selenium Grid.

Tesbo


Our Selenium grid also supports hybrid frameworks like Tesbo.

Tesbo is a hybrid framework for test automation that works on a keyword-driven approach. It allows you to write automation scripts in plain English like you’d do with a BDD framework. Built on top of Selenium, Tesbo helps you to perform cross browser testing over a Selenium Grid in parallel.

Check our support document to run your first Tesbo script over LambdaTest Selenium Grid.

Selenium Version Requirement#


LambdaTest recommends you to always use the latest version of the Selenium WebDriver for your particular scripting language.

Default Selenium Version#


LambdaTest Capabilities Generator will by default make use of latest compatible Selenium version based on the selections of browser/OS configurations. However, you are also allowed to test across other Selenium versions, in case if you want to run your automation script through a specific, legacy Selenium version. Below is the representation of the default Selenium versions used depending upon your browser selection.

BROWSER NAMEDEFAULT SELENIUM VERSION
Microsoft Edge2.52.0
ChromeLatest Chromedriver
FirefoxDev: 3.4.0, Beta: 3.4.0, 53+: 3.4.0, 39+: 2.53.1
Safari11.0: 3.4.0, <11.0: 2.48.0
Internet Explorer2.53.1

Note: 'selenium_version' is the desire capability responsible for selecting a Selenium version at LambdaTest. For instance,

selenium_version' = '3.13.0'

Product Access#


To run your Selenium tests on the LambdaTest requires a username and an access key. You can always get your username and access key from the Desired Capabilities Generator, as shown in the below image:

Image

Running Automation Tests From Local Machine#


If you want to run the automation tests on your local machine, with the help of LambdaTest's cloud-based online Selenium grid, you can choose the option Get Started.

Image

You can select the language of your choice to get started. For demo purpose, we will show you how to get started with each language.

1. Java#


If you choose Java as your preferred language to get started, you will see a window like below, where you can configure your test script and environment based on your choice.

Image

So to run your Java test on local machine:

  • Verify your test script: To help you get started, we have already covered a test scenario which: - Open the LambdaTest Sample ToDo app - Check the first item in the list - Check the second item in the list - Add a new item to the list with custom text
    @Test(enabled = true)    public void testScript() throws Exception {        try {            driver.get("https://lambdatest.github.io/sample-todo-app/");            driver.findElement(By.name("li1")).click();            driver.findElement(By.name("li2")).click();            driver.findElement(By.id("sampletodotext")).clear();            driver.findElement(By.id("sampletodotext")).sendKeys("Yey, Let's add it to list");            driver.findElement(By.id("addbutton")).click();            driver.quit();        } catch (Exception e) {            System.out.println(e.getMessage());        }    }
  • Select OS: Next you need to generate the desired capabilties. Select the desired operating system from the given list, on which you want to run your tests.

    Image
  • Select Resolution: Select the desired resolution from the given list, on which you want to run your tests.

    Image
  • Select Browser: Select the desired browser from the given list, on which you want to run your tests.

    Image
  • Select Browser Version: Select the desired version of the browser from the given list, on which you want to run your tests.

Image
  • Save the code: Once the desired capabilities are set, copy the code from the editor and save them in your local Java project. Below is the complete code of the selected desired capabilities, as shown in the image.
    //This is maven project        package lambdatest; // import org.testng.annotations.Test;    import java.net.MalformedURLException;    import java.net.URL;    import org.openqa.selenium.By;    import org.openqa.selenium.remote.DesiredCapabilities;    import org.openqa.selenium.remote.RemoteWebDriver;    import org.testng.annotations.BeforeTest;        public class Lambdatest {            public RemoteWebDriver driver = null;        String username = "rishabhps";        String accessKey = "euSJFdOOh4ItQlkv7ihsOne0E03OrbGIe1uux1pVLcZHP7NNof";            @BeforeTest        public void setUp() throws Exception {            DesiredCapabilities capabilities = new DesiredCapabilities();            capabilities.setCapability("platform", "Windows 10");            capabilities.setCapability("browserName", "Chrome");            capabilities.setCapability("version", "88.0"); // If this cap isn't specified, it will just get the any available one            capabilities.setCapability("resolution", "1024x768");            capabilities.setCapability("build", "First Test");            capabilities.setCapability("name", "Sample Test");            capabilities.setCapability("network", true); // To enable network logs            capabilities.setCapability("visual", true); // To enable step by step screenshot            capabilities.setCapability("video", true); // To enable video recording            capabilities.setCapability("console", true); // To capture console logs                try {                driver = new RemoteWebDriver(new URL("https://" + username + ":" + accessKey + "@stage-hub.lambdatest.com/wd/hub"), capabilities);            } catch (MalformedURLException e) {                System.out.println("Invalid grid URL");            }        }            @Test(enabled = true)        public void testScript() throws Exception {            try {                driver.get("https://lambdatest.github.io/sample-todo-app/");                driver.findElement(By.name("li1")).click();                driver.findElement(By.name("li2")).click();                driver.findElement(By.id("sampletodotext")).clear();                driver.findElement(By.id("sampletodotext")).sendKeys("Yey, Let's add it to list");                driver.findElement(By.id("addbutton")).click();                driver.quit();            } catch (Exception e) {                System.out.println(e.getMessage());            }        }    } 
  • You need to press the Run your test at the bottom to go on to the next step.
Image
  • Select the Local OS: Now the next step is to select the local machine OS on which you are expecting the tests to run.

    Image
  • Copy the pom.xml code: Copy the code of the pom.xml file and paste it in your local project.

    Image
  • Install the necessary plugins and packages: You would also need latest Selenium client and it’s WebDriver Bindings. Selenium can be downloaded from here. You should always run latest version of Selenium Client and WebDriver on LambdaTest Selenium cloud grid to avoid any errors.

  • Run your test locally: Now go to the directory where the file is saved and open the command terminal. It will be showing something like this:

    cd /path/to/the/test/directory

    Then you need to run the test from maven via surefire plugin, using the below command:

    mvn test

That's all. This will run your tests and you can see the output in your console.

Note: If you decide at anytime that you don't want to run your test locally, or want to try out the cloud-based workspace to execute the test, just click on the "Run in Gitpod" option available on your screen.

Image

2. Node JS#


Similarly, if you choose Node JS as your preferred language to get started, the steps will remain the same as above Java language, except the internal code and syntax details. You will see a window like below to configure your test script and environment based on your choice.

Image

So to run your Node JS test on the local machine:

  • Verify your test script: To help you get started, we have already covered a test scenario which: - Go to www.google.com - Type "LambdaTest" in the google search box - Compare the title of the first search result with "LambdaTest - Google Search" - Assert the title value

    // navigate to a url, search for a text and get title of pagedriver.get('https://www.google.com/ncr').then(function() {  driver.findElement(webdriver.By.name('q')).sendKeys('LambdaTest').then(function() {    driver.getTitle().then(function(title) {      setTimeout(function() {        console.log(title);        driver.quit();      }, 5000);    });  });
  • Select OS: Next you need to generate the desired capabilties. Select the desired operating system from the given list, on which you want to run your tests.

    Image
  • Select Resolution: Select the desired resolution from the given list, on which you want to run your tests.

    Image
  • Select Browser: Select the desired browser from the given list, on which you want to run your tests.

    Image
  • Select Browser Version: Select the desired version of the browser from the given list, on which you want to run your tests.

    Image
  • Save the code: Once the desired capabilities are set, copy the code from the editor and save them in your local Node JS project. Below is the complete code of the selected desired capabilities, as shown in the image.

const webdriver = require('selenium-webdriver'); // username: Username can be found at automation dashboardconst USERNAME = 'rishabhps'; // Accesskey:  Accesskey can be generated from automation dashboard or profile sectionconst KEY = 'euSJFdOOh4ItQlkv7ihsOne0E03OrbGIe1uux1pVLcZHP7NNof'; // gridUrl: gridUrl can be found at automation dashboardconst GRID_HOST = 'stage-hub.lambdatest.com/wd/hub'; function searchTextOnGoogle() {    // Setup Input capabilities    const capabilities = {        platform: 'Windows 10',        browserName: 'Chrome',        version: '88.0',        resolution: '1024x768',        network: true,        visual: true,        console: true,        video: true,        name: 'Test 1', // name of the test        build: 'NodeJS build' // name of the build    }     // URL: https://{username}:{accessKey}@hub.lambdatest.com/wd/hub    const gridUrl = 'https://' + USERNAME + ':' + KEY + '@' + GRID_HOST;     // setup and build selenium driver object    const driver = new webdriver.Builder()        .usingServer(gridUrl)        .withCapabilities(capabilities)        .build();     // navigate to a url, search for a text and get title of page    driver.get('https://www.google.com/ncr').then(function() {        driver.findElement(webdriver.By.name('q')).sendKeys('LambdaTest').then(function() {            driver.getTitle().then(function(title) {                setTimeout(function() {                    console.log(title);                    driver.quit();                }, 5000);            });        });    });}
searchTextOnGoogle();   
  • You need to press the Run your test at the bottom to go on to the next step.

    Image
  • Select the Local OS: Now the next step is to select the local machine OS on which you are expecting the tests to run.

    Image
  • Install the necessary plugins and packages: Now go to the directory where the file is saved and open the command terminal. It will be showing something like this:

    cd /path/to/the/test/directory

    You would also need the latest Selenium client and its WebDriver Bindings. Selenium can be downloaded using the code given below. You should always run the latest version of Selenium Client and WebDriver on LambdaTest Selenium cloud grid to avoid any errors.

    npm i selenium-webdriver

  • Run your test locally: Then you need to run the test file, using the below command:

    node lambdatest.js

That's all. This will run your tests and you can see the output in your console.

Note: If you decide at anytime that you don't want to run your test locally, or want to try out the cloud-based workspace to execute the test, just click on the "Run in Gitpod" option available on your screen.

Image

3. Python#


Similarly, if you choose Python as your preferred language to get started, the steps will remain the same as above Java language, except the internal code and syntax details. You will see a window like below to configure your test script and environment based on your choice.

Image

So to run your Python test on the local machine:

  • Verify your test script: To help you get started, we have already covered a test scenario which:
  • Open the LambdaTest Sample ToDo app

  • Check the first item in the list

  • Check the second item in the list

  • Add a new item to the list with custom text

     def test_unit_user_should_able_to_add_item(self): # try: driver = self.driver
     # Url driver.get("https://lambdatest.github.io/sample-todo-app/")
     # Click on check box check_box_one = driver.find_element_by_name("li1") check_box_one.click()
     # Click on check box check_box_two = driver.find_element_by_name("li2") check_box_two.click()
     # Enter item in textfield textfield = driver.find_element_by_id("sampletodotext") textfield.send_keys("Yey, Let's add it to list")
     # Click on add button add_button = driver.find_element_by_id("addbutton") add_button.click()
     # Verified added item added_item = driver.find_element_by_xpath("//span[@class='done-false']").text print (added_item)
  • Select OS: Next you need to generate the desired capabilties. Select the desired operating system from the given list, on which you want to run your tests.

    Image
  • Select Resolution: Select the desired resolution from the given list, on which you want to run your tests.

    Image
  • Select Browser: Select the desired browser from the given list, on which you want to run your tests.

    Image
  • Select Browser Version: Select the desired version of the browser from the given list, on which you want to run your tests.

    Image
  • Save the code: Once the desired capabilities are set, copy the code from the editor and save them in your local Python project. Below is the complete code of the selected desired capabilities, as shown in the image.
  import unittest  import sys  from selenium import webdriver
username = "rishabhps" # Replace the usernameaccess_key = "euSJFdOOh4ItQlkv7ihsOne0E03OrbGIe1uux1pVLcZHP7NNof" # Replace the access key
class FirstSampleTest(unittest.TestCase):    # Generate capabilites from here: https://www.lambdatest.com/capabilities-generator/    # setUp runs before each test case and     def setUp(self):        desired_caps = {            "build": 'PyunitTest sample build', # Change your build name here            "name": 'Py-unittest', # Change your test name here            "platform": 'Windows 10', # Change your OS version here            "browserName": 'Chrome', # Change your browser here            "version": '88.0', # Change your browser version here            "resolution": '1024x768', # Change your resolution here            "console": 'true', # Enable or disable console logs            "network":'true'   # Enable or disable network logs        }        self.driver = webdriver.Remote(            command_executor="https://{}:{}@stage-hub.lambdatest.com/wd/hub".format(username, access_key),            desired_capabilities= desired_caps)

# tearDown runs after each test case    def tearDown(self):        self.driver.quit()
    # """ You can write the test cases here """    def test_unit_user_should_able_to_add_item(self):        # try:        driver = self.driver
        # Url        driver.get("https://lambdatest.github.io/sample-todo-app/")
        # Click on check box        check_box_one = driver.find_element_by_name("li1")        check_box_one.click()
        # Click on check box        check_box_two = driver.find_element_by_name("li2")        check_box_two.click()
        # Enter item in textfield        textfield = driver.find_element_by_id("sampletodotext")        textfield.send_keys("Yey, Let's add it to list")
        # Click on add button        add_button = driver.find_element_by_id("addbutton")        add_button.click()
        # Verified added item        added_item = driver.find_element_by_xpath("//span[@class='done-false']").text        print (added_item)
    if __name__ == "__main__":    unittest.main()
  • You need to press the Run your test at the bottom to go on to the next step.

    Image
  • Select the Local OS: Now the next step is to select the local machine OS on which you are expecting the tests to run.

    Image
  • Install the necessary plugins and packages: Now go to the directory where the file is saved and open the command terminal. It will be showing something like this:

    cd /path/to/the/test/directory

    You would also need the latest Selenium client and its WebDriver Bindings. Selenium can be downloaded using the code given below. You should always run the latest version of Selenium Client and WebDriver on LambdaTest Selenium cloud grid to avoid any errors.

    pip install pytest && pip install selenium>2.5

  • Run your test locally: Then you need to run the test file, using the below command:

    python lambdatest.py

That's all. This will run your tests and you can see the output in your console.

Note: If you decide at anytime that you don't want to run your test locally, or want to try out the cloud-based workspace to execute the test, just click on the "Run in Gitpod" option available on your screen.

Image

4. Ruby#


Similarly, if you choose Ruby as your preferred language to get started, the steps will remain the same as above Java language, except the internal code and syntax details. You will see a window like below to configure your test script and environment based on your choice.

Image

So to run your Ruby test on the local machine:

  • Verify your test script: To help you get started, we have already covered a test scenario which: - Open the LambdaTest Sample ToDo app - Check the first item in the list - Check the second item in the list - Add a new item to the list with custom text

    driver.navigate.to "https://lambdatest.github.io/sample-todo-app/"driver.find_element(:name, 'li1')driver.find_element(:name, 'li2')driver.find_element(:id, 'sampletodotext').send_keys("Yey, Let's add it to list")driver.find_element(:id, 'addbutton').clickenteredText = driver.find_element(:xpath, '/html/body/div/div/div/ul/li[6]/span').textstatus = true if enteredText == "Yey, Let's add it to list"
  • Select OS: Next you need to generate the desired capabilties. Select the desired operating system from the given list, on which you want to run your tests.

    Image
  • Select Resolution: Select the desired resolution from the given list, on which you want to run your tests.

    Image
  • Select Browser: Select the desired browser from the given list, on which you want to run your tests.

    Image
  • Select Browser Version: Select the desired version of the browser from the given list, on which you want to run your tests.
Image
  • Save the code: Once the desired capabilities are set, copy the code from the editor and save them in your local Ruby project. Below is the complete code of the selected desired capabilities, as shown in the image.
require 'rubygems'require 'selenium-webdriver'# Input capabilities
USERNAME = 'rishabhps'ACCESS_KEY = 'euSJFdOOh4ItQlkv7ihsOne0E03OrbGIe1uux1pVLcZHP7NNof'caps = Selenium::WebDriver::Remote::Capabilities.newcaps[:browserName] = 'Chrome'caps[:platform] = 'Windows 10'caps[:version] = '88.0'caps[:resolution] = '1024x768'caps[:name] = 'LT sample Test' # test namecaps[:build] = 'LT sample build' # CI/CD job or build name
driver = Selenium::WebDriver.for(:remote,:url => "https://#{USERNAME}:#{ACCESS_KEY}@stage-hub.lambdatest.com/wd/hub",:desired_capabilities => caps)
driver.navigate.to "https://lambdatest.github.io/sample-todo-app/"driver.find_element(:name, 'li1')driver.find_element(:name, 'li2')driver.find_element(:id, 'sampletodotext').send_keys("Yey, Let's add it to list")driver.find_element(:id, 'addbutton').clickenteredText = driver.find_element(:xpath, '/html/body/div/div/div/ul/li[6]/span').textstatus = true if enteredText == "Yey, Let's add it to list"driver.quit
  • You need to press the Run your test at the bottom to go on to the next step.
Image
  • Select the Local OS: Now the next step is to select the local machine OS on which you are expecting the tests to run.
Image
  • Install the necessary plugins and packages: Now go to the directory where the file is saved and open the command terminal. It will be showing something like this:

    cd /path/to/the/test/directory

    You would also need the latest Selenium client and its WebDriver Bindings. Selenium can be downloaded using the code given below. You should always run the latest version of Selenium Client and WebDriver on LambdaTest Selenium cloud grid to avoid any errors.

    gem install selenium-webdriver && gem install ffi

  • Run your test locally: Then you need to run the test file, using the below command:

    ruby lambdatest.rb

That's all. This will run your tests, and you can see the output in your console.

Last updated on