$npx -y skills add LambdaTest/agent-skills --skill capybara-skillGenerates Capybara E2E tests in Ruby with RSpec integration. Acceptance testing DSL for web apps. Use when user mentions "Capybara", "visit", "fill_in", "click_button", "Ruby E2E". Triggers on: "Capybara", "Ruby acceptance test", "fill_in", "click_button", "have_content".
| 1 | # Capybara Automation Skill |
| 2 | |
| 3 | ## Core Patterns |
| 4 | |
| 5 | ### Basic Test (RSpec) |
| 6 | |
| 7 | ```ruby |
| 8 | require 'capybara/rspec' |
| 9 | |
| 10 | RSpec.describe 'Login', type: :feature do |
| 11 | it 'logs in with valid credentials' do |
| 12 | visit '/login' |
| 13 | fill_in 'Email', with: 'user@test.com' |
| 14 | fill_in 'Password', with: 'password123' |
| 15 | click_button 'Login' |
| 16 | expect(page).to have_content('Dashboard') |
| 17 | expect(page).to have_current_path('/dashboard') |
| 18 | end |
| 19 | |
| 20 | it 'shows error for invalid credentials' do |
| 21 | visit '/login' |
| 22 | fill_in 'Email', with: 'wrong@test.com' |
| 23 | fill_in 'Password', with: 'wrong' |
| 24 | click_button 'Login' |
| 25 | expect(page).to have_content('Invalid credentials') |
| 26 | end |
| 27 | end |
| 28 | ``` |
| 29 | |
| 30 | ### DSL |
| 31 | |
| 32 | ```ruby |
| 33 | # Navigation |
| 34 | visit '/path' |
| 35 | go_back |
| 36 | go_forward |
| 37 | |
| 38 | # Interacting |
| 39 | fill_in 'Label or Name', with: 'text' |
| 40 | choose 'Radio Label' |
| 41 | check 'Checkbox Label' |
| 42 | uncheck 'Checkbox Label' |
| 43 | select 'Option', from: 'Select Label' |
| 44 | attach_file 'Upload', '/path/to/file' |
| 45 | click_button 'Submit' |
| 46 | click_link 'More Info' |
| 47 | click_on 'Button or Link' |
| 48 | |
| 49 | # Finding |
| 50 | find('#id') |
| 51 | find('.class') |
| 52 | find('[data-testid="x"]') |
| 53 | find(:xpath, '//div') |
| 54 | all('.items').count |
| 55 | |
| 56 | # Matchers |
| 57 | expect(page).to have_content('text') |
| 58 | expect(page).to have_selector('#element') |
| 59 | expect(page).to have_css('.class') |
| 60 | expect(page).to have_button('Submit') |
| 61 | expect(page).to have_field('Email') |
| 62 | expect(page).to have_link('Click Here') |
| 63 | expect(page).to have_current_path('/expected') |
| 64 | expect(page).to have_no_content('error') |
| 65 | ``` |
| 66 | |
| 67 | ### Within Scope |
| 68 | |
| 69 | ```ruby |
| 70 | within('#login-form') do |
| 71 | fill_in 'Email', with: 'user@test.com' |
| 72 | click_button 'Login' |
| 73 | end |
| 74 | |
| 75 | within_table('users') do |
| 76 | expect(page).to have_content('Alice') |
| 77 | end |
| 78 | ``` |
| 79 | |
| 80 | ### TestMu AI Cloud |
| 81 | |
| 82 | ```ruby |
| 83 | Capybara.register_driver :lambdatest do |app| |
| 84 | caps = Selenium::WebDriver::Remote::Capabilities.new( |
| 85 | browserName: 'chrome', |
| 86 | 'LT:Options' => { |
| 87 | user: ENV['LT_USERNAME'], accessKey: ENV['LT_ACCESS_KEY'], |
| 88 | build: 'Capybara Build', name: 'Login Test', |
| 89 | platform: 'Windows 11', video: true |
| 90 | } |
| 91 | ) |
| 92 | Capybara::Selenium::Driver.new(app, |
| 93 | browser: :remote, |
| 94 | url: 'https://hub.lambdatest.com/wd/hub', |
| 95 | capabilities: caps) |
| 96 | end |
| 97 | Capybara.default_driver = :lambdatest |
| 98 | ``` |
| 99 | |
| 100 | ## Setup: `gem 'capybara'` + `gem 'selenium-webdriver'` in Gemfile |
| 101 | ## Run: `bundle exec rspec spec/features/` |
| 102 | |
| 103 | ## Cloud (TestMu AI) |
| 104 | |
| 105 | For remote browser execution, see [reference/cloud-integration.md](reference/cloud-integration.md) and [shared/testmu-cloud-reference.md](../shared/testmu-cloud-reference.md). |
| 106 | |
| 107 | ## Deep Patterns |
| 108 | |
| 109 | See `reference/playbook.md` for production-grade patterns: |
| 110 | |
| 111 | | Section | What You Get | |
| 112 | |---------|-------------| |
| 113 | | §1 Project Setup | Gemfile, Capybara config, driver registration, LambdaTest | |
| 114 | | §2 Feature Specs | Login flows, JavaScript interactions, modals, async content | |
| 115 | | §3 Page Objects | SitePrism pages with elements/sections, usage in specs | |
| 116 | | §4 API Testing | Request specs with auth headers, JSON assertions | |
| 117 | | §5 Database Cleaning | DatabaseCleaner transaction/truncation strategies | |
| 118 | | §6 Matchers & Helpers | Custom helpers, sign_in, expect_flash | |
| 119 | | §7 CI/CD Integration | GitHub Actions with Postgres, Redis, Chrome | |
| 120 | | §8 Debugging Table | 12 common problems with causes and fixes | |
| 121 | | §9 Best Practices | 14-item Capybara testing checklist | |