Skip to content

Files

Latest commit

 

History

History

sdk

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Integrating SmartUI SDK with Selenium(JS) tests

Welcome to the world of simplified visual testing with the SmartUI SDK.

Integrating seamlessly into your existing Selenium testing suite, SmartUI SDK revolutionizes the way you approach visual regression testing. Our robust solution empowers you to effortlessly capture, compare, and analyze screenshots across a multitude of browsers and resolutions, ensuring comprehensive coverage and accuracy in your visual testing endeavors.

Pre-requisites for running tests through SmartUI SDK

  • Basic understanding of Command Line Interface and Selenium is required.
  • Login to LambdaTest SmartUI with your credentials.

The following steps will guide you in running your first Visual Regression test on LambdaTest platform using SmartUI Selenium SDK integration.

Create a SmartUI Project

The first step is to create a project with the application in which we will combine all your builds run on the project. To create a SmartUI Project, follow these steps:

  1. Go to Projects page
  2. Click on the new project button
  3. Select the platform as CLI or Web for executing your SDK tests.
  4. Add name of the project, approvers for the changes found, tags for any filter or easy navigation.
  5. Click on the Submit.

Steps to run your first test

Once you have created a SmartUI Project, you can generate screenshots by running automation scripts. Follow the below steps to successfully generate screenshots

Step 1: Create/Update your test

You can clone the sample repository to run LambdaTest automation tests with SmartUI and use the sdk.js file present in the sdk folder.

git clone https://github.com/LambdaTest/smartui-node-sample

Step 2: Install the Dependencies

Install required NPM modules for LambdaTest Smart UI Selenium SDK in your Frontend project.

npm i @lambdatest/smartui-cli @lambdatest/selenium-driver selenium-webdriver

To ensure seamless execution of ES6 modules within our repository, it is essential to configure the Node.js environment to recognize ES6 module syntax. This is accomplished by specifying the module type in your package.json file.

"type": "module"

Step 3: Configure your Project Token

Setup your project token show in the SmartUI app after, creating your project.

export PROJECT_TOKEN="123456#1234abcd-****-****-****-************"
set PROJECT_TOKEN="123456#1234abcd-****-****-****-************"
$Env:PROJECT_TOKEN="123456#1234abcd-****-****-****-************"

Step 4: Create and Configure SmartUI Config

You can now configure your project settings on using various available options to run your tests with the SmartUI integration. To generate the configuration file, please execute the following command:

smartui config:create smartui-web.json

Once, the configuration file will be created, you will be seeing the default configuration pre-filled in the configuration file:

{
  "web": {
    "browsers": [
      "chrome", 
      "firefox",
      "safari",
      "edge"
    ],
    "viewports": [
      [
        1920,
        1080
      ],
      [
        1366,
        768
      ],
      [
        360,
        640
      ]
    ],
    "waitForPageRender": 50000, 
    "waitForTimeout": 1000

  }
}

Optional Keys in SmartUI configuration

waitForPageRender - If one or more URLs in your script require a relatively higher amount of time to load, you may use the waitForPageRender key in the config file to make sure the screenshots are rendered correctly. Avoid using the same in case your websites render in less than 30 seconds as it might increase the execution time of your tests.

waitForTimeout - If you are using any async components, you can add wait time for the page to load the DOM of your components. This can help avoid false-positive results for your tests. You can add the wait time in milliseconds, which might increase the execution time of your tests. :::

Step 5: Adding SmartUI function to take screenshot

  • You can incorporate SmartUI into your custom Selenium automation test (any platform) script by adding the smartuiSnapshot function in the required segment of selenium script of which we would like to take the screenshot, as shown below:
import  { Builder, By, Key, until } from 'selenium-webdriver';
import { smartuiSnapshot } from '@lambdatest/selenium-driver';

(async function example() {
    let driver = await new Builder()
        .forBrowser('chrome')
        .build();

    try {
        await driver.get('<Required URL>'); //enter your desired URL here
        await smartuiSnapshot(driver, '<Screenshot_Name>');
        // Please specify your driver and the screenshot name in this function
        // driver - selenium driver instance (required)
        // Screenshot_Name - Name of the screenshot ; unique to each screenshot (required)
        await driver.get('https://www.example.com');
        await smartuiSnapshot(driver, '<Screenshot Name>');
    } finally {
        await driver.quit();
    }
})();

Step 6: Execute the Tests on SmartUI Cloud

Execute visual regression tests on SmartUI using the following commands

npx smartui exec node <fileName>.js

**You may use the smartui --help command in case you are facing issues during the execution of SmartUI commands in the CLI. **

View SmartUI Results

You have successfully integrated SmartUI SDK with your Selenium tests. Visit your SmartUI project to view builds and compare snapshots between different test runs.

You can see the Smart UI dashboard to view the results. This will help you identify the mis-matches from the existing Baseline build and do the required visual testing.

For additional information about SmartUI APIs please explore the documentation here