Skip to content

Work around to Capybara webdriver visibility to "select" fields

Patrick Bolger edited this page Oct 25, 2017 · 6 revisions

As of October, 2017, we have had to stop using poltergeist as a cucumber test driver because it was raising an exception with the HIPS javascript code. This is almost certainly due to an incomplete handling of new javascript features - in ECMAScript 6 - by PhantomJS (which is used by Poltergeist to handle javascript).

Generally, changing the driver to selenium (headless) worked fine. The one situation where it did not work was when there is a search form on the page, and we are testing the non-visibility of items due to selected search criteria. The problem is that selenium (headless or visible), as well as Firefox, "sees" the select option values in the search form.

For instance, this sequence of steps, from a feature testing companies search, worked fine with poltergeist:

Scenario: Search by region
  Given I am Logged out
  And I am on the "landing" page
  Then I select "Västerbotten" in select list t("activerecord.attributes.company.region")
  And I click on t("search")
  Then I should see "HappyMutts"
  And I should not see "Barky Boys"
  And I should not see "Dogs R Us"

but failed when using selenium, because company name (such as "Barky Boys") is a select option field in the search form.

The work-around is to hide the search form, which adds the display: none attribute to the form and thus makes the content not visible to the driver:

Scenario: Search by region
  Given I am Logged out
  And I am on the "landing" page
  Then I select "Västerbotten" in select list t("activerecord.attributes.company.region")
  And I click on t("search")
  Then I click on t("toggle.company_search_form.hide")
  Then I should see "HappyMutts"
  And I should not see "Barky Boys"
  And I should not see "Dogs R Us"
Clone this wiki locally