vendredi 8 avril 2016

How to interact with Bootstrap Popover using Capybara Rails?

I'm trying to test that pressing a button inserts a new record into the DB (Rails 5b3)

The button is in a bootstrap popover and function it runs works well. However, when I try to test it, I can't seem to target the element.

The content of the popover is not on the DOM by default, it's inserted and removed upon click of a button. This is the default behavior in Bootstrap v4

Here's my testing gem set:

  gem "rails-controller-testing", :git => "http://ift.tt/1IqGyF9"
  gem 'launchy'
  gem 'poltergeist'
  gem 'rspec', '~> 3.5.0.beta1'
  gem 'rspec-core', '~> 3.5.0.beta1'
  gem 'rspec-rails', '~> 3.5.0.beta1'
  gem 'guard-rspec', '~> 4.6', require: false
  gem 'capybara'
  gem 'factory_girl_rails'

Here's the relevant HTML inserted by the popover I'm trying to target:

<button data-js-method="createblock" class='btn btn-secondary btn-block'>Heading</button>

And here is my test:

scenario 'Popover#Heading' do
  before_count = HeadingBlock.count
  find('.btn-add-block').click

  # The line below is what I'm trying to target
  # click_button('Heading') doesn't work either
  find('button [data-js-method="createblock"]').click
  after_count = HeadingBlock.count

  expect(after_count - before_count).to eq(1)
end

Finally, the error:

Capybara::ElementNotFound:
       Unable to find css "button [data-js-method=\"createblock\"]"

Aucun commentaire:

Enregistrer un commentaire