I am doing automation testing of a rails app. Using cucumber-rails gem, Poltergeist and Capybara gem.
I get following error's when I run a single scenario or a complete folder of scenarios.
Net::ReadTimeout (Net::ReadTimeout)
I often get Server out of reach error.
Before running a scenario I change my driver with below line
Capybara.current_driver = :poltergeist
A small example is below
Scenario: Mark asset as Sold on Assets Page for leader
Given javascript driver is changed
Given "company_admin" is login
And Create a group
Then logout from "Company Admin"
I usually get error on company admin is login line.
Can anyone please help in fixing this error
below are the testing gems I am currently using or have in my gemfile.
group :development, :test do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'rails_dt'
gem 'spring'
gem 'dotenv-rails'
gem 'pry-rails'
gem 'cucumber-rails', :require => false
gem 'selenium-webdriver'
gem "chromedriver-helper"
# Pry navigation commands via byebug
gem 'pry-byebug'
gem 'factory_girl_rails', '~> 4.0' # easy fixtures
gem 'rspec-rails', '~> 3.0' # better unit testing
gem 'capybara'
gem 'capybara-screenshot'
gem 'rspec-activejob'
gem 'poltergeist'
gem 'valid_attribute' # concise validation testing
gem 'database_cleaner'
gem 'whiny_validation'
end
I just want to get my cucumber test to accept a confirm dialogue, with my cucumber test, I've installed selenium-webdriver and it gives me this error:
unable to obtain stable firefox connection in 60 seconds (127.0.0.1:7055) (Selenium::WebDriver::Error::WebDriverError)
I tried running gem update selenium-webdriver, and that didn't work.
Here is my the feature file:
Feature: Delete User
In order to remove an exisiting user
As a user
I want to be able to remove a user from the database
Scenario: User successfully deletes another user
Given I am currently on the Users page
When I select a user to delete
Then the user should no longer visible on the users page
Here is relevant part of the steps file:
Feature: Delete User, Scenario: User successfully deletes another user
When /^I select a user to delete js: true$/ do
page.evaluate_script('window.confirm = function() { return true; }')
find(:xpath, "//a[#href='/users/2?page=1' and #data-confirm='Are you sure?']").click
end
Then /^the user should no longer visible on the users page$/ do
expect(page).to have_no_content "cwl0#aber.ac.uk"
end
Here is the env.rb file:
require 'cucumber/rails'
require 'selenium-webdriver'
Dir["../../spec/factories/*.rb"].each {|file| require_relative file }
ActionController::Base.allow_rescue = false
Remove/comment out the lines below if your app doesn't have a database.
For some databases (like MongoDB and CouchDB) you may need to use :truncation instead.
begin
DatabaseCleaner.strategy = :transaction
rescue NameError
raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end
Before do
DatabaseCleaner.start
load Rails.root.join('db/seeds.rb')
end
After do |scenario|
DatabaseCleaner.clean
end
Cucumber::Rails::Database.javascript_strategy = :truncation
And here is the gemfile:
source 'https://rubygems.org'
gem 'thin'
gem 'paperclip', '~> 4.1'
gem 'simple-navigation'
gem 'will_paginate', '~> 3.0'
Required by Windows and some Linux platforms when running with Rails 4.1.5!
gem 'tzinfo-data'
Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.5'
Use sqlite3 as the database for Active Record
gem 'sqlite3'
Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
gem 'oauth', '~>0.4.6'
See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', platforms: :ruby
Use jquery as the JavaScript library
gem "jquery-rails", "~> 2.3.0"
gem 'jquery-ui-rails', '4.1.2'
Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
group :test do
gem 'cucumber-rails', :require => false
gem 'launchy'
gem 'database_cleaner'
gem 'selenium-webdriver', "~> 2.38.0"
gem 'rspec-rails', '~> 3.0.0'
gem 'factory_girl_rails'
end
Please can someone suggest the best way of testing this feature, which allows me to accept the confirm dialogue?
Check the version of selenium-webdriver that you are using compared to your version of Firefox for compatibility and make the appropriate version change in your gemfile.lock file. https://selenium.googlecode.com/git/rb/CHANGES
Older Firefox versions can be found here
https://ftp.mozilla.org/pub/mozilla.org/firefox/releases/
In your Gemfile have the following:
group :test do
gem "capybara"
# selenium webdriver is a dependency of Capybara. However it needs updating
# much more frequently to keep up with firefox. Including it in the Gemfile
# allows us to run 'bundle update selenium-webdriver' when this happens.
gem 'selenium-webdriver'
end
Then follow the instructions in the comment i.e. run
bundle update selenium-webdriver
This is the first time, I'm trying BDD and testing, I'm trying things by seeing tutorials and my problem is I found that guard is looking for spec folder as defined in its guard file,
but there is no spec folder, I have test folder instead.
when I run
guard
it tries to load spec folder but there is no spec folder. is it okay to edit the guard file to look for test folder instead of spec folder?
Am I supposed to do rspec install?
rails g rspec install
Could not find generator rspec.
my gem file
source 'https://rubygems.org'
gem 'rails', path: '/home/phanindra/rails'
gem 'journey', git: 'https://github.com/rails/journey.git'
gem 'arel', git: 'https://github.com/rails/arel'
gem 'activerecord-deprecated_finders', git: 'https://github.com/rails/activerecord-deprecated_finders'
gem 'sqlite3'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sprockets-rails', git: 'https://github.com/rails/sprockets-rails'
gem 'sass-rails', git: 'https://github.com/rails/sass-rails'
gem 'coffee-rails', git: 'https://github.com/rails/coffee-rails'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', platforms: :ruby
gem 'uglifier', '>= 1.0.3'
end
gem 'rb-inotify', '~> 0.8.8'
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
group :test, :development do
gem 'cucumber-rails', :require => false
gem 'database_cleaner'
gem 'rspec'
gem 'spork'
gem 'guard'
gem 'guard-rspec'
gem 'launchy'
end
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano', group: :development
# To use debugger
# gem 'debugger'
my guard file
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
guard 'rspec' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
# Rails example
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
# Capybara features specs
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
# Turnip features and steps
watch(%r{^spec/acceptance/(.+)\.feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
end
by following the answer on Could not find generator rspec:install.
I have added rspec-rails to my gem file and did bundle install, then rspec generator worked and it generated spec folder.
But it does not have any folders like fixtures or acceptance or functional etc in test folder!!
according to the official document(https://github.com/rspec/rspec-rails#install), I think you should run :
# not: rails g rspec install
rails generate rspec:install
to generate the "spec" folder and "spec/spec_helper.rb" file and other related stuff.
Try adding the Rails Rspec gem to your gem file:
group :development do
gem 'rspec-rails'
end
run bundle install then rails generate rspec:install
I've been self-learning developing rails plugin.
One referenced tutorial I'm using is here.
Unfortunately, it seemed I got stuck since the first step when I run "rails generate plugin. It's returning an error saying "rspec [not found]".
c:\rails\test\rails generate plugin HelloWorld
create vendor/plugins/hello_world
create vendor/plugins/hello_world/MIT-LICENSE
create vendor/plugins/hello_world/README
create vendor/plugins/hello_world/Rakefile
create vendor/plugins/hello_world/init.rb
create vendor/plugins/hello_world/install.rb
create vendor/plugins/hello_world/uninstall.rb
create vendor/plugins/hello_world/lib
create vendor/plugins/hello_world/lib/hello_world.rb
error rspec [not found]
I tried to look for possible solutions myself. One that I tried was making an update of the project's bundler gem in hope that might come from a bug of plugin compatibility.
anyway, just in case it would help give you guys some clue on where it could go wrong, I also post my GemFile as follows.
source 'http://rubygems.org'
gem 'rails', '3.1.1'
gem 'annotate', ">=2.5.0"
gem 'sqlite3'
gem 'faker', '0.3.1'
gem 'gravatar_image_tag', '1.0.0.pre2'
gem 'will_paginate', '3.0.pre2'
gem 'jquery-rails'
gem 'pg', '0.14.0'
gem 'bundler', '1.2.0.rc.2'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
group :development do
gem 'rspec-rails', '2.6.1'
end
group :test do
gem 'rspec-rails', '2.6.1'
gem 'webrat', '0.7.1'
gem 'factory_girl_rails', '1.0'
end
Any advice would be really appreciated!
I think it's trying to generate template rspec examples for the plugin, but the rspec directory isn't there. Did you run the rspec installer (rails g rspec:install) after adding rspec to your Gemfile?
A lot of the guides I've been finding don't use bundler.
this is the part of the gemfile I'm using for tests:
group :test do
gem "cucumber"
gem "cucumber-rails"
gem "launchy"
gem "hpricot"
gem "gherkin"
gem "capybara"
gem "rspec"
gem "rack"
gem "rspec-rails"
gem "webrat"
gem "database_cleaner"
gem "factory_girl"
gem "shoulda", :require => nil
gem "shoulda-matchers", :git => "https://github.com/thoughtbot/shoulda-matchers"
gem "cobravsmongoose"
gem "rcov"
gem "ZenTest"
gem "autotest-growl"
gem "inherited_resources", "1.0.2"
gem "responders", "0.4.2"
end
But even with all that, the generators never exist.
so doing: script/generate rspec
doesn't work, (can't find the rspec) generator
generators would be installed if the gems were installed as plugins... but I think that just adds bloat to the app, and different gems compile differently on different OSes.
So, anyone have any guides for setting up rspec with bundler with rails 2.3.x?
Setting up RSpec, Guard, and Spork on a Rails 2 project
I've done this a few times now; hopefully this will be helpful to anyone needing to maintain Rails 2.3 apps. This has worked great for the apps I've worked on, but I welcome contributions from others who suggest additional steps.
This guide assumes a Rails 2.3.x project on Bundler
Get rid of any old rspec plugins that are in your project, if any. RSpec bits may be hiding in:
Rakefile
lib/tasks/rspec.rake
vendor/plugins/rspec
(anything else you can find)
RSpec 2 is not compatible with Rails 2; use RSpec 1 (docs). Put the most recent compatible gem versions to your Gemfile:
group :test, :development do
gem 'test-unit', '1.2.3', :require => false # for rspec
gem 'rspec', '~> 1.2', :require => false
gem 'rspec-rails', '~> 1.2', :require => false
gem 'guard', :require => false
gem 'spork', '~> 0.8.0', :require => false
gem 'guard-rspec', :require => false
gem 'guard-spork', :require => false
gem 'growl', :require => false # notifications; optional
gem 'rb-fsevent', :require => false # for OSX; optional
gem 'listen', '>= 0.5.1', :require => false
gem 'machinist', '~> 2.0', :require => false
gem 'database_cleaner', '~> 0.9.1', :require => false
end
The :require => false options are optional, but it helps the app to start up faster in development if it doesn't have to load testing libraries outside of when SpecHelper.rb requires them.
Install the bundle. Use bundle update for any gems that were already in your Gemfile.
Ensure lib/tasks/rspec.rake and spec/spec_helper.rb do not exist.
script/generate rspec
Remove the config.gem line that was added to config/environments/test.rb; the app uses bundler.
spork --bootstrap
Then edit spec/spec_helper.rb and follow the instructions.
Move everything from the stock spec_helper.rb into the prefork block, except:
Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
belongs in each_run.
Install database_cleaner. In spec/spec_helper.rb,
In the prefork block:
require 'database_cleaner'
In the each_run block:
DatabaseCleaner.clean
Initialize Guardfile
guard init spork
guard init rspec
Modify the Guardfile's rspec guard to use the correct version and drb (spork):
guard 'rspec', :version => 1, :cli => '--drb --color' do
Modify the Guardfile as appropriate for your project
Run rake spec. You should get no output (if you have no tests). If you get errors, resolve them.
Run guard. No errors? Great, test away!
Problems? Try again more quickly by running spec spec instead of re-running guard.
We still have an app on rails 2.3.8, but we updated it to use bundler (Gemfile), and it has rspec and cucumber working as well.
Make sure you follow the bundler guide to make your app correctly use the Gemfile's gem loading instead of Rails' default: http://gembundler.com/rails23.html
After you get that preinitializer.rb and change the config/boot.rb working correctly, you might need to make sure you're using the right versions of rspec and cucumber.
I think just that generic gem 'rspec-rails' might try installing rspec 2 for you, but that only works on Rails 3 (I believe), so you might need to specifically tell it to use rspec 1.x.
Our test group looks like this (although I think some of these gems may be older than they need to be, it's been awhile since we've updated them since a rails 3 upgrade for the app is pending we're not too worried about what it looks like right now):
group :test, :cucumber do
gem 'autotest-fsevent'
gem 'test-unit', '~>1.2.3'
gem "hoe", "1.5.1"
gem 'autotest-rails', '4.1.0'
gem 'rspec', '1.3.2'
gem 'rspec-rails', '1.3.4'
gem 'cucumber', '0.10.0'#, '0.9.0'
# Change this shinanigans to 0.4.0 when it gets released ;)
gem 'cucumber-rails', '0.3.2'
gem 'database_cleaner', '0.5.2'
gem 'capybara', '0.3.9'
gem 'launchy'
gem 'dupe', '0.5.1'
gem 'factory_girl', '1.2.4'
gem 'email_spec', '~>0.6.2', :require => false
end
After doing this, and running bundle install, I am able to type the command script/generate --help which includes this in the output:
Installed Generators
Rubygems: business_time_config, cucumber, culerity, dupe, email_spec, feature, integration_spec, paperclip, rspec, rspec_controller, rspec_model, rspec_scaffold
Builtin: controller, helper, integration_test, mailer, metal, migration, model, observer, performance_test, plugin, resource, scaffold, session_migration
As you can see, the cucumber and rspec generators are in fact available there.
I think your problem might be the version of rspec it's installing. If it's installing rspec version 2, then that is tied to rails 3, which handles generators in gems differently I believe (I believe they have to be put in a different directory structure). That could be why your rails 2.3.x app isn't seeing them.
You don't have to follow my versions exactly, I'm not a fan (at all) of putting specific versions in a Gemfile but we ended up doing it here way back when because a) we didn't fully understand bundler, and b) We needed to make sure we were getting rails 2.3-compatible gems.
Hopefully this helps! Let me know if you have questions.
The reason the generators don't exist is that when you run rails generate ..., it's executing in the development environment while these gems are only loaded in the test environment.
Option 1
Add them to both development and test environments.
Option 2
Run rails generate ... RAILS_ENV=test
(I'm not positive that this option will work.)
In rails 5.1.4 you there are four easy steps to get your RSpec up and running:
group :development, :test do
gem "database_cleaner"
gem "rspec-rails"
end
Add the above gems to the :test and :development groups in your Gemfile.
run bundle install from the command line
run rails generate rspec:install from the command line, it will create the following files:
create .rspec
create spec
create spec/spec_helper.rb
create spec/rails_helper.rb
configure spec_helper.rb and rails_helper.rb
You can check more detailed info on: https://kolosek.com/rails-rspec-setup.