In a Ruby on Rails project, I found this method whose goal is to retrieve Selenium driver depending the environment. (development, test or production)
def driver
@driver ||= begin
if Rails.env.production?
driver = Selenium::WebDriver.for :remote, url: 'http://localhost:4444/wd/hub'
else
driver = Selenium::WebDriver.for :firefox
end
driver.manage.timeouts.implicit_wait = 1
driver
end
end
Of course, I read the official documentation but it still not appears very clear:
http://code.google.com/p/selenium/wiki/RemoteWebDriver – http://code.google.com/p/selenium/wiki/FirefoxDriver
What are the differences between these two ways (remote and firefox) ?
And especially, for the removed way, why set the pointed host to localhost… indeed, if localhost is chosen, why not choose the firefox driver instead ?
:remote means that you’re going to use a remote server running Selenium Server at the :url. In this case selenium server’s running on localhost. Because no browser is identified, it will use whatever default browser the server is set to.
:firefox means it’s going to try to use firefox on the same box the script is running on.
You can see these two examples on the intro page to rubybindings.
http://code.google.com/p/selenium/wiki/RubyBindings
For more general documentation stuff this might be a good place…
http://selenium.googlecode.com/svn/trunk/docs/api/rb/index.html
As to why someone would this is? Maybe in a prod environment someone else aside from the guy who developed this code controls the selenium server depending on the platform it’s on (chrome, ie, ff, etc) (like some prod guy who can’t access code?). I’m just guessing here.