End-to-End Tests
Brut uses Playwright, which is the worst way to end-to-end test, except for all the rest.
Bookmark Playwright Ruby Client Documentation as you will need to consult it frequently.
Create your end-to-end test with
brut scaffold:bashdx/exec brut scaffold e2e_test login # => specs/e2e/login.spec.rbOr, to create it in a subfolder of
specs/e2ebashdx/exec brut scaffold e2e_test login --path=auth # => specs/e2e/auth/login.spec.rbUse
#locatorand CSS selectors. Playwright provides a lot of ways to locate elements, and most of them are extremely confusing or have behavior that is difficuilt to predict and control. CSS selectors is simplest.rubyit "shows a welcome message" do page.goto(HomePage.routing) expect(page.locator("h1")).to have_text("Welcome!") expect(page.locator("header h2")).to have_text("Brut is Awesome") endUse
be_page_forafter navigating to ensure navigation completes and puts you on the correct pagerubyit "allows editing preferences" do page.goto(HomePage.routing) link = page.locator("header nav a[title='Preferences']") link.click # Waits a fixed amount of time for # <meta name="class" content="PreferencesPage"> # to show up in the browser, thus waiting for # navigation to complete expect(page).to be_page_for(PreferencesPage) endUse
with_cluesto dump HTML when your test is failing and you don't know why.rubyit "allows editing preferences" do page.goto(HomePage.routing) link = page.locator("header nav a[title='Preferences']") link.click with_clues do expect(page).to be_page_for(PreferencesPage) end endWhen the
expect(page)...fails,with_clueswill output the HTML of the page at the time the test failed. This can help debug what's going on. Don't leave this in your test - it's for debugging only.
See End-to-End Tests for more.