Skip to main content

SmartUI CLI Complete Reference Guide

This comprehensive reference guide covers all SmartUI CLI and Storybook CLI commands, options, advanced features, and end-to-end workflows for visual regression testing.

Prerequisites

  • Node.js v20.3+ installed (required for SmartUI CLI v4.x.x)
  • npm or yarn package manager
  • LambdaTest account credentials
  • SmartUI project created
note

If you face any problems executing tests with SmartUI-CLI versions >= v4.x.x, upgrade your Node.js version to v20.3 or above.

Installation

npm install -g @lambdatest/smartui-cli@latest

Current Version: v4.1.43+


SmartUI CLI Commands

Main Commands Overview

CommandDescriptionUsage
execExecute test commands with SmartUI serversmartui exec [options] -- <command>
captureCapture screenshots of static URLssmartui capture [options] <file>
uploadUpload screenshots from directorysmartui upload [options] <directory>
upload-pdfUpload PDFs for visual comparisonsmartui upload-pdf [options] <directory>

Command Details

Execute Tests

Execute test commands with SmartUI server running.

Syntax:

smartui exec [options] -- <command>

Arguments:

ArgumentDescriptionExample
<command>Test command to executenpm test, mvn test, python test.py

Options:

OptionShortDescriptionDefault
--port <number>-PPort number for the server49152
--fetch-results [filename]Fetch results and save to JSON fileresults.json
--buildName <string>Custom build name for test runRandom
--scheduled <string>Specify schedule ID-
--userName <string>LambdaTest username (overrides env)-
--accessKey <string>LambdaTest access key (overrides env)-
--config <file>-cConfiguration file path.smartui.json

Examples:

# Basic execution
smartui exec -- npm test

# Custom port
smartui exec -P 5000 -- npm test

# With build name and results
smartui exec --buildName "Release-1.0" --fetch-results results.json -- npm test

# With custom config
smartui exec --config custom-config.json -- npm test

# Override credentials
smartui exec --userName "user" --accessKey "key" -- npm test

Global Options

These options can be used with most commands:

OptionShortDescription
--version-VOutput version number
--config <filepath>-cConfig file path
--markBaselineMark this build as baseline
--baselineBranch <string>Mark build baseline for branch
--baselineBuild <string>Mark build baseline
--githubURL <string>GitHub URL including commit ID
--help-hDisplay help

Storybook CLI Commands

Main Command

Syntax:

smartui storybook [options] <url|directory>

Arguments:

ArgumentDescriptionExample
<url|directory>Storybook URL or static build directoryhttp://localhost:6006 or ./storybook-static

Options:

OptionShortDescriptionDefault
--config <file>-cConfig file path.smartui.json
--force-rebuildForce rebuild of existing buildfalse
--buildName <string>Build name for pipelineRandom
--env <prod|stage>Runtime environmentprod

Examples:

# Local Storybook server
smartui storybook http://localhost:6006 --config .smartui.json

# Static build
smartui storybook ./storybook-static --config .smartui.json

# Public hosted URL
smartui storybook https://your-storybook-url.com --config .smartui.json

# Force rebuild
smartui storybook ./storybook-static --force-rebuild

# Stage environment
smartui storybook http://localhost:6006 --env stage

Advanced Options

Hidden/Advanced Options

These options are available but may not be prominently documented:

OptionCommandsDescriptionExample
--scheduled <string>capture, execSpecify schedule ID for scheduled test runssmartui capture urls.json --scheduled "schedule-123"
--userName <string>capture, exec, uploadOverride LambdaTest username (overrides env)smartui capture urls.json --userName "user"
--accessKey <string>capture, exec, uploadOverride LambdaTest access key (overrides env)smartui exec --accessKey "key" -- npm test
--env <prod|stage>storybookSwitch between production and staging environmentssmartui storybook http://localhost:6006 --env stage
--forcecaptureForcefully apply parallel instances even if not optimalsmartui capture urls.json --parallel 10 --force
--force-rebuildstorybookForce rebuild of an already existing Storybook buildsmartui storybook ./storybook-static --force-rebuild

Usage Examples:

# Scheduled test runs
smartui capture urls.json --scheduled "schedule-123"
smartui exec --scheduled "schedule-123" -- npm test

# Override credentials
smartui capture urls.json --userName "user" --accessKey "key"
smartui exec --userName "user" --accessKey "key" -- npm test

# Environment switching (Storybook)
smartui storybook http://localhost:6006 --env stage
smartui storybook http://localhost:6006 --env prod

# Force parallel execution
smartui capture urls.json --parallel 10 --force

# Force rebuild (Storybook)
smartui storybook ./storybook-static --force-rebuild

Environment Variables

VariableDescriptionRequired
PROJECT_TOKENSmartUI project tokenYes (for CLI projects)
LT_USERNAMELambdaTest usernameYes (for Hooks)
LT_ACCESS_KEYLambdaTest access keyYes (for Hooks)

Setting Environment Variables:

export PROJECT_TOKEN="123456#token"
export LT_USERNAME="username"
export LT_ACCESS_KEY="access_key"
export HTTP_PROXY="http://proxy:8080"
export LT_SDK_DEBUG=true

End-to-End Workflows

Basic Static URL Capture

# 1. Install CLI
npm install -g @lambdatest/smartui-cli

# 2. Set project token
export PROJECT_TOKEN="123456#token"

# 3. Create config
npx smartui config:create .smartui.json

# 4. Create URLs file (urls.json)
# 5. Capture screenshots
npx smartui capture urls.json --config .smartui.json

# 6. Fetch results
npx smartui capture urls.json --fetch-results results.json

Best Practices

Build Naming

  • Use meaningful, consistent names
  • Include version or commit info
  • Avoid special characters
  • Use environment variables for dynamic names
# Good
--buildName "Release-v1.0.0"
--buildName "$(git rev-parse --short HEAD)"
--buildName "${{ github.sha }}"

# Bad
--buildName "test"
--buildName "build-$(date)"

Troubleshooting

Server Not Running

# Check status
npx smartui exec:ping

# Start server
npx smartui exec:start

# Verify address
echo $SMARTUI_SERVER_ADDRESS

Additional Resources

Test across 3000+ combinations of browsers, real devices & OS.

Book Demo

Help and Support

Related Articles