First you have to install web driver that you prefer
For me, I'm using chromedriver
Install selenium-webdriver
gem
gem install selenium-webdriver
Then install chromedriver
, currently I am using the latest chrome browser version 93
- Download
chromedriver
from chromedriver's website - Choose the driver that support with your browser, eg: ChromeDriver 93.0.4577.15
- Extract the zip file and install the package
- Move the executable to under /opt/WebDriver/bin (create if the does not exist).
For more detail visit
I get an example from cucumber official website but have a few tweak to get it works in my local machine
# features/search_cheese_on_google.feature
Feature: Visit google using web driver
Everybody wants to see the result when we search something on google
Scenario: search for cheese
Given I am on the google search page
When I search for "cheese"
Then the page title will start with "cheese"
In step definition,
# features/step_definitions/webdriver_step.rb
require 'rubygems'
require 'selenium-webdriver'
Selenium::WebDriver::Chrome::Service.driver_path = "/opt/WebDriver/bin/chromedriver"
Given('I am on the google search page') do
@driver = Selenium::WebDriver.for :chrome
@driver.get "http://google.com"
end
When('I search for {string}') do |string|
element = @driver.find_element name: "q"
element.send_keys "cheese"
element.submit
end
Then('the page title will start with {string}') do |expected_result|
wait = Selenium::WebDriver::Wait.new timeout: 10
wait.until { @driver.title.downcase.start_with? "cheese" }
puts "Page title is #{@driver.title}"
@driver.close
expect(@driver.title).to include expected_result
end
run
cucumber
You would the result something like this
Well done!
Top comments (0)