Skip to content

Commit 96fbf32

Browse files
committed
Fix Playwright selectors for Choices.js combobox
The govuk_publishing_components v65.1.1 gem includes an upgrade of Choices.js from v11.1.0 to v11.2.1. Choices.js v11.2.0 introduced an ARIA accessibility fix (Choices-js/Choices#1330) that changes how elements are exposed in the accessibility tree. This caused Playwright's get_by_role() queries to match multiple elements: - get_by_role('combobox') matched both the hidden <select> and the visible Choices.js wrapper <div> - get_by_role('option') matched both the hidden <option> elements and the visible Choices.js dropdown items The fix uses CSS locators to target only the visible Choices.js elements: - div.choices[role='combobox'] for the combobox wrapper - .choices__list--dropdown [role='option'] for dropdown options Note: to reproduce CI failures locally, assets must be precompiled: rm -rf tmp/cache public/assets RAILS_ENV=test bundle exec rails assets:precompile bundle exec cucumber
1 parent ea21f7d commit 96fbf32

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

features/support/helpers.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,9 @@ def select_organisation(organisation)
8888
@organisation = organisation
8989
if Capybara.current_session.driver.is_a?(Capybara::Playwright::Driver)
9090
Capybara.current_session.driver.with_playwright_page do |page|
91-
combobox = page.get_by_role("combobox", name: "Lead organisation")
91+
combobox = page.locator("div.choices[role='combobox']")
9292
combobox.click
93-
listbox = combobox.locator(".choices__list").get_by_role("listbox")
94-
listbox.get_by_role("option", name: organisation.name).click
93+
combobox.locator(".choices__list--dropdown [role='option']", hasText: organisation.name).click
9594
end
9695
else
9796
select organisation.name, from: "edition_lead_organisation_id"

0 commit comments

Comments
 (0)