I am trying to run test features."bundle exec cucumber features" starts failing abnormally(during login itself),it fails to recognize an existing user. while it works fine if i run individual feature files. What am i doing wrong?
Gem File:
group :test do
gem 'ruby-prof'
gem 'cucumber-rails', :require => false
gem 'cucumber'
gem 'spork'
gem 'launchy'
gem 'capybara'
gem 'selenium-webdriver'
gem 'selenium-client'
gem 'database_cleaner'
gem 'email_spec', :branch=>'rails3'
end
In env.rb
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
Related
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
In cucumber, my seed data is loaded up via several rake tasks. None of which are working:
Spree::Core::Engine.load_seed if defined?(Spree::Core)
Spree::Auth::Engine.load_seed if defined?(Spree::Auth)
Rake::Task['alchemy:db:seed'].invoke
When I run one of spree's rake tasks I get:
Don't know how to build task 'db:load_dir' (RuntimeError)
When I run one of alchemy's rake tasks I get:
Don't know how to build task 'alchemy:db:seed' (RuntimeError)
The testing database exists. I have ran rake db:test:prepare and it appears to be setup from my inspections. Lets move onto the hooks:
# features/support/hooks.rb
Before do
load File.join(Rails.root, 'db', 'seeds.rb')
end
This goes to the root and gets me the seed data. I decided to try this:
# features/support/hooks.rb
before do
# load File.join(Rails.root, 'db', 'seeds.rb')
Rake::Task['alchemy:db:seed'].invoke
end
The error was:
Don't know how to build task 'alchemy:db:seed' (RuntimeError)
I'm unable to figure out why the rake tasks are not working in cucumber.
My Gemfile is as follows:
source 'https://rubygems.org'
ruby '2.1.2'
gem 'rails', '4.0.6'
gem 'pg'
gem 'redis-rails'
gem 'redis-rack-cache'
gem 'sass-rails', '~> 4.0.3'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'thin'
gem 'durable_decorator_rails', github: 'jumph4x/durable_decorator_rails'
gem 'newrelic_rpm'
gem 'rake'
gem 'spree', '2.2.2'
gem 'spree_gateway', github: 'spree/spree_gateway', branch: '2-2-stable'
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-2-stable'
gem 'spree_bootstrap_frontend', github: '200Creative/spree_bootstrap_frontend', branch: '2-2-stable'
gem 'alchemy_cms', github: 'magiclabs/alchemy_cms'
gem 'spree_alchemy', github: 'tesserakt/spree_alchemy'
group :doc do
gem 'sdoc', '~> 0.4.0'
end
group :development do
gem 'better_errors'
gem 'binding_of_caller'
gem 'meta_request'
end
group :test do
gem 'simplecov', require: false
gem 'cucumber-rails', require: false
gem "cucumber-websteps"
gem 'database_cleaner'
gem "selenium-webdriver"
gem "capybara-webkit"
end
group :development, :test do
gem "factory_girl_rails", "~> 4.0"
gem "rspec-rails"
gem 'rspec-its'
gem 'shoulda-matchers', require: false
end
And this is my env support file:
# features/support/env.rb
require 'cucumber/rails'
ActionController::Base.allow_rescue = false
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
Cucumber::Rails::Database.javascript_strategy = :truncation
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(app, browser: :chrome)
end
Capybara.javascript_driver = :chrome
Rake doesn't load tasks by default, you can check for yourself:
irb(main):002:0> require 'rake'
=> true
irb(main):003:0> Rake::Task.tasks
=> []
So it doesn't "know" how to run your task. You need to tell Rails to load them:
Rails.application.load_tasks
Spree::Core::Engine.load_seed if defined?(Spree::Core)
Spree::Auth::Engine.load_seed if defined?(Spree::Auth)
It seems that the test database is missing. So as already written in the comment above, the solution is to create the database and run the migrations with
RAILS_ENV=test rake db:setup
Happy to help :)
I really like Miniskirt and Minitest but I am having issues loading the factories.rb file on each run using spork server. It goes:
cannot load such file -- factories (LoadError)
My factories.rb file is located in the /test directory along with my test_helper.rb.
Any tips would be appreciated.
require 'rubygems'
require 'spork'
Spork.prefork do
...
require 'factories'
end
It took me a little trial and error to get everything to work, but I fixed it by switching to spork-minitest and using the master branch of guard-minitest. Here's my test suite:
group :test, :development do
gem 'capybara'
gem 'database_cleaner'
gem 'awesome_print'
gem 'turn'
gem 'guard'
gem 'guard-spork'
gem 'guard-minitest', github: 'guard/guard-minitest'
gem 'guard-livereload'
gem 'terminal-notifier-guard'
gem 'capybara_minitest_spec'
gem 'rb-fsevent', '~> 0.9.1'
gem "spork-minitest", git: "https://github.com/semaperepelitsa/spork-minitest.git"
gem 'miniskirt'
gem 'minitest-spec-rails'
end
Thanks for the help anyway.
when I toggle :js => true on my examples, takes too long very long to come up and run the first test, then becomes acceptable peformance
this sample running in 0.36722 seconds without :js, and 58.15 seconds with :js => true
require 'spec_helper'
include UserAbilitiesHelper
describe "Customer Task Pages" do
subject { page }
describe "side panel with the history of the tasks related to customer" do
before do
visit root_path()
end
it { sould have_content(I18n.t("customers.tasks.side.title")) }
end
describe "side panel with the history of the tasks related to customer" do
before do
visit root_path()
end
it { sould have_content(I18n.t("customers.tasks.side.title")) }
end
end
my Gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.5'
gem 'pg', '0.12.2'
gem "meta_search"
# Bootstrap and layouting
gem 'bootstrap-sass', '2.0.3'
gem 'will_paginate', '3.0.3'
gem 'bootstrap-will_paginate', '0.0.6'
gem 'rails3-jquery-autocomplete'
#test support
gem 'faker', '1.0.1'
#login rules
gem 'devise'
gem 'cancan'
#criptar
gem 'bcrypt-ruby', '3.0.1'
#BR
gem 'brazilian-rails'
gem 'rails-i18n'
group :development do
gem 'annotate', '~> 2.4.1.beta'
gem 'nested_scaffold'
end
group :development, :test do
gem 'rspec-rails', '2.10.0'
gem 'guard-rspec', '0.5.5'
gem 'guard-spork', '0.3.2'
gem 'spork', '0.9.0'
gem 'ruby-debug19'
gem 'linecache19'
gem 'factory_girl_rails', '1.4.0'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '3.2.4'
gem 'coffee-rails', '3.2.2'
gem 'uglifier', '1.2.3'
end
gem 'jquery-rails', '2.0.0'
group :test do
gem 'capybara', '1.1.2'
gem "launchy"
gem 'ZenTest'
#MAC OS Especific
gem 'rb-fsevent', '0.4.3.1', :require => false
gem 'growl', '1.0.3'
#Cucumber
gem 'cucumber-rails', '1.2.1', require: false
gem 'database_cleaner', '0.7.0'
end
group :production do
#gem 'pg', '0.12.2'
end
running with
bundle exec rspec
An example any
Bruno-Guerras-MacBook-Pro:railstutorial brunoguerra$ bundle exec rspec spec/requests/authentication_pages_spec.rb
No DRb server is running. Running in local process instead ...
WARNING: Nokogiri was built against LibXML version 2.7.8, but has dynamically loaded 2.7.3
.....................
Finished in 6.07 seconds
21 examples, 0 failures
Bruno-Guerras-MacBook-Pro:railstutorial brunoguerra$ bundle exec rspec spec/requests/authentication_pages_spec.rb
No DRb server is running. Running in local process instead ...
WARNING: Nokogiri was built against LibXML version 2.7.8, but has dynamically loaded 2.7.3
............F........
Failures:
1) Authentication authorization for non-signed-in users when attempting to visit a protected page after signing in should render the desired protected page
Failure/Error: page.should have_selector('title', text: 'Edit user')
expected css "title" with text "Edit user" to return something
# ./spec/requests/authentication_pages_spec.rb:65:in `block (6 levels) in <top (required)>'
Finished in 1 minute 14.18 seconds
21 examples, 1 failure
Failed examples:
rspec ./spec/requests/authentication_pages_spec.rb:64 # Authentication authorization for non-signed-in users when attempting to visit a protected page after signing in should render the desired protected page
Bruno-Guerras-MacBook-Pro:railstutorial brunoguerra$
thanks
I discovery, my dns server is too slow, I changed my dns server and the problem solved, another thing I did to improve the speed of testing was to configure these parameters webrick
configure webrik speedup but, its solve the same problem, DNS server! urgh!!!
You can also try changing the driver :webkit_debug and then rerun your specs to see any if there are any scripts that don't need to be loaded on the page.
Capybara.javascript_driver = :webkit_debug
Then add any urls to the black list
config.before(:each, js: true) do
page.driver.browser.url_blacklist = ["http://use.typekit.net"]
end