How can I access the default webdriver for Selenium 2 with Rails 3 Rspec and Capybara?

Viewed 2082

I have been trying to implement Selenium webdriver for a couple days to do my javascript testing. I have installed and included the gem selenium-webdriver in my Gemfile. A few simple tests pass by adding , js: true to an Rspec test.

Nothing else was necessary: When the tests are run, a Firefox window opens the current page specified earlier in the file with Capybara visit path("/news/#{news_item.id}") and then a button is clicked, displaying a form that was hidden, fields are filled, and a submit button is pressed, no problem. The test passes and the browser closes.

Advancing to more complex tests require me to call methods on the webdriver, but I don't know how to access it, because I did not explicitly create one. I could, however, if I wanted create my own with driver = Selenium::WebDriver.for :firefox but this causes a second browser instance to open, and it is completely blank rather than opening the page Capybara navigated to.

My question is: How can I get access to the default webdriver being used so that I can call methods such as empty_stars = driver.find_element(:class, "empty-stars-container") and driver.action.move_to(empty_stars).perform ?

1 Answers
Related