I am trying to test a feature of my app in Ruby on Rails by Cucumber and Capybara: when you click "delete" button, there is a confirm says " Are you sure?" Then it is supposed to click "OK".
At first I simply tried
Given('I accept the popup') do
click_button('OK')
end
Then Cucumber throw an error:
Unable to find button "OK" (Capybara::ElementNotFound)
Then I tried:
Given('I accept the popup') do
page.driver.browser.switch_to.alert.accept
end
as mentioned in How to test a confirm dialog with Cucumber? Cucumber throw this error:
undefined method `switch_to' for #<Capybara::RackTest::Browser:0x0000000009241c20> (NoMethodError)
Then I tried add "@javascript" before my scenario in my 'test.feature' like:
@javascript
Scenario: Admin can manage scales
Given I am on Scales page
Given I destroy a scale
Given I accept the popup
Then I should see "Scale deleted"
Then Cucumber throw an error:
Unable to find Mozilla geckodriver. Please download the server from https://github.com/mozilla/geckodriver/releases and place it somewhere on your PATH. More info at https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver.
I'm so confused. Did I configure the environment wrong?
My Gemfile:
group :test do
gem 'shoulda-matchers'
gem 'simplecov', :require => false
gem 'rails-controller-testing', '1.0.2'
gem 'minitest-reporters', '1.1.14'
gem 'guard', '2.13.0'
gem 'guard-minitest', '2.4.4'
gem 'capybara'
gem 'launchy'
gem 'selenium-webdriver'
gem 'cucumber-rails', :require => false
gem 'cucumber-rails-training-wheels'
end
My web_steps.rb:
require 'uri'
require 'cgi'
require 'selenium-webdriver'