Skip to content

Visibility issue upon replacing hidden nodes (Race condition) #239

Open
@stevschmid

Description

@stevschmid

I noticed the following: If you replace hidden content of a hidden parent (e.g. using innerHTML) and then make the parent visible, Capybara intermittently picks up the old content.

I was able to create this very minimal HTML with the accompanying, random failing spec:

<!-- test.html -->
<button onclick="document.querySelector('#editor').style.display = 'none'">Hide</button>
<button onclick="setTimeout(() => { document.querySelector('#editor').innerHTML = '<textarea name=draft></textarea>'; document.querySelector('#editor').style.display = 'block'; }, 100);">Reset</button>

<div id=editor>
  <textarea name=draft></textarea>
</div>
# test.rb
scenario 'flaky spec' do
  visit '/test.html'
  click_on 'Hide'
  expect(page).not_to have_field('draft')
  click_on 'Reset'
  fill_in 'draft', with: 'World'
  expect(page).to have_field('draft', with: 'World')
end

Testing this multiple times using while bin/rspec spec/features/test.rb; do :; done leads quickly to

    Failure/Error: expect(page).to have_field('draft', with: 'World')
       expected to find field "draft" that is not disabled with value "World" but there were no matches. Also found "", which matched the selector but not all filters. Expected value to be "World" but was ""

Tested both with the most recent gem version as well as github master.

I will submit a PR with a potential fix.

Update: After further investigation, this seems to be an issue in Ferrum. I will open the PR there and reference this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions