Currently, I am utilizing Sinatra and my testing environment is structured in the following manner.
Gemfile:
gem 'rspec'
gem 'capybara'
gem 'pry'
gem 'selenium-webdriver'
spec_helper.rb
require 'view_helpers'
require 'capybara/rspec'
require 'rspec'
require 'selenium-webdriver'
Capybara.javascript_driver = :selenium
staticpages_integration_test.rb
require 'capybara/rspec'
require './app'
Capybara.app = Sinatra::Application
set :show_exceptions, false
...
describe 'ensuring the home page does not contain javascript errors', {:type => :feature } do
# Activating Selenium for JavaScript assessment
before :all do
Capybara.current_driver = :selenium
visit '/'
end
it 'the home page should run scripts without error', :js => true do
expect(page).not_to have_errors
end
# Disabling Selenium for regular testing
after :all do
Capybara.use_default_driver
end
end
The remaining tests are loading properly and Selenium is executing while opening the Firefox browser. However, an error message is displayed as follows:
Failure/Error: expect(page).not_to have_errors
expected #<Capybara::Session:0x007f8146be1e90> to respond to `has_errors?`
I am seeking assistance in resolving this issue. I have attempted using error_message as a method as well, but it appears that Selenium is either not operating or lacks access to these methods. Could there be a missing dependency causing this problem? Your help is appreciated.
Alternatively, if there is a more efficient way to test for JavaScript errors, I would greatly appreciate any suggestions.