Can selenium test cases be run without setting up the rails environment? - ruby-on-rails

We have a few test cases automated with selenium & capybara during the application development. They all works well when we run it from within the application using rake spec command.
Now in order for the QA team to run these, we don't want to setup the rails environment in their computer. Is there a solution for this?
I am using the following gems,
capybara
selenium
rspec
Any input or suggestion will be really helpful.
Thanks in advance....

Related

watir-webdriver phantomjs and ghostdriver

I currently have a rails app that uses rspec and watir-webdriver for my integration tests. I want to run my integration tests in a headless browser (for speed purposes). Since my development is done on a mac the headless gem won't work for me. I am looking to phantomjs as the solution. Whereas phantomjs works well with rspec/capybara (via poltergeist) and there are plenty of examples on how to make that work, I can't find much in the way of getting it to work well with watir-webdriver and ghostdriver.
I have built the "special" phantomjs that ghostdriver requires but I am lost after that. Has anyone used this setup before (rails/watir-webdriver/ghostdriver)?
My main goal is to speed up my integration tests. So if anyone has a better suggestion than what I have described here, I am flexible :)
Any help is greatly appreciated!
It is now fully supported by Watir-WebDriver and easy to get running:
Steps to get working on OSX
First make sure you have homebrew installed
brew update
brew install phantomjs
Run irb and start using GhostDriver!
require 'watir-webdriver'
b = Watir::Browser.new :phantomjs
b.goto "www.google.com"
b.url #"http://www.google.com.au/"
b.title #"Google"
See full details on this blog post: http://watirmelon.com/2013/02/05/watir-webdriver-with-ghostdriver-on-osx-headless-browser-testing/

Rails rspec+capybara test on staging server?

So I do testing rspec+capybara on localhost, but if I wanted to test on staging server(linux), is it possible to use capybara?
I'm guessing testing with selenium will not work on staging server.
I would like to test frontend(mostly js stuff) on staging, any recommendation would be great.
I use Rails 3.
Checkout the headless gem - From the author
I created it so I can run Selenium tests in Cucumber without any shell scripting. Even more, you can go headless only when you run tests against Selenium.
I'd imagine it would would with rspec as well.

Run selenium on a remote server

I am writing integration test for one of my project, using the following gems for the same, rspec, capybara and selenium.
I face the following challenges in the same,
I want to run the test on an existing database, i don't want to clear the existing data before or after executing the test.
We have a remote server for integration testing. Is it possible to run the test on a remove server? The way i would like to go is after updating the build on integration server, i would like to go for a integration test using selenium.
Any help is highly appreciated.
Sorry, but selenium tests cannot be run in a transaction. You have to (for example) dump database and load previously prepared database after executing each test.
Yes, it is possible. What solution you're using for continuous integration and build management? What's the problem you're encountering? Can you describe it?
Got the solution, we need to do as follows,
Capybara.current_driver = :selenium
Capybara.app_host = 'http://www.google.com'
...
visit('/')
Reference: capybara gem

Can 'cucumber' run my rspec-on-rails tests?

I have a small test project that I'm using to test the waters for a much larger project. I am using rspec on rails for testing, but recently looked into Cucumber. It looks very nice, but I'm wondering if there's a way for cucumber to run my spec tests, or for rspec (autospec) to run my cucumber features. I've looked around extensively, but have yet to find a solid conclusion.
Thanks,
Mike
I've been experimenting with Cucumber as well. It supports autotest:
AUTOFEATURE=true autospec
That runs both the rspec & cucumber test suite continuously.
An easy way to do this would be to create a Rake task that invokes both tools, such as this minimal example:
desc 'Run rspec + cucumber'
task :build => [:spec, :features]
Then you can build both with:
rake build
Both RSpec and Cucumber come with some default tasks which work with Rails, but you can customize the tasks to suit your needs. There's more info on writing rake tasks here.
Depends on what you are looking for, but the best way to run cucumber tests with rspec is to use turnip, which uses exactly the same feature syntax as cucumber (the syntax is called gherkin), but allows you to use most of the functionality of rspec. https://github.com/jnicklas/turnip.
If you want to take things one step further, you can run your features from inside rspec _spec.rb files using a gem we created called rutabaga. https://github.com/simplybusiness/rutabaga
In both cases, all the tests can be run by executing rspec or bundle exec rspec as needed.

Why is RSpec so slow under Rails?

Whenever I run rspec tests for my Rails application it takes forever and a day of overhead before it actually starts running tests. Why is rspec so slow? Is there a way to speed up Rails' initial load or single out the part of my Rails app I need (e.g. ActiveRecord stuff only) so it doesn't load absolutely everything to run a few tests?
I definitely suggest checking out spork.
http://spork.rubyforge.org/
The railstutorial specifically addresses this, and gives a workaround to get spork running nicely in rails 3.0 (as of this moment, spork is not rails 3 ready out of the box). Of course, if you're not on rails 3.0, then you should be good to go.
The part of the tutorial showing how to get spork running in rails 3.0
http://railstutorial.org/chapters/static-pages#sec:spork
Checking when spork is rails 3.0 ready
http://www.railsplugins.org/plugins/440-spork
You should be able to to speed up your script/spec calls by running script/spec_server in a separate terminal window, then adding the additional -X parameter to your spec calls.
Why is rspec so slow? because it loads all the environement, loads fixtures and all that jazz.
Is there a way to speed up Rails' initial load you could try using mocks instead of relying on the database, this is actually correct for unit testing and will definitly speed up your unit tests. Additionnaly using the spec server as mentionned by #Scott Matthewman can help, same with the autotest from zentest mentionned by #Marc-Andre Lafortune
Is there a way to single out the part of my Rails app I need (e.g. ActiveRecord stuff only) so it doesn't load absolutely everything to run a few tests? what about this
rake test:recent
I am not sure how the rspec task integrate with this but you could definitely use the test:recent task as a template to do the same with rspec tests if the.
rake test:rspec:recent
doesn't exist yet
because it loads all the environement, loads fixtures and all that jazz.
The real culprit is if you run it using rake spec, it runs the db:test:prepare task.
This task drops your entire test database and re-creates it from scratch. This seems ridiculous to me, but that's what it does (the same thing happens when you run rake:test:units etc).
You can easily work around this using the spec application which rspec installs as part of the rspec gem.
Like this:
cd railsapp
spec spec # run all specs without rebuilding the whole damn database
spec spec/models # run model specs only
cd spec
spec controllers/user* # run specs for controllers that start with user
I think the "zen" experience you're looking for is to run spec_server and autospec in the background, with the result being near-instant tests when you save a file.
However, I'm having problems getting these two programs to communicate.
I found an explanation here:
I've noticed that autotest doesn't send commands to the spec_server.
Instead it reloads the entire Rails environment and your application's
plugins everytime it executes. This causes autotest to run
significantly slower than script server, because when you run the
script/spec command the specs are sent to the spec_server which
already has your Rails environment fired up and ready to go. If you
happen to install a new plugin or something like that, then you'll
have to restart the spec_server.
But, how do we fix this issue? I'm guessing it would involve downloading ZenTest and changing code for the autotest program, but don't have time to try it out right now.
Are you running this over Rails? If so, it's not RSpec's initialization that's slow, it's Rails'. Rails has to initialize the entire codebase and yours before running the specs. Well, it doesn't have to, but it does. RSpec runs pretty fast for me under my small non-rails projects.
Running tests can be really slow because the whole rails environment has to load (try script/console) and only then can all tests run. You should use autotest which keeps the environment loaded and will check which files you edit. When you edit and save a file, only the tests that depend on these will run automatically and quickly.
If you're using a Mac I recommend using Rspactor over autotest as it uses a lot fewer resources for polling changed files than autotest. There is both a full Cocoa version
RSpactor.app
or the gem version that I maintain at Github
sudo gem install pelle-rspactor
While these don't speed up individual rspec tests, they feel much faster as they auto run the affected spec's within a second of you hitting save.
As of rspec-rails-1.2.7, spec_server is deprecated in favor of the spork gem.
The main reason is that require takes forever on windows, for some reason.
Tips for speedup:
spork now works with windows, I believe.
You can try "faster_require" which caches locations:
http://github.com/rdp/faster_require
GL.
-rp
If you are on a Windows environment then there is probably little you can do as Rails seems to startup really slowly under Windows. I had the same experience on Windows and had to move my setup to a Linux VM to make it really zippy (I was also using autotest).

Resources