关于 lettuce-skill
lettuce-skill 是用于旧版 Lettuce Python BDD 测试的参考技能,涵盖 Gherkin 功能文件、步骤定义及环境设置与清理。它指出 Lettuce 基本已停止维护,并建议新项目考虑 Behave。
主要功能
- 01Gherkin 功能文件模式
- 02Python 步骤定义示例
- 03使用 terrain.py 设置和清理场景
- 04Selenium 浏览器测试示例
- 05迁移到 Behave 的建议
适用场景
- 01维护现有的 Lettuce BDD 测试
- 02编写场景并将其关联到 Python 步骤
- 03规划从 Lettuce 迁移到 Behave
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ lambdatest/ agent-skills --skill lettuce-skill安装后在 Claude Code 中输入/lettuce-skill确认已加载。
附带文件reference/advanced-patterns.mdreference/playbook.md
详细介绍
Lettuce BDD 技能(旧版)
注意: Lettuce 基本上已无人维护。对于新的 Python BDD 项目,请改用 Behave。
核心模式
功能文件(features/login.feature)
Feature: User Login
Scenario: Successful login
Given I navigate to the login page
When I enter "[email protected]" as email
And I enter "password123" as password
And I click login
Then I should see the dashboard
Scenario: Invalid login
Given I navigate to the login page
When I enter "[email protected]" as email
And I enter "wrong" as password
And I click login
Then I should see "Invalid credentials"
步骤定义(features/steps.py)
from lettuce import step, world
from selenium import webdriver
from selenium.webdriver.common.by import By
@step(r'I navigate to the login page')
def navigate_to_login(step):
world.browser = webdriver.Chrome()
world.browser.get(world.base_url + '/login')
@step(r'I enter "([^"]*)" as email')
def enter_email(step, email):
el = world.browser.find_element(By.ID, 'email')
el.clear()
el.send_keys(email)
@step(r'I enter "([^"]*)" as password')
def enter_password(step, password):
el = world.browser.find_element(By.ID, 'password')
el.clear()
el.send_keys(password)
@step(r'I click login')
def click_login(step):
world.browser.find_element(By.CSS_SELECTOR, 'button[type="submit"]').click()
@step(r'I should see the dashboard')
def see_dashboard(step):
assert '/dashboard' in world.browser.current_url
@step(r'I should see "([^"]*)"')
def see_text(step, text):
assert text in world.browser.page_source
Terrain(设置/清理 — terrain.py)
from lettuce import before, after, world
@before.all
def setup():
world.base_url = 'http://localhost:3000'
@before.each_scenario
def before_scenario(scenario):
pass
@after.each_scenario
def cleanup(scenario):
if hasattr(world, 'browser'):
world.browser.quit()
@after.all
def teardown(total):
print(f"Ran {total.scenarios_ran} scenarios")
安装:pip install lettuce selenium
运行:lettuce 或 lettuce features/login.feature
在 TestMu AI 上进行云端执行
设置环境变量:LT_USERNAME、LT_ACCESS_KEY
# terrain.py
from selenium import webdriver
import os
@before.all
def setup():
lt_options = {
"user": os.environ["LT_USERNAME"],
"accessKey": os.environ["LT_ACCESS_KEY"],
"build": "Lettuce Build",
"platformName": "Windows 11",
"video": True,
"console": True,
}
options = webdriver.ChromeOptions()
options.set_capability("LT:Options", lt_options)
world.browser = webdriver.Remote(
command_executor=f"https://{os.environ['LT_USERNAME']}:{os.environ['LT_ACCESS_KEY']}@hub.lambdatest.com/wd/hub",
options=options,
)
迁移:考虑切换到 behave,以获得积极维护
深入模式
有关高级模式、调试指南、CI/CD 集成和最佳实践,
请参阅 reference/playbook.md。
评论
支持 Markdown