Skip to content

Instantly share code, notes, and snippets.

@alisterscott
Created October 6, 2011 23:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alisterscott/1268955 to your computer and use it in GitHub Desktop.
Save alisterscott/1268955 to your computer and use it in GitHub Desktop.
Benchmark of three ruby testing APIS
user system total real
selenium-webdriver 1.820000 0.830000 24.010000 ( 67.492727)
watir-webdriver 1.850000 0.840000 24.200000 ( 64.550630)
capybara 1.810000 0.830000 25.160000 ( 69.461563)
# * Start browser
# * Navigate to watir-webdriver-demo form
# * Check whether text field with id 'entry_0' exists
# * Check whether text field with id 'entry_99' exists
# * Set text field with id 'entry_0' to '1'
# * Set text field with id 'entry_0' to '2'
# * Select 'Ruby' from select list with id 'entry_1'
# * Click the Submit button
require 'bench'
require 'selenium-webdriver'
require 'watir-webdriver'
require 'capybara/dsl'
benchmark 'selenium-webdriver' do
driver = Selenium::WebDriver.for :firefox
driver.navigate.to 'http://bit.ly/watir-webdriver-demo'
begin
driver.find_element(:id, 'entry_0')
rescue Selenium::WebDriver::Error::NoSuchElementError
# doesn't exist
end
begin
driver.find_element(:id, 'entry_99').displayed?
rescue Selenium::WebDriver::Error::NoSuchElementError
# doesn't exist
end
driver.find_element(:id, 'entry_0').clear
driver.find_element(:id, 'entry_0').send_keys '1'
driver.find_element(:id, 'entry_0').clear
driver.find_element(:id, 'entry_0').send_keys '2'
driver.find_element(:id, 'entry_1').find_element(:tag_name => 'option', :value => 'Ruby').click
driver.find_element(:name, 'submit').click
driver.quit
end
benchmark 'watir-webdriver' do
b = Watir::Browser.start 'bit.ly/watir-webdriver-demo', :firefox
b.text_field(:id => 'entry_0').exists?
b.text_field(:id => 'entry_99').exists?
b.text_field(:id => 'entry_0').set '1'
b.text_field(:id => 'entry_0').set '2'
b.select_list(:id => 'entry_1').select 'Ruby'
b.button(:name => 'submit').click
b.close
end
benchmark 'capybara' do
Capybara.app_host = 'http://bit.ly/watir-webdriver-demo'
include Capybara::DSL
session = Capybara::Session.new(:selenium)
session.visit('http://bit.ly/watir-webdriver-demo')
begin
session.find_by_id('entry_0').visible?
rescue Capybara::ElementNotFound
# false
end
begin
session.find_by_id('entry_0').visible?
rescue
#false
end
session.fill_in 'entry_0', :with => '1'
session.fill_in 'entry_0', :with => '2'
session.select 'Ruby', :from => 'entry_1'
session.click_button 'Submit'
session.driver.quit
end
run 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment