capybara with :js => true very slow - ruby-on-rails

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

Related

Net::ReadTimeout Error While Testing Rails App using cucumber, poltergeist

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

Im getting error : No DRb server is running. Running in local process instead

I'm following the ROR tutorials , Im testing with rspec spec/requests/static_pages_spec.rb , Error occurred " No DRb server is running. Running in local process instead"' I did some research , they said it's because Spork server is not running , so i added Spork.each_run do to the spc file, it dosen't help , I also modified the gem file from gem 'guard-spork' to gem 'guard-spork', :github => 'guard/guard-spork' Still the same, Anyone can help? Thanks in Advance!
Spec file:
require 'spec_helper'
Spork.each_run do
end
describe "Static pages" do
let(:base_title) { "Ruby on Rails Tutorial Sample App" }
describe "Home page" do
it "should have the content 'Sample App'" do
visit '/static_pages/home'
expect(page).to have_content('Sample App')
end
it "should have the base title" do
visit '/static_pages/home'
expect(page).to have_title("Ruby on Rails Tutorial Sample App")
end
it "should not have a custom page title" do
visit '/static_pages/home'
expect(page).not_to have_title('| Home')
end
describe "Contact page" do
it "should have the content 'Contact'" do
visit '/static_pages/contact'
expect(page).to have_content('Contact')
end
it "should have the title 'Contact'" do
visit '/static_pages/contact'
expect(page).to have_title("Ruby on Rails Tutorial Sample App | Contact")
end
end
end
end
Gemfile :
source 'https://rubygems.org'
ruby '2.0.0'
gem 'rails', '4.0.2'
gem 'bootstrap-sass', '2.3.2.0'
gem 'pg', '0.15.1'
group :development, :test do
gem 'guard-spork', :github => 'guard/guard-spork'
gem 'sprockets', '2.11.0'
gem 'rspec-rails', '2.13.1'
gem 'guard-rspec', '2.5.0'
gem 'spork-rails', '4.0.0'
gem 'childprocess', '0.3.6'
end
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
end
gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '2.2.1'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
group :doc do
gem 'sdoc', '0.3.20', require: false
end
group :production do
gem 'rails_12factor', group: :production
end
# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
You should run spork in different process with command spork. Also, remove Spork part from test and modify you spec_helper file with something like this (move all in Spork.prefork block)
The other thing is that Spork had been replaced (not directly) by spring that does the same thing, but without additional configuration.

Why am I getting an error while using RSpec 3.0 with Capybara 2.3 in Rails 4.1?

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

Don't know how to build task - Cucumber

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 :)

Getting error while running bundle exec rspec spec/requests/static_pages_spec.rb in Rails

I am following this article where I can written this code in this ruby file below and home page does have sample app, but it still says static pages home page should have content 'Sample App' when I run bundle exec rspec spec/requests/static_pages_spec.rb
spec/requests/static_pages_spec file code:
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
home.html.erb
<h1>Sample App</h1>
<p>
This is the home page for the
Ruby on Rails Tutorial
sample application.
</p>
Below is my gem file for this app. please advise. thanks for your help.
source 'https://rubygems.org'
gem 'rails', '3.2.1'
gem 'sqlite3'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
group :development do
gem 'rspec-rails', '2.6.0'
end
group :test do
gem 'webrat', '0.7.1'
gem 'capybara', '1.0.0.beta1'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '3.2.3'
gem 'coffee-rails', '3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer'
gem 'uglifier', '1.0.3'
end
gem 'jquery-rails', '2.0.0'
group :production do
gem 'pg', '0.12.2'
end
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
In the output from your failed rspec test do you have the line FATAL: database "sample_app_test" does not exist many lines above the error Failed examples: rspec ./spec/requests/static_pages_spec.rb:7 # Static pages Home page should have the content 'Ruby on Rails'? If so the following steps worked for me:
Open the sample_app/config.database.yml file in a text editor, and under test, change the database to the actual name of the postgres db you using, save the .yml file, and re-run the rspec test.
I think that you need to require capybara manualy in the spec_helper.rb. That's what I normally do :)
I think this is a conflict with webrat. Remove it from you gem file.
#gem 'webrat', '0.7.1'
gem 'capybara', '1.0.0.beta1'

Resources