$npx -y skills add LambdaTest/agent-skills --skill lettuce-skillGenerates Lettuce BDD tests for Python with feature files and step definitions. Note: Lettuce is legacy/unmaintained; consider Behave for new projects. Use when user specifically mentions "Lettuce". Triggers on: "Lettuce", "lettuce test", "lettuce BDD".
| 1 | # Lettuce BDD Skill (Legacy) |
| 2 | |
| 3 | > **Note:** Lettuce is largely unmaintained. For new Python BDD projects, use **Behave** instead. |
| 4 | |
| 5 | ## Core Patterns |
| 6 | |
| 7 | ### Feature File (features/login.feature) |
| 8 | |
| 9 | ```gherkin |
| 10 | Feature: User Login |
| 11 | Scenario: Successful login |
| 12 | Given I navigate to the login page |
| 13 | When I enter "user@test.com" as email |
| 14 | And I enter "password123" as password |
| 15 | And I click login |
| 16 | Then I should see the dashboard |
| 17 | |
| 18 | Scenario: Invalid login |
| 19 | Given I navigate to the login page |
| 20 | When I enter "bad@test.com" as email |
| 21 | And I enter "wrong" as password |
| 22 | And I click login |
| 23 | Then I should see "Invalid credentials" |
| 24 | ``` |
| 25 | |
| 26 | ### Step Definitions (features/steps.py) |
| 27 | |
| 28 | ```python |
| 29 | from lettuce import step, world |
| 30 | from selenium import webdriver |
| 31 | from selenium.webdriver.common.by import By |
| 32 | |
| 33 | @step(r'I navigate to the login page') |
| 34 | def navigate_to_login(step): |
| 35 | world.browser = webdriver.Chrome() |
| 36 | world.browser.get(world.base_url + '/login') |
| 37 | |
| 38 | @step(r'I enter "([^"]*)" as email') |
| 39 | def enter_email(step, email): |
| 40 | el = world.browser.find_element(By.ID, 'email') |
| 41 | el.clear() |
| 42 | el.send_keys(email) |
| 43 | |
| 44 | @step(r'I enter "([^"]*)" as password') |
| 45 | def enter_password(step, password): |
| 46 | el = world.browser.find_element(By.ID, 'password') |
| 47 | el.clear() |
| 48 | el.send_keys(password) |
| 49 | |
| 50 | @step(r'I click login') |
| 51 | def click_login(step): |
| 52 | world.browser.find_element(By.CSS_SELECTOR, 'button[type="submit"]').click() |
| 53 | |
| 54 | @step(r'I should see the dashboard') |
| 55 | def see_dashboard(step): |
| 56 | assert '/dashboard' in world.browser.current_url |
| 57 | |
| 58 | @step(r'I should see "([^"]*)"') |
| 59 | def see_text(step, text): |
| 60 | assert text in world.browser.page_source |
| 61 | ``` |
| 62 | |
| 63 | ### Terrain (Setup/Teardown — terrain.py) |
| 64 | |
| 65 | ```python |
| 66 | from lettuce import before, after, world |
| 67 | |
| 68 | @before.all |
| 69 | def setup(): |
| 70 | world.base_url = 'http://localhost:3000' |
| 71 | |
| 72 | @before.each_scenario |
| 73 | def before_scenario(scenario): |
| 74 | pass |
| 75 | |
| 76 | @after.each_scenario |
| 77 | def cleanup(scenario): |
| 78 | if hasattr(world, 'browser'): |
| 79 | world.browser.quit() |
| 80 | |
| 81 | @after.all |
| 82 | def teardown(total): |
| 83 | print(f"Ran {total.scenarios_ran} scenarios") |
| 84 | ``` |
| 85 | |
| 86 | ## Setup: `pip install lettuce selenium` |
| 87 | ## Run: `lettuce` or `lettuce features/login.feature` |
| 88 | |
| 89 | ### Cloud Execution on TestMu AI |
| 90 | |
| 91 | Set environment variables: `LT_USERNAME`, `LT_ACCESS_KEY` |
| 92 | |
| 93 | ```python |
| 94 | # terrain.py |
| 95 | from selenium import webdriver |
| 96 | import os |
| 97 | |
| 98 | @before.all |
| 99 | def setup(): |
| 100 | lt_options = { |
| 101 | "user": os.environ["LT_USERNAME"], |
| 102 | "accessKey": os.environ["LT_ACCESS_KEY"], |
| 103 | "build": "Lettuce Build", |
| 104 | "platformName": "Windows 11", |
| 105 | "video": True, |
| 106 | "console": True, |
| 107 | } |
| 108 | options = webdriver.ChromeOptions() |
| 109 | options.set_capability("LT:Options", lt_options) |
| 110 | world.browser = webdriver.Remote( |
| 111 | command_executor=f"https://{os.environ['LT_USERNAME']}:{os.environ['LT_ACCESS_KEY']}@hub.lambdatest.com/wd/hub", |
| 112 | options=options, |
| 113 | ) |
| 114 | ``` |
| 115 | ## Migration: Consider switching to `behave` for active maintenance |
| 116 | |
| 117 | ## Deep Patterns |
| 118 | |
| 119 | For advanced patterns, debugging guides, CI/CD integration, and best practices, |
| 120 | see `reference/playbook.md`. |