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
Related
Rails.application.initialize! command in environment.rb loads the files including route.rb twice when executing test using rspec. It works when executing it in production environment and route file is loaded exactly once. What may be the issue. I am using gemset
group :development,:test do
gem "rails-erd"
gem 'letter_opener'
gem 'spring'
gem 'faker'
gem 'pry-rails'
gem 'pry-byebug'
gem 'rspec-rails'
gem 'factory_girl_rails'
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
I am new to Rails development. I am following Michael Hartl's video tutorials. However I am not able to run the tests using Capybara/RSpec. I am getting some errors. My setup is as follows:
I am using Ruby 2.0.0p353.
Rails - 4.1.1 and
RSpec - 3.0.1
Capybara - 2.3.0
Below is my GemFile.
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
ruby '2.0.0'
gem 'rails', '4.1.1'
gem 'bootstrap-sass'
gem 'bcrypt'
gem 'faker'
gem 'will_paginate'
gem 'bootstrap-will_paginate'
gem 'rails_12factor'
# Use sqlite3 as the database for Active Record
group :development, :test do
gem 'sqlite3'
gem 'rspec-rails'
gem 'guard-rspec'
gem 'guard-spork'
gem 'childprocess'
gem 'spork'
end
#Gems used only for assets and not used in production enviornment by default
group :assets do
# 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'
end
group :test do
gem 'capybara'
gem 'factory_girl_rails'
gem 'cucumber-rails'
gem 'database_cleaner'
#gem 'launchy'
#gem 'rb-fsevent'
#gem 'growl'
end
group :production do
gem 'pg'
end
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# 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', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring', group: :development
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
Below is my spec/spec_helper.rb:
require 'capybara/rspec'
RSpec.configure do |config|
config.include Capybara::DSL
end
And, here is my spec. test - spec/features/static_pages_spec.rb
require 'spec_helper'
describe "Static pages" do
describe "Home page" do
it "should have the content 'Sample App'" do
visit '/static_pages/home'
page.should have_content('Sample App')
end
end
end
If I run the command rspec/featues/static_pages_spec.rb I get a long stack trace. It shows two main issues:
/usr/local/share/ruby/site_ruby/rubygems/core_ext/kernel_require.rb:73:
warning: loading in progress, **circular require considered harmful -
/home/MAC/.gem/ruby/gems/capybara-2.3.0/lib/capybara.rb**
and
An error occurred in an after hook
**ArgumentError: rack-test requires a rack application, but none was given**
occurred at /home/MAC/.gem/ruby/gems/capybara-2.3.0/lib/capybara/rack_test/driver.rb:16:in `initialize'
F
Failures:
1) Static pages Home page should have the content 'Sample App'
Failure/Error: visit '/static_pages/home'
ArgumentError:
**rack-test requires a rack application, but none was given**
# ./spec/features/static_pages_spec.rb:10:in `block (3 levels) in <top (required)>'
Finished in 0.00062 seconds (files took 0.58874 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./spec/features/static_pages_spec.rb:8 # Static pages Home page should have the content 'Sample App'
I have tried googling for this issue. It seems Capybara 2.3.0 and RSpec 3.0.1 do not play nicely. However I haven't found any solution which solves the issue. Has anyone encountered and solved such an issue? Please let me know. Thanks in advance.
rspec-rails 3 no longer defaults to setting the spec type based on the location, so your spec isn't being setup as a feature spec
You can either tag the feature specs individually or add
config.infer_spec_type_from_file_location!
To your spec helper to restore the old behaviour
Trying to upgrade from 2.14.2,to rspec 3.x get deprication messages
The `:example_group` key in an example group's metadata hash is deprecated. Use the example group's hash directly for the computed keys and `:parent_example_group` to access the parent example group metadata instead. Called from /home/georgi/ruby/xxx/spec/models/user_spec.rb:2:in `<top (required)>'.
This message is showed for every line in spec file that have 'describe'. Gems that i use in test env is
group :development, :test do
gem 'rspec-rails'
end
group :test do
gem 'factory_girl_rails'
gem 'database_cleaner'
gem 'capybara'
gem 'poltergeist'
gem 'selenium-webdriver', '~> 2.42.0'
gem 'shoulda-matchers'
gem 'rspec-retry'
gem 'simplecov'
end
Information from config.raise_errors_for_deprecations! configuration:
https://gist.github.com/tapalilov/b96b4e2f4237e2ecef84
How to remove these deprecation messages and how to change rspec configuration?
Best regards,
Georgi.
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