Add missing expectations to confirm the page has changed

After a `visit`, we were checking for content or filling in fields that
were already there before the `visit`, so we weren't 100% sure that the
request had finished before the test continued.

In the case of the verification tests, we were clicking the submit
buttons over and over without and then checking or interacting with
elements that were already there. Even though the button was disabled
between requests, meaning there wouldn't be simultaneous requests, it
was possible to interact with a form field before waiting for the
request to finish.

Some of these tests have recently failed on our CI, and it might be
because of that:

```
1) Admin budgets Edit Changing name for current locale will update the
   slug if budget is in draft phase
   Failure/Error: raise ex, cause: cause

   Selenium::WebDriver::Error::UnknownError:
     unknown error: unhandled inspector error: {"code":-32000,
     "message":"Node with given id does not belong to the document"}
       (Session info: chrome=134.0.6998.35)

1) Budgets creation wizard Creation of a multiple-headings budget by
   steps
   Failure/Error: expect(page).to have_content "Heading created
   successfully!"

   Selenium::WebDriver::Error::UnknownError:
     unknown error: unhandled inspector error: {"code":-32000,
     "message":"Node with given id does not belong to the document"}
       (Session info: chrome=134.0.6998.35)

1) Custom information texts Show custom texts instead of default ones
   Failure/Error: raise ex, cause: cause

   Selenium::WebDriver::Error::UnknownError:
     unknown error: unhandled inspector error: {"code":-32000,
     "message":"Node with given id does not belong to the document"}
       (Session info: chrome=134.0.6998.35)

1) Users Regular authentication Sign in Avoid username-email collisions
   Failure/Error: raise ex, cause: cause

   Selenium::WebDriver::Error::UnknownError:
     unknown error: unhandled inspector error: {"code":-32000,
     "message":"Node with given id does not belong to the document"}
       (Session info: chrome=134.0.6998.35)

2) Verify Letter Code verification 6 tries allowed
   Failure/Error: raise ex, cause: cause

   Selenium::WebDriver::Error::UnknownError:
     unknown error: unhandled inspector error: {"code":-32000,
     "message":"Node with given id does not belong to the document"}
       (Session info: chrome=134.0.6998.35)

2) Valuation budget investments Valuate Finish valuation
   Failure/Error: raise ex, cause: cause

   Selenium::WebDriver::Error::UnknownError:
     unknown error: unhandled inspector error: {"code":-32000,
     "message":"Node with given id does not belong to the document"}
       (Session info: chrome=134.0.6998.35)

1) Users Delete a level 2 user account from document verification page
   Failure/Error: raise ex, cause: cause

   Selenium::WebDriver::Error::UnknownError:
     unknown error: unhandled inspector error: {"code":-32000,
     "message":"Node with given id does not belong to the document"}
       (Session info: chrome=134.0.6998.35)
```
This commit is contained in:
Javi Martín
2025-03-14 20:30:51 +01:00
parent 99932e0aaf
commit f63be041c1
16 changed files with 88 additions and 44 deletions

View File

@@ -189,6 +189,7 @@ describe "Admin budget headings", :admin do
visit budget_investments_path(budget, heading_id: "old-english-name") visit budget_investments_path(budget, heading_id: "old-english-name")
expect(page).not_to have_content "Heading updated successfully"
expect(page).to have_content "Old English Name" expect(page).to have_content "Old English Name"
visit edit_admin_budget_group_heading_path(budget, group, heading) visit edit_admin_budget_group_heading_path(budget, group, heading)
@@ -201,6 +202,7 @@ describe "Admin budget headings", :admin do
visit budget_investments_path(budget, heading_id: "new-english-name") visit budget_investments_path(budget, heading_id: "new-english-name")
expect(page).not_to have_content "Heading updated successfully"
expect(page).to have_content "New English Name" expect(page).to have_content "New English Name"
end end
end end

View File

@@ -128,6 +128,9 @@ describe "Admin budgets", :admin do
expect(page).to have_content "Group created successfully!" expect(page).to have_content "Group created successfully!"
within("#notice") { click_button "Close" }
expect(page).not_to have_content "Group created successfully!"
click_button "Add new group" click_button "Add new group"
fill_in "Group name", with: "District A" fill_in "Group name", with: "District A"
click_button "Create new group" click_button "Create new group"
@@ -315,6 +318,7 @@ describe "Admin budgets", :admin do
visit budget_path(id: "old-english-name") visit budget_path(id: "old-english-name")
expect(page).not_to have_content "Participatory budget updated successfully"
expect(page).to have_content "Old English Name" expect(page).to have_content "Old English Name"
visit edit_admin_budget_path(budget) visit edit_admin_budget_path(budget)
@@ -327,6 +331,7 @@ describe "Admin budgets", :admin do
visit budget_path(id: "new-english-name") visit budget_path(id: "new-english-name")
expect(page).not_to have_content "Participatory budget updated successfully"
expect(page).to have_content "New English Name" expect(page).to have_content "New English Name"
end end

