Fetching Results through SmartUI SDK
SmartUI CLI allows you to fetch detailed build results after executing your visual tests. This feature enables you to access comprehensive information about your build and screenshots in a JSON file, making it easier to integrate with your CI/CD pipelines and automation workflows.
Prerequisites
- Basic understanding of Command Line Interface
- Login to LambdaTest SmartUI with your credentials.
- Ensure you are using
@lambdatest/smartui-cli
version 4.0.8 or higher. - A properly configured SmartUI CLI project
Steps to Use
Step 1: Install SmartUI CLI
If you haven't already installed SmartUI CLI, install it using npm:
npm i @lambdatest/smartui-cli
Step 2: Configure your Project Token
Setup your project token show in the SmartUI app after, creating your project.
- MacOS/Linux
- Windows - CMD
- Windows-PS
export PROJECT_TOKEN="123456#1234abcd-****-****-****-************"
set PROJECT_TOKEN="123456#1234abcd-****-****-****-************"
$Env:PROJECT_TOKEN="123456#1234abcd-****-****-****-************"
Step 3: Execute Tests with Results Fetching
You can fetch build results by adding the --fetch-results
flag to your test execution command. Here are different ways to use this feature:
Default Usage
If no filename is specified, results will be stored in results.json
:
npx smartui --config .smartui.json exec --fetch-results -- <execution-command>
Example: For a
Node.js
test script :npx smartui --config .smartui.json exec --fetch-results -- node test.js
Custom Filename
Specify a custom filename for your results:
npx smartui --config .smartui.json exec --fetch-results custom-results.json -- node test.js
Step 4: Understanding the Results
The fetched results JSON file contains detailed information about your build and screenshots. Here's what you'll find in the results file:
{
"screenshots": {
"Screenshot-1": [
{
"screenshot_name": "Screenshot-1",
"captured_image": "image_url",
"baseline_image": "image_url",
"compared_image": "image_url",
"browser_name": "edge",
"viewport": "1920",
"mismatch_percentage": 3.3,
"status": "Changes found"
},
{
"screenshot_name": "Screenshot-1",
"captured_image": "image_url",
"baseline_image": "image_url",
"compared_image": "image_url",
"browser_name": "firefox",
"viewport": "1366",
"mismatch_percentage": 4.74,
"status": "Changes found"
},
{
"screenshot_name": "Screenshot-1",
"captured_image": "image_url",
"baseline_image": "image_url",
"compared_image": "image_url",
"browser_name": "chrome",
"viewport": "1366",
"mismatch_percentage": 4.64,
"status": "Changes found"
},
{
"screenshot_name": "Screenshot-1",
"captured_image": "image_url",
"baseline_image": "image_url",
"compared_image": "image_url",
"browser_name": "chrome",
"viewport": "1920",
"mismatch_percentage": 3.3,
"status": "Changes found"
},
],
"Screenshot-2": [
{
"screenshot_name": "Screenshot-2",
"captured_image": "image_url",
"baseline_image": "image_url",
"compared_image": "image_url",
"browser_name": "edge",
"viewport": "1920",
"mismatch_percentage": 0.0,
"status": "Approved"
},
{
"screenshot_name": "Screenshot-2",
"captured_image": "image_url",
"baseline_image": "image_url",
"compared_image": "image_url",
"browser_name": "firefox",
"viewport": "1366",
"mismatch_percentage": 4.74,
"status": "Changes found"
},
{
"screenshot_name": "Screenshot-2",
"captured_image": "image_url",
"baseline_image": "image_url",
"compared_image": "image_url",
"browser_name": "chrome",
"viewport": "1366",
"mismatch_percentage": 4.64,
"status": "Changes found"
},
{
"screenshot_name": "Screenshot-2",
"captured_image": "image_url",
"baseline_image": "image_url",
"compared_image": "image_url",
"browser_name": "chrome",
"viewport": "1920",
"mismatch_percentage": 3.3,
"status": "Changes found"
},
]
},
"build": {
"build_id": "b420b7a9-77c6-****-****",
"baseline": false,
"build_type": "smartui-cli",
"build_status_ind": "completed",
"build_status": "pending-approval",
"commitId": "2b93***",
"branch": "main",
"commitAuthor": "John Doe",
"commitMessage": "Merge pull request from xyz/main"
},
"project": {
"project_id": "1dfb7712-7f20-446f-***-***",
"name": "Project-Name",
"username": "johndoe",
"project_type": "smartui-cli",
"projectCategory": "web",
"platform": "cli"
}
}