There are a lot of examples on how to perform javascript tests with Capybara/Selenium/Rspec in which you can write a test like so:
it "does something", :js => true do
...
end
However with minitest you can't pass a second parameter to instruct selenium to perform the test.
Does anyone have any ideas on how this can be done?
https://github.com/wojtekmach/minitest-metadata seems to have provided a solution to exactly this.
You can do the following:
Just to update some information, there is a more powerful selenium-webdriver with Ruby Bindings now.
To test JavaScript on firefox from terminal quickly with Rails 4 and selenium-webdriver, you need to do the 4 steps below:
Add gem to your Gemfile
gem 'selenium-webdriver' gem 'minitest-rails'
Install gem
bundle install
Generate test case (Ref: Official Guide)
bin/rails generate integration_test your_case_name
Start to write test code in your test case. Actually you can write it in ruby without Capybara, to write case with Capybara you can refer to Capybara at Github
Minitest sample:
Currently it seems lack of resources with respect to how to work with selenium-webdriver, CI server (Jenkins) and Rails minitest smoothly, I have created a simple project and hope it can help any one getting started quickly and easily: Rails Selenium Working Case
Also appreciate the comments that let me can make better answer.
Hmm I noticed a couple lines in the docs that seem to say that the above can only be done in Rspec
However, if you are using RSpec or Cucumber, you may instead want to consider leaving the faster
:rack_test
as thedefault_driver
, and marking only those tests that require a JavaScript-capable driverusing :js => true
or@javascript
, respectively.What
:js
flag is doing is very simple. It switches the current driver from default (rack-test) to another one that supports javascript execution (selenium, webkit). You can do the same thing in minitest:Of course you can abstract this into a module for convenience: