CAPABILITY GENERATOR

LambdaTest DocumentationReal Time Testing ● Automation Testing With Selenium And Jest

Automation Testing With Selenium And Jest


Developed by Facebook, Jest is a JavaScript testing library for React web-applications. With Jest, you can perform snapshot testing to help you comprehend the state of your react trees which are transforming over time. It provides an excellent combination of a test runner & an assertion library. You can make use of built-in code coverage reports for figuring out the areas the files that aren’t a part of your test code. There is also a built-in mocking library. Jest also works with Typescript.

LambdaTest now integrates with Jest to boost your go-to-market delivery. Perform automated cross browser testing with LambdaTest to ensure your development code renders seamlessly through an on-cloud Selenium Grid providing 2000+ real browsers running through machines. Perform automation testing in parallel using LambdaTest’s Selenium Grid to drastically trim down your test cycles.

Prerequisites


  1. Global Dependencies
    • Make sure to use the latest version of JavaScript.
    • A Git or GitHub repository
    • Download and install node.js and node package manager or npm.

      To install node.js with homebrew use the below command.

    • If you have npm already installed, you may want to upgrade it to latest version. Here the code you can run in your terminal to upgrade npm.

  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 Linux/Mac:
    • For Windows:

Setup For Running Jest Integration With Selenium Grid.


Check our GitHub repository for Jest and Selenium WebDriver Code Sample.

Step 1: Navigate to the cloned directory.

Step 2:Install dependencies using npm install.

Step 3:In you command prompt/ terminal, route the pointer to the folder test.

Running Tests Using Jest On LambdaTest Selenium Grid


Execute the below command to run a single test:

Sample Code:

Test Your Locally Hosted Jest Scripts With LambdaTest


To help you perform cross browser testing of your locally stored web pages, LambdaTest provides an SSH(Secure Shell) tunnel connection with the name Lambda Tunnel. With Lambda Tunnel, you can execute a test of your locally hosted Jest scripts on cloud to perform automated cross browser testing on 2000+ browsers offered by Selenium Grid on LambdaTest. So you make sure how well your changes look, even before your customers. Curious to know more about Lambda Tunnel?

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

Once, the tunnel is successfully set up. Set tunnel value to true in test capabilities.

Execute the below command for running your locally hosted test cases:

Sample code for local testing:

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”.

Fast track your automated cross browser testing process by executing your test cases using Jest on LambdaTest Selenium Grid. Happy testing!