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.
- 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.
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:
- Go to Projects page
- Click on the
new project
button - Select the platform as CLI or Web for executing your
SDK
tests. - Add name of the project, approvers for the changes found, tags for any filter or easy navigation.
- Click on the Submit.
Once you have created a SmartUI Project, you can generate screenshots by running automation scripts. Follow the below steps to successfully generate screenshots
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
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"
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-****-****-****-************"
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
}
}
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.
:::
- You can incorporate SmartUI into your custom
Selenium
automation test (any platform) script by adding thesmartuiSnapshot
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();
}
})();
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.
**
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