From de9c261c0ebd6f16e0b18d064775dcbbede5b1b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 23 Mar 2021 16:41:39 +0100 Subject: [PATCH 1/2] Clear fields in tests before filling them in There seems to be an issue with capybara or chromedriver which results in `fill_in` sometimes appending to an input rather than overwriting [1], causing some tests to fail under certain circumstances. Clearing fields before filling them in solves the issue. Note we're now getting warnings on all tests using the rack driver. I haven't found a way to avoid the `clear: :backspace` option in non-JavaScript tests, so to avoid the annoying warnings we should reduce the number of tests using the rack driver even more. [1] See issue 2419 in https://github.com/teamcapybara/capybara/issues --- spec/rails_helper.rb | 1 + spec/system/budgets/ballots_spec.rb | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index a3ecc187d..06d22b895 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -47,6 +47,7 @@ end Capybara.exact = true Capybara.enable_aria_label = true +Capybara.default_set_options = { clear: :backspace } Capybara.disable_animation = true OmniAuth.config.test_mode = true diff --git a/spec/system/budgets/ballots_spec.rb b/spec/system/budgets/ballots_spec.rb index 3306425e5..6876b4a79 100644 --- a/spec/system/budgets/ballots_spec.rb +++ b/spec/system/budgets/ballots_spec.rb @@ -645,6 +645,10 @@ describe "Ballots" do click_button "Save heading" expect(page).to have_content "Heading updated successfully" + + within "tr", text: "New York" do + expect(page).to have_css "td", exact_text: "€10" + end end in_browser(:user) do From 235e39672eaf121b514105794b71e0d8d4a5cd45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 9 Apr 2021 18:19:51 +0200 Subject: [PATCH 2/2] Create admin user before starting a browser Even after the previous changes, this test is still failing sometimes (although now it fails for a different reason). We're doing this change in order to discard it as the reason why the test is failing. --- spec/system/budgets/ballots_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/system/budgets/ballots_spec.rb b/spec/system/budgets/ballots_spec.rb index 6876b4a79..6d5f65014 100644 --- a/spec/system/budgets/ballots_spec.rb +++ b/spec/system/budgets/ballots_spec.rb @@ -630,6 +630,7 @@ describe "Ballots" do scenario "Edge case voting a non-elegible investment" do investment1 = create(:budget_investment, :selected, heading: new_york, price: 10000) + admin_user = create(:administrator).user in_browser(:user) do login_as user @@ -639,7 +640,7 @@ describe "Ballots" do end in_browser(:admin) do - login_as create(:administrator).user + login_as admin_user visit edit_admin_budget_group_heading_path(budget, states, new_york) fill_in "Amount", with: 10 click_button "Save heading"