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
?
Capybara is a web-based test automation software that simulates scenarios for user stories and automates web application testing for behavior-driven software development. It is written in the Ruby programming language.
It is a wrapper around requestly extension to enable easy integration in selenium-webdriver.The extension can modify headers.
You can get access to the webdriver in Capybara using:
page.driver.browser
So you would want to do something like:
empty_stars = page.driver.browser.find_element(:class, "empty-stars-container")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With