3

I am writing tests to test that both affirming and dismissing a conformation popup work. However, I get the error:

And I dismiss popup                                     # features/step_definitions/web_steps.rb:74
  undefined method `switch_to' for #<Capybara::RackTest::Browser:0xa6f0dec> (NoMethodError)
  ./features/step_definitions/web_steps.rb:75:in `/^I confirm popup$/'
  features/add_session.feature:121:in `And I confirm popup'

when running my tests.

The steps in my .features files look something like this:

And I press "Delete"
And I confirm popup

Within web_steps.rb, I have the following defined:

When /^I confirm popup$/ do
  #page.evaluate_script('window.confirm = function() { return true; }')
  #page.click('OK')
  page.driver.browser.switch_to.alert.accept
  #popup.confirm 
end

When /^I dismiss popup$/ do
  page.driver.browser.switch_to.alert.dismiss
  #page.evaluate_script('window.confirm = function() { return true; }')
  #page.click('Cancel')
  #popup.dismiss
end

I am using the prickle gem which I have included as follows in my Gemfile:

group :test do
  gem 'cucumber-rails'
  gem 'prickle'
end

And I added a couple lines to my Gemfile as outlined here to include prickle. I initially had it as World do, like they show on the github page, but that was giving me errors since World was being used twice (the other time in the cucumber library). Here are the lines I added to my env.rb file:

require 'prickle/capybara'    # require

module Prickle_helper
  include Capybara::DSL
  include Prickle::Capybara  # include  Prickle
end

World(Prickle_helper)

Any ideas as to what could be causing my errors? Thanks!

user1253952
  • 1,577
  • 8
  • 22
  • 34

1 Answers1

0

I was omitting the @javascript before the methods that I wanted to use selenium on. For example:

@javascript
Scenario: Delete the class
  Given I am on the home page
  And I press "Delete"
  And I confirm popup
  Then I am on the homepage
  And I should not see the deleted class
user1253952
  • 1,577
  • 8
  • 22
  • 34