Before starting, we’ll need to download the latest ChromeDriver binary executable. Once we have it, we’ll need to tell Selenium where it is.
Add it to the System PATH or Specify it in the Selenium setup or Launch ChromeDriver and connect to it via Selenium Remote
Create one file as chrome.rb
require 'selenium-webdriver'
require 'rspec/expectations'
include RSpec::Matchers
def setup
Selenium::WebDriver::Chrome::Service.executable_path = File.join(Dir.pwd, 'chromedriver')
@driver = Selenium::WebDriver.for :chrome
end
def teardown
@driver.quit
end
def run
setup
yield
teardown
end
Notice that in setup we are telling Selenium where the ChromeDriver exectuable is with executable_path before instantiating the browser.
Now add a simple test to chrome.rb
run do
@driver.get 'http://example.com/'
expect(@driver.title).to eql 'The Internet'
end
If we save this file and run it (e.g., ruby chrome.rb) it will launch an instance of Chrome.
Now run your test cases.