Performance: System tests with Capybara
System tests with Capybara affect the overall test suite runtime and browser interaction speed, impacting developer feedback loop and CI pipeline duration.
visit '/users' find('#submit-button').click
visit '/users' find('div').click find('div').click find('div').click
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Generic selectors (e.g., 'div') | Multiple DOM queries | Multiple reflows if clicks trigger layout | High paint cost if many updates | [X] Bad |
| Specific selectors (e.g., '#id', '[data-test]') | Single targeted DOM query | Minimal reflows | Low paint cost | [OK] Good |
| Fixed sleep waits | No DOM operations during wait | None | Blocks test thread | [X] Bad |
| Capybara wait methods | DOM queries with timeout | Minimal reflows | Non-blocking | [OK] Good |
| Full browser mode | Full DOM and rendering | Multiple reflows | High paint and CPU cost | [X] Bad |
| Headless browser mode | Full DOM but no UI paint | Minimal paint cost | Lower CPU usage | [OK] Good |
visit with a path or URL to open a page.root_path is the Rails helper for homepage path, so visit root_path is correct.visit root_path
fill_in 'Email', with: 'user@example.com'
fill_in 'Password', with: 'secret'
click_button 'Log in'
expect(page).to have_content('Welcome, user@example.com')have_content will pass and test passes.visit root_path fill_in 'Username', with: 'testuser' click_button 'Submit'
visit is called, the likely cause is the field labeled 'Username' does not exist on the page.Pass the test and this pattern moves unknown