View File

@@ -48,9 +48,9 @@ describe "Budgets wizard, first step", :admin do
visit new_admin_budgets_wizard_budget_path visit new_admin_budgets_wizard_budget_path
click_button "Continue to groups" click_button "Continue to groups"
expect(page).not_to have_content "New participatory budget created successfully!"
expect(page).to have_css ".is-invalid-label", text: "Name" expect(page).to have_css ".is-invalid-label", text: "Name"
expect(page).to have_css ".creation-timeline" expect(page).to have_css ".creation-timeline"
expect(page).not_to have_content "New participatory budget created successfully!"
end end
scenario "Name should be unique" do scenario "Name should be unique" do
@@ -60,9 +60,9 @@ describe "Budgets wizard, first step", :admin do
fill_in "Name", with: "Existing Name" fill_in "Name", with: "Existing Name"
click_button "Continue to groups" click_button "Continue to groups"
expect(page).not_to have_content "New participatory budget created successfully!"
expect(page).to have_css(".is-invalid-label", text: "Name") expect(page).to have_css(".is-invalid-label", text: "Name")
expect(page).to have_css("small.form-error", text: "has already been taken") expect(page).to have_css("small.form-error", text: "has already been taken")
expect(page).not_to have_content "New participatory budget created successfully!"
end end
scenario "Do not show results and stats settings on new budget" do scenario "Do not show results and stats settings on new budget" do

View File

@@ -53,12 +53,12 @@ describe "Budgets wizard, groups step", :admin do
click_button "Create new group" click_button "Create new group"
expect(page).not_to have_content "Group created successfully!"
expect(page).to have_css ".is-invalid-label", text: "Group name" expect(page).to have_css ".is-invalid-label", text: "Group name"
expect(page).to have_css ".creation-timeline" expect(page).to have_css ".creation-timeline"
expect(page).to have_content "can't be blank" expect(page).to have_content "can't be blank"
expect(page).to have_button "Create new group" expect(page).to have_button "Create new group"
expect(page).to have_button "Cancel" expect(page).to have_button "Cancel"
expect(page).not_to have_content "Group created successfully!"
expect(page).not_to have_button "Add new group" expect(page).not_to have_button "Add new group"
expect(page).not_to have_content "Continue to headings" expect(page).not_to have_content "Continue to headings"
end end

View File

@@ -74,11 +74,11 @@ describe "Budgets wizard, headings step", :admin do
click_button "Create new heading" click_button "Create new heading"
expect(page).not_to have_content "Heading created successfully!"
expect(page).to have_css(".is-invalid-label", text: "Heading name") expect(page).to have_css(".is-invalid-label", text: "Heading name")
expect(page).to have_content "can't be blank" expect(page).to have_content "can't be blank"
expect(page).to have_button "Create new heading" expect(page).to have_button "Create new heading"
expect(page).to have_button "Cancel" expect(page).to have_button "Cancel"
expect(page).not_to have_content "Heading created successfully!"
expect(page).not_to have_button "Add new heading" expect(page).not_to have_button "Add new heading"
expect(page).not_to have_content "Continue to phases" expect(page).not_to have_content "Continue to phases"

View File

@@ -52,6 +52,9 @@ describe "Budgets creation wizard", :admin do
within("table") { expect(page).to have_content "All city" } within("table") { expect(page).to have_content "All city" }
expect(page).not_to have_content "There are no groups." expect(page).not_to have_content "There are no groups."
within("#notice") { click_button "Close" }
expect(page).not_to have_content "Group created successfully!"
click_button "Add new group" click_button "Add new group"
fill_in "Group name", with: "Districts" fill_in "Group name", with: "Districts"
click_button "Create new group" click_button "Create new group"
@@ -85,6 +88,9 @@ describe "Budgets creation wizard", :admin do
within_table("Headings in Districts") { expect(page).to have_content "North" } within_table("Headings in Districts") { expect(page).to have_content "North" }
expect(page).not_to have_content "There are no headings" expect(page).not_to have_content "There are no headings"
within("#notice") { click_button "Close" }
expect(page).not_to have_content "Heading created successfully!"
click_button "Add new heading" click_button "Add new heading"
fill_in "Heading name", with: "South" fill_in "Heading name", with: "South"
fill_in "Money amount", with: "500000" fill_in "Money amount", with: "500000"

View File

@@ -113,17 +113,24 @@ describe "Admin booths", :admin do
end end
scenario "Search" do scenario "Search" do
booth = create(:poll_booth) create(:poll_booth, name: "Consulting Detective", location: "221B Baker Street")
create(:poll_booth, name: "World's Greatest Detective", location: "Gotham")
visit admin_booths_path visit admin_booths_path
fill_in "search", with: booth.name expect(page).to have_css ".booth", count: 2
click_button "Search"
expect(page).to have_css(".booth", count: 1)
fill_in "search", with: booth.location fill_in "search", with: "Consulting"
click_button "Search" click_button "Search"
expect(page).to have_css(".booth", count: 1) expect(page).not_to have_content "Greatest Detective"
expect(page).to have_content "Consulting Detective"
expect(page).to have_css ".booth", count: 1
fill_in "search", with: "Gotham"
click_button "Search"
expect(page).not_to have_content "Consulting Detective"
expect(page).to have_content "Greatest Detective"
expect(page).to have_css ".booth", count: 1
fill_in "search", with: "Wrong search criteria" fill_in "search", with: "Wrong search criteria"
click_button "Search" click_button "Search"

View File

@@ -87,7 +87,6 @@ describe "Admin edit translatable records", :admin do
expect(page).to have_content "Draft updated successfully" expect(page).to have_content "Draft updated successfully"
visit path
click_link class: "fullscreen-toggle" click_link class: "fullscreen-toggle"
expect(page).to have_field "Text", with: "Text in English" expect(page).to have_field "Text", with: "Text in English"
@@ -120,6 +119,9 @@ describe "Admin edit translatable records", :admin do
expect(page).to have_content "Question updated successfully" expect(page).to have_content "Question updated successfully"
visit path visit path
expect(page).not_to have_content "Question updated successfully"
select "Português brasileiro", from: "Language:" select "Português brasileiro", from: "Language:"
expect(page).to have_field "Questão", with: "Português" expect(page).to have_field "Questão", with: "Português"
@@ -338,8 +340,6 @@ describe "Admin edit translatable records", :admin do
expect(page).to have_content "Process updated successfully" expect(page).to have_content "Process updated successfully"
visit edit_admin_legislation_process_path(translatable)
expect_to_have_language_selected "Français" expect_to_have_language_selected "Français"
expect_not_to_have_language "English" expect_not_to_have_language "English"
end end
@@ -363,8 +363,8 @@ describe "Admin edit translatable records", :admin do
visit path visit path
expect(page).not_to have_select "Current language", with_options: ["Español"]
expect(page).to have_select "Current language", with_options: ["English"] expect(page).to have_select "Current language", with_options: ["English"]
expect(page).not_to have_select "Current language", with_options: ["Español"]
end end
end end

View File

@@ -27,14 +27,21 @@ describe "Executions" do
create(:milestone, milestoneable: investment1) create(:milestone, milestoneable: investment1)
visit budget_path(budget) visit budget_path(budget)
expect(page).not_to have_content(investment1.title)
click_link "See results" click_link "See results"
expect(page).to have_content(investment1.title)
expect(page).to have_content(investment2.title)
expect(page).to have_content(investment4.title)
click_link "Milestones" click_link "Milestones"
expect(page).to have_content(investment1.title)
expect(page).not_to have_content(investment2.title) expect(page).not_to have_content(investment2.title)
expect(page).not_to have_content(investment3.title) expect(page).not_to have_content(investment3.title)
expect(page).not_to have_content(investment4.title) expect(page).not_to have_content(investment4.title)
expect(page).to have_content(investment1.title)
end end
scenario "Do not display headings with no winning investments for selected status" do scenario "Do not display headings with no winning investments for selected status" do
@@ -56,11 +63,12 @@ describe "Executions" do
end end
scenario "Show message when there are no winning investments with the selected status" do scenario "Show message when there are no winning investments with the selected status" do
create(:milestone_status, name: I18n.t("seeds.budgets.statuses.executed")) create(:milestone, milestoneable: investment1)
create(:milestone_status, name: "Executed")
visit budget_executions_path(budget) visit budget_executions_path(budget)
expect(page).to have_content("No winner investments in this state") expect(page).not_to have_content("No winner investments in this state")
select "Executed (0)", from: "Project's current state" select "Executed (0)", from: "Project's current state"
click_button "Filter" click_button "Filter"
@@ -118,8 +126,8 @@ describe "Executions" do
select "Studying the project (1)", from: "Project's current state" select "Studying the project (1)", from: "Project's current state"
click_button "Filter" click_button "Filter"
expect(page).to have_content(investment1.title)
expect(page).not_to have_content(investment2.title) expect(page).not_to have_content(investment2.title)
expect(page).to have_content(investment1.title)
select "Bidding (1)", from: "Project's current state" select "Bidding (1)", from: "Project's current state"
click_button "Filter" click_button "Filter"
@@ -130,8 +138,8 @@ describe "Executions" do
select "Executing the project (0)", from: "Project's current state" select "Executing the project (0)", from: "Project's current state"
click_button "Filter" click_button "Filter"
expect(page).not_to have_content(investment1.title)
expect(page).not_to have_content(investment2.title) expect(page).not_to have_content(investment2.title)
expect(page).not_to have_content(investment1.title)
end end
scenario "are based on latest milestone status" do scenario "are based on latest milestone status" do
@@ -145,15 +153,17 @@ describe "Executions" do
visit budget_executions_path(budget) visit budget_executions_path(budget)
expect(page).to have_content investment1.title
select "Studying the project (0)", from: "Project's current state" select "Studying the project (0)", from: "Project's current state"
click_button "Filter" click_button "Filter"
expect(page).not_to have_content(investment1.title) expect(page).not_to have_content investment1.title
select "Bidding (1)", from: "Project's current state" select "Bidding (1)", from: "Project's current state"
click_button "Filter" click_button "Filter"
expect(page).to have_content(investment1.title) expect(page).to have_content investment1.title
end end
scenario "milestones with future dates are not shown" do scenario "milestones with future dates are not shown" do
@@ -167,15 +177,17 @@ describe "Executions" do
visit budget_executions_path(budget) visit budget_executions_path(budget)
select "Studying the project (1)", from: "Project's current state" expect(page).to have_content investment1.title
click_button "Filter"
expect(page).to have_content(investment1.title)
select "Bidding (0)", from: "Project's current state" select "Bidding (0)", from: "Project's current state"
click_button "Filter" click_button "Filter"
expect(page).not_to have_content(investment1.title) expect(page).not_to have_content investment1.title
select "Studying the project (1)", from: "Project's current state"
click_button "Filter"
expect(page).to have_content investment1.title
end end
scenario "by milestone tag, only display tags for winner investments" do scenario "by milestone tag, only display tags for winner investments" do
@@ -198,26 +210,26 @@ describe "Executions" do
select "Studying the project (1)", from: "Project's current state" select "Studying the project (1)", from: "Project's current state"
click_button "Filter" click_button "Filter"
expect(page).to have_content(investment1.title)
expect(page).not_to have_content(investment2.title) expect(page).not_to have_content(investment2.title)
expect(page).to have_content(investment1.title)
select "Bidding (1)", from: "Project's current state" select "Bidding (1)", from: "Project's current state"
click_button "Filter" click_button "Filter"
expect(page).not_to have_content(investment1.title)
expect(page).to have_content(investment2.title) expect(page).to have_content(investment2.title)
expect(page).not_to have_content(investment1.title)
select "tag1 (1)", from: "Milestone tag" select "tag1 (1)", from: "Milestone tag"
click_button "Filter" click_button "Filter"
expect(page).not_to have_content(investment1.title)
expect(page).not_to have_content(investment2.title) expect(page).not_to have_content(investment2.title)
expect(page).not_to have_content(investment1.title)
select "All (2)", from: "Milestone tag" select "All (2)", from: "Milestone tag"
click_button "Filter" click_button "Filter"
expect(page).not_to have_content(investment1.title)
expect(page).to have_content(investment2.title) expect(page).to have_content(investment2.title)
expect(page).not_to have_content(investment1.title)
end end
end end

View File

@@ -78,15 +78,14 @@ describe "Users" do
fill_in "document_verification_document_number", with: "12345678Z" fill_in "document_verification_document_number", with: "12345678Z"
click_button "Check document" click_button "Check document"
expect(page).not_to have_content "This user account is already verified."
expect(page).to have_content "This user can participate in the website with the following permissions" expect(page).to have_content "This user can participate in the website with the following permissions"
expect(page).not_to have_content "This user account is already verified."
click_link "Delete user" click_link "Delete user"
accept_confirm { click_button "Delete account" } accept_confirm { click_button "Delete account" }
expect(page).to have_content "User account deleted." expect(page).to have_content "User account deleted."
refresh
fill_in "document_verification_document_number", with: "12345678Z" fill_in "document_verification_document_number", with: "12345678Z"
click_button "Check document" click_button "Check document"

View File

@@ -34,16 +34,16 @@ describe "Moderate users" do
expect(page).not_to have_content(debate2.title) expect(page).not_to have_content(debate2.title)
expect(page).to have_content(debate3.title) expect(page).to have_content(debate3.title)
visit debate_path(debate3) click_link debate3.title
expect(page).to have_css "h1", exact_text: debate3.title
expect(page).not_to have_content(comment3.body) expect(page).not_to have_content(comment3.body)
click_link "Sign out" click_link "Sign out"
expect(page).to have_content "You have been signed out successfully" expect(page).to have_content "You have been signed out successfully"
visit root_path within("#notice") { click_button "Close" }
click_link "Sign in" click_link "Sign in"
fill_in "user_login", with: citizen.email fill_in "user_login", with: citizen.email
fill_in "user_password", with: citizen.password fill_in "user_password", with: citizen.password

View File

@@ -12,6 +12,9 @@ describe "Custom information texts", :admin do
expect(page).to have_content "Translation updated successfully" expect(page).to have_content "Translation updated successfully"
visit admin_site_customization_information_texts_path(tab: "proposals") visit admin_site_customization_information_texts_path(tab: "proposals")
expect(page).not_to have_content "Translation updated successfully"
fill_in "contents[content_#{proposal_key}]values[value_en]", with: "Custom help with proposals" fill_in "contents[content_#{proposal_key}]values[value_en]", with: "Custom help with proposals"
click_button "Save" click_button "Save"

View File

@@ -94,12 +94,9 @@ describe "Users" do
click_button "Enter" click_button "Enter"
expect(page).to have_content "You have been signed in successfully." expect(page).to have_content "You have been signed in successfully."
visit account_path
expect(page).to have_link "My content", href: user_path(u1) expect(page).to have_link "My content", href: user_path(u1)
visit "/" within("#notice") { click_button "Close" }
click_link "Sign out" click_link "Sign out"
expect(page).to have_content "You have been signed out successfully." expect(page).to have_content "You have been signed out successfully."
@@ -235,6 +232,8 @@ describe "Users" do
expect(page).to have_content "You have been signed out successfully" expect(page).to have_content "You have been signed out successfully"
visit "/" visit "/"
expect(page).not_to have_content "You have been signed out successfully"
expect_not_to_be_signed_in expect_not_to_be_signed_in
end end

View File

@@ -427,7 +427,9 @@ describe "Valuation budget investments" do
expect(page).to have_content investment.title expect(page).to have_content investment.title
click_link investment.title click_link investment.title
expect(page).to have_content("Valuation finished")
expect(page).to have_content "Investment preview"
expect(page).to have_content "Valuation finished"
end end
context "Reopen valuation" do context "Reopen valuation" do

View File

@@ -119,13 +119,19 @@ describe "Verify Letter" do
visit edit_letter_path visit edit_letter_path
6.times do 5.times do |n|
fill_in "verification_letter_email", with: user.email fill_in "Email", with: user.email
fill_in "verification_letter_password", with: user.password fill_in "Password", with: user.password
fill_in "verification_letter_verification_code", with: "1" fill_in "Code you received in letter", with: "1"
click_button "Verify my account" click_button "Verify my account"
expect(page).to have_field "Password", with: ""
expect(page).to have_content "Verification code incorrect"
end end
fill_in "Password", with: user.password
click_button "Verify my account"
expect(page).to have_content "You have reached the maximum number of attempts. Please try again later." expect(page).to have_content "You have reached the maximum number of attempts. Please try again later."
expect(page).to have_current_path(account_path) expect(page).to have_current_path(account_path)
end end

View File

@@ -128,6 +128,9 @@ describe "Residence" do
click_button "Verify residence" click_button "Verify residence"
expect(page).to have_content "The Census was unable to verify your information" expect(page).to have_content "The Census was unable to verify your information"
within("#error_explanation") { click_button "Close" }
expect(page).not_to have_content "The Census was unable to verify your information"
end end
click_button "Verify residence" click_button "Verify residence"