Author: Konstantin Filtschew
Presentation: 2020-01-30
Last Update: 2020-02-03
visit root_url
# capybara: load requested url
# rack-test: fake Rack request
# rack-test: in-memory instance of Rails
# rack-test: response parse by rack-test
# rack-test: saved as current page
# capybara: ...
Running a test using Selenium, capybara-webkit, Poltergeist, ...
Understand:
Bad
first(".active").click
Good
find(".active").click
Bad
all(".active").each(&:click)
Good
find(".active", match: :first)
all(".active").each(&:click)
Bad
execute_script("$('.active').focus()")
Good
find(".active")
execute_script("$('.active').focus()")
Bad
expect(find_field("Name").value).to eq("Kevin")
Good
expect(page).to have_field("Name", with: "Kevin")
Bad
expect(has_css?(".active")).to be_falsey
Good
expect(page).not_to have_css(".active")
Bad
expect(page).to !have_css(".some-class")
Good
expect(page).to have_no_css(".some-class")
Good
expect(page).to have_no_css(".some-class")
Better
expect(page).to_not have_css(".some-class")
Still won’t find them all
Capybara.default_max_wait_time
sleep 1
Wait, can we use it to fail flaky tests?
# app/controllers/application_controller.rb
after_action -> { sleep(0.5) }
# get extra time
expect(page).to have_current_path(expected_path)
expect(page).to have_content("page_title")
expect(page).to have_content("element_below")
Look up things that should already be there, buy additional time.
Understand the underlying architecture
https://bit.ly/2RsxDfM