Converting Selenium IDE tests to run in rspec without browser - ruby-on-rails

We have a rails app and some users have used Selenium IDE firefox extension to record/create some tests. We'd like to be able to integrate these tests into our codebase of automated tests.
I understand that Selenium IDE has the ability to export test cases, but what is the easiest way to convert these tests into something that rspec can run without a browser (or headless)?

I've used both. Here is what you can do
export the file using the rspec webdriver format
adjust any use of variables or local file storage that is possible in selenium to make sense using rspec. This will depend totally on your usage.
Here's what one goes through:
Select the test you want to export (you can also export the entire suite)
Export as rspec webdriver
Open the resulting file
Adjust as needed, e.g. move common items to spec_helper.rb and make sure it is included.
Put the file in an rspec folder, e.g. spec/views and make sure that spec_helper includes them.

I understand that Selenium IDE has the ability to export test cases, but what is the easiest way to convert these tests into something that rspec can run without a browser (or headless)?
Selenium IDE is only plugin for Firefox.
I believe, you can to do the same steps on another language/way.
But for this you need to have another code.
Code for Selenium Web Driver is possible to use with headless browser as phantomJS. And its easy.
But Selenium IDE code is only for Firefox IDE plugin.
And by the way, its hard to maintain tests written using IDE. I believe, better to rewrite all tests using Selenium WebDriver in your case. Its will be much easier and faster. (you can use Page Object model for this, as example)

Related

Rspec: testing Mac OS app integration

I have a Rails app that interacts with some Mac software and I need to write some tests for it. How on earth do I do that? Where do I even start?
The Rails app connects to the Mac app through AppleScript and Terminal. Any ideas?
Update
Found this gem to help with Shell expectations. Is that as good as I'm gonna get?
https://github.com/matthijsgroen/rspec-shell-expectations
Testing external dependencies can certainly be a challenge.
Remember that tests you write should test the behavior of the Rails app, not the external dependency. You should have integration tests to verify that the code actually works with the application, but they should be "smoke tests", not a full suite to test every feature.
Write unit tests to verify the behavior of the code that relies on the dependency, and mock out the interactions. Typically with command line apps that means:
the app wrote to STDOUT
the app wrote to STDERR
the app read from STDIN
the app exited with a particular status code
The gem you mentioned is a good start, but you may find it worthwhile to look at rolling your own helper code using Open3 from the Ruby standard library, which can be useful for all the items in the list above.
Use a tag on the specs that need to use the Mac application to make it easier to filter out those specs as necessary.
You may already be familiar with vcr for mocking out HTTP interactions; its "playback" feature is a good source of inspiration.

What is a Good Automated Testing Platform for RSpec?

For testing purposes for Ruby/Rails I use RSpec and I have well over 1000 tests that are already written in my application. Once the app goes live I want to have the tests run once a day on the production server (since all the code is there) and see if anything fails. The test itself will be run against test data and now production data. This is an effort so that any new code that is added in the future will not cause anything to unknowingly break.
I have found a few solutions:
Travis-CI (only open-source ... not suitable for closed-source projects)
Jenkins-CI (not sure if it works with or well with Ruby/RSpec/Rails)
Watir (not sure if Ruby/Rspec works with it, but the tool itself is written in Ruby).
Preferably something that checks the codebase daily and then emails me when something isn't working.
I also plan on integrating JavaScript testing with the a testing library of my choice (I just need the automation platform for testing it).
Can someone provide me some insight as to which tool to use? Or does anyone have any other tools to recommend?
Jenkins-CI works great with rspec, and can run your jasmine javascript testing, and your cucumber javascript tests as well.
The only thing I'd recommend is not to test on your production server itself. When you push changes to your source-control repository, Jenkins will download the new code and run your tests there. When you're green (tests pass), push the code to production.

Running selenium/watir inside the context of the rails server

How can I run a watir test in the context of the app that's being tested? I'd like my test to browse the app and then access ActionMailer::Base.deliveries for emails or check models directly. This is how I understand what's being described here.
UPDATE: They probably use Capybara to be able to acces the email array and be in the context of the "server" which is instantiated just for the test.
I suggest checking out the Rails unit testing docs, then writing a simple Rails test case that starts your app - then try adding a line or two of Watir code to access your app:
http://guides.rubyonrails.org/testing.html
As far as I know you should be able to write a Rails unit test, then put Watir code inside one of your test methods - and if all goes well you should be able to instantiate your web app, use Watir to launch a browser to test it, and in the same method(s) perform non-Watir low-level testing (e.g. checking models/data/etc.)
I've never used Watir inside a Rails test, but I don't see why it wouldn't work.
Watir is about driving browsers to automate functional testing. You could I suppose use it for unit testing of the top level UI stuff, but more often in a 'unit test' context that would be done using a headless browser emulation, Capybara, celerity, or watir-webdriver using the headless option, purely for speed of operation since driving an actual browser can be slow even with a fast browser like chrome.
Most of the times people use Watir it's for more functional tests, often from a test runner framework like Cucumber, sometimes Rspec depending on your needs. You might combine that with other ruby code to access or create test data, to validate something made it into the DB from the UI, but everything in the Watir gem is all about the browser and interacting with it much like a human would, and driving the browser is it's function within the set of tools you might use.
I had the same need and found the following solution: https://stackoverflow.com/a/9687562/90741. I reproduce it here, as the linked question seems to be dead, with its owner...
I had the same need (Watir+RSpec), but the problem is: there is no Rack stack running by default during tests...
I found this solution:
In spec_helper.rb:
HTTP_PORT = 4000
test_instance_pid = fork do
exec 'unicorn_rails -E test -p %d' % HTTP_PORT
end
at_exit do
Process.kill "INT", test_instance_pid
Process.wait
end
Which start the test stack once for all spec tests, and kill it at the end. (In this sample, I am using unicorn, but we can imagine using any other server)
In the spec, I reuse the HTTP_PORT constant to build URL:
browser.goto "http://localhost:#{HTTP_PORT}/"

Does capybara replace selenium?

When using capybara for testing, do you still need the likes of selenium?
What are the advantages of either solution?
Capybara uses Selenium as one of its drivers. By default, Capybara uses the Rack::Test driver instead of controlling an actual browser with Selenium, but when you run Javascript tests, the Selenium driver is the default.
The project's README gives a good overview of how the pieces fit together.

Using Rails with Webrat + Selenium or only Selenium?

I'm reading The Rspec Book, and in that book they are using Webrat with Selenium.
Is it possible to use Selenium directly for integration tests in Rails instead of using it through Webrat?
What are the pros and cons with each way?
It is most definitely possible to use Selenium by itself. I recommend installing the Selenium IDE plugin for Firefox. This gives you an easy scripting layer to automate clicks and that sort of thing. By integrating Selenium with Rails, you can execute integration tests from the command line, which is nice for a number of reasons: other developers on your team can run them more easily, you can run the same tests against multiple browsers more easily, and you can run the tests from a continuous integration server (that can launch a web browser).
We use Cucumber with Capybara for our integration tests. Webrat does not support JavaScript, so if you click a link that has a click event handler for example, the handler won't fire. Capybara knows Javascript so will fire the event handler. Selenium would let you do this as well, but we already use Cucumber and I prefer Cucumber+Capybara tests to Selenium because it is more integrated and the tests are easier to maintain.

Resources