CAPABILITY GENERATOR

LambdaTest DocumentationReal Time Testing ● Running Cucumber Scripts With TestNG And Selenium

Running Cucumber Scripts With TestNG And Selenium


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 Cucumber scripts with TestNG and Selenium for automating your web application over 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 Cucumber Java automation test scripts on LambdaTest Selenium cloud platform. In this post we would be exploring:

  • Prerequisites and Environment Setup.
  • Running your first Cucumber Java test.
  • Running your Cucumber scripts on locally hosted web application.

Prerequisites


Visit our GitHub repository for Cucumber and TestNG for finding all the relevant code samples.
  1. Global Dependencies
    • Make sure you have the latest Java installed in your system. For Windows, you can install it from their official website by clicking here.
    • For Linux, execute the following command in terminal.
    • For Mac, Java is installed by default on Mac OS X.
    • Install Maven from their official website. You could also use the below command for Homebrew.

  2. LambdaTest Authentication Credentials
  3. Be aware of your LambdaTest authentication credentials i.e. your LambdaTest username, access key and HubURL. You need to set them up as your environment variables. You can retrieve them from your LambdaTest automation dashboard by clicking on the key icon near the help button.

    • For Windows user:
    • set LT_USERNAME=”YOUR_USERNAME”
      set LT_ACCESS_KEY=”YOUR ACCESS KEY”

    • For macOS/Linux user:
    • export LT_USERNAME=”YOUR_USERNAME”
      export LT_ACCESS_KEY=”YOUR ACCESS KEY”

  4. Environment Setup
    • Ensure that the necessary packages are available by running the below command.
    • You may also want to run the command below to check for outdated dependencies. Please be sure to verify and review updates before editing your pom.xml file as they may not be compatible with your code.

Running Your First Cucumber Script For TestNG and Selenium


Here is the sample feature file for Cucumber.

Here is the TestRunner file to automate our feature file through Selenium using TestNG.

Below are the step definitions.

Open your cmd/terminal and route the pointer to Cucumber-TestNG-Sample.

Testing Locally Hosted or Privately Hosted Projects


You can test your locally hosted or privately hosted projects with LambdaTest Selenium grid cloud using Lambda Tunnel app. All you would have to do is set up an SSH tunnel using Lambda Tunnel app, and pass toggle tunnel = True via desired capabilities. Lambda Tunnel establishes a secure SSH protocol based tunnel that allows you in testing your locally hosted or privately hosted pages, even before they are made live.

Refer our LambdaTest Tunnel documentation for more information.

Here’s how you can establish Lambda Tunnel.

Download latest LambdaTest Tunnel binary file and extract it.

To run your Cucumber tests for locally hosted web applications you would need to set the Tunnel Capability flag to true

Important Note:

Some Safari & IE browsers, doesn’t support automatic resolution of the URL string “localhost”. Therefore if you test on URLs like “http://localhost/” or “http://localhost:8080” etc, you would get an error in these browsers. A possible solution is to use “localhost.lambdatest.com” or replace the string “localhost” with machine IP address. For example if you wanted to test “http://localhost/dashboard” or, and your machine IP is 192.168.2.6 you can instead test on “http://192.168.2.6/dashboard” or “http://localhost.lambdatest.com/dashboard”.