关于 smartui-skill
面向使用 LambdaTest SmartUI 进行视觉回归测试的技能指南,涵盖 Playwright 和 Selenium、命令行运行、截图基线及差异审查。
主要功能
- 01Playwright 与 Selenium 用法
- 02命令行配置与运行
- 03浏览器和视口配置
- 04基线比较与审批
- 05Storybook 截图流程
适用场景
- 01比较不同测试运行的截图
- 02检查多个视口下的响应式布局
- 03在 SmartUI 控制面板审查视觉变化
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ lambdatest/ agent-skills --skill smartui-skill安装后在 Claude Code 中输入/smartui-skill确认已加载。
附带文件reference/playbook.md
详细介绍
SmartUI 视觉回归技能
核心模式
Playwright + SmartUI SDK
const { chromium } = require('playwright');
const { smartuiSnapshot } = require('@lambdatest/smartui-cli');
(async () => {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
await smartuiSnapshot(page, 'Homepage');
await page.goto('https://example.com/login');
await smartuiSnapshot(page, 'Login Page');
await browser.close();
})();
Selenium + SmartUI
// Take SmartUI screenshot
((JavascriptExecutor) driver).executeScript(
"smartui.takeScreenshot=Login Page"
);
CLI 执行
# Install
npm install @lambdatest/smartui-cli@latest --save-dev
# Configure
npx smartui config:create smartui.config.json
# Execute
npx smartui exec -- node test.js
# or with Playwright
npx smartui exec -- npx playwright test
smartui.config.json
{
"web": {
"browsers": ["chrome", "firefox", "safari"],
"viewports": [[1920, 1080], [1366, 768], [375, 812]]
},
"waitForPageRender": 5000,
"waitForTimeout": 1000
}
SmartUI 与 Storybook
npx smartui storybook http://localhost:6006 --config smartui.config.json
审批工作流
- 首次运行会创建基线截图
- 后续运行会与基线进行比较
- 差异会在仪表板中高亮显示
- 在 LambdaTest SmartUI 仪表板中批准或拒绝更改
- 已批准的截图会成为新的基线
反模式
| 不佳做法 | 良好做法 | 原因 |
|---|---|---|
| 不配置视口 | 配置多个视口 | 响应式问题 |
| 不等待渲染完成 | waitForPageRender | 截图不完整 |
| 对所有内容截图 | 针对关键页面/组件 | 减少噪声 |
| 没有审批流程 | 在仪表板中审查差异 | 捕获回归问题 |
云端身份验证
设置环境变量:
export PROJECT_TOKEN="your-smartui-project-token" # From SmartUI dashboard
export LT_USERNAME="your-username" # For Selenium/Playwright cloud
export LT_ACCESS_KEY="your-access-key" # For Selenium/Playwright cloud
CLI 方式(使用 PROJECT_TOKEN):
npx smartui exec -- npx playwright test
Selenium 云端方式(使用 LT_USERNAME/LT_ACCESS_KEY):
// Capabilities include SmartUI options
HashMap<String, Object> ltOptions = new HashMap<>();
ltOptions.put("user", System.getenv("LT_USERNAME"));
ltOptions.put("accessKey", System.getenv("LT_ACCESS_KEY"));
ltOptions.put("build", "SmartUI Build");
ltOptions.put("smartUI.project", "My SmartUI Project");
ChromeOptions options = new ChromeOptions();
options.setCapability("LT:Options", ltOptions);
WebDriver driver = new RemoteWebDriver(
new URL("https://hub.lambdatest.com/wd/hub"), options);
快速参考
| 任务 | 命令 |
|---|---|
| 安装 | npm install @lambdatest/smartui-cli@latest |
| 初始化配置 | npx smartui config:create smartui.config.json |
| 运行 | npx smartui exec -- <test command> |
| Storybook | npx smartui storybook <url> |
| 仪表板 | https://smartui.lambdatest.com |
深入模式
有关高级模式、调试指南、CI/CD 集成和最佳实践,
请参阅 reference/playbook.md。
评论
支持 Markdown