Skip to content

Instantly share code, notes, and snippets.

@jarib
Forked from alisterscott/results.txt
Created October 6, 2011 23:21
Show Gist options
  • Save jarib/1268979 to your computer and use it in GitHub Desktop.
Save jarib/1268979 to your computer and use it in GitHub Desktop.
Benchmark of three ruby testing APIS
fijabakk :: /tmp> ruby test.rb
user system total real
selenium-webdriver 2.670000 0.750000 16.950000 ( 27.015838)
watir-webdriver 1.990000 0.790000 17.540000 ( 27.292868)
capybara 1.890000 0.810000 17.310000 ( 27.553319)
fijabakk :: /tmp>
# encoding: utf-8
# * 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'
require 'uri'
url = "data:text/html;charset=utf-8,#{URI.encode DATA.read}"
benchmark 'selenium-webdriver' do
driver = Selenium::WebDriver.for :firefox
driver.navigate.to url
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(:xpath => '//option[text()="Ruby"]').click
driver.find_element(:name, 'submit').click
driver.quit
end
benchmark 'watir-webdriver' do
b = Watir::Browser.start url, :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 = ''
include Capybara::DSL
session = Capybara::Session.new(:selenium)
session.visit(url)
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 'Send'
session.driver.quit
end
run 10
__END__
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><link rel="shortcut icon" href="//www.google.com/images/icons/product/forms-16.png" type="image/x-icon">
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Watir-WebDriver Demo</title>
<link href='/static/spreadsheets/client/css/779923916-published_form_compiled.css' type='text/css' rel='stylesheet'>
<link href='/static/spreadsheets/client/css/779923916-published_form_compiled.css' type='text/css' rel='stylesheet'>
</head>
<body class="ss-base-body" dir="ltr">
<div class="ss-form-container">
<div class="ss-form-heading"><h1 class="ss-form-title">Watir-WebDriver Demo</h1>
<p></p>
<div class="ss-form-desc ss-no-ignore-whitespace">This is a demo form to demo Watir-WebDriver</div>
<hr class="ss-email-break" style="display:none;">
<div class="ss-required-asterisk">*Må fylles ut</div></div>
<div class="ss-form"><form action="#submitted" method="GET" id="ss-form">
<br>
<div class="errorbox-good">
<div class="ss-item ss-item-required ss-text"><div class="ss-form-entry"><label class="ss-q-title" for="entry_0">What is your name?
<span class="ss-required-asterisk">*</span></label>
<label class="ss-q-help" for="entry_0"></label>
<input type="text" name="entry.0.single" value="" class="ss-q-short" id="entry_0"></div></div></div>
<br> <div class="errorbox-good">
<div class="ss-item ss-item-required ss-select"><div class="ss-form-entry"><label class="ss-q-title" for="entry_1">What language does Watir-WebDriver use?
<span class="ss-required-asterisk">*</span></label>
<label class="ss-q-help" for="entry_1"></label>
<select name="entry.1.single" id="entry_1"><option value="Java">Java</option> <option value="Ruby">Ruby</option> <option value="C#">C#</option> <option value="Clojure">Clojure</option> <option value="Python">Python</option></select></div></div></div>
<br> <div class="errorbox-good">
<div class="ss-item ss-radio"><div class="ss-form-entry"><label class="ss-q-title" for="entry_2">What is ruby?
</label>
<label class="ss-q-help" for="entry_2"></label>
<ul class="ss-choices"><li class="ss-choice-item"><label class="ss-choice-label"><input type="radio" name="entry.2.group" value="A programming language" class="ss-q-radio" id="group_2_1">
A programming language</label></li> <li class="ss-choice-item"><label class="ss-choice-label"><input type="radio" name="entry.2.group" value="A gem" class="ss-q-radio" id="group_2_2">
A gem</label></li> <li class="ss-choice-item"><label class="ss-choice-label"><input type="radio" name="entry.2.group" value="Both" class="ss-q-radio" id="group_2_3">
Both</label></li>
</ul></div></div></div>
<br> <div class="errorbox-good">
<div class="ss-item ss-checkbox"><div class="ss-form-entry"><label class="ss-q-title" for="entry_3">What versions of ruby?
</label>
<label class="ss-q-help" for="entry_3"></label>
<ul class="ss-choices"><li class="ss-choice-item"><label class="ss-choice-label"><input type="checkbox" name="entry.3.group" value="1.8.6" class="ss-q-checkbox" id="group_3_1">
1.8.6</label></li> <li class="ss-choice-item"><label class="ss-choice-label"><input type="checkbox" name="entry.3.group" value="1.8.7" class="ss-q-checkbox" id="group_3_2">
1.8.7</label></li> <li class="ss-choice-item"><label class="ss-choice-label"><input type="checkbox" name="entry.3.group" value="1.9.2" class="ss-q-checkbox" id="group_3_3">
1.9.2</label></li>
</ul></div></div></div>
<br>
<input type="hidden" name="pageNumber" value="0">
<input type="hidden" name="backupCache" value="">
<div class="ss-item ss-navigate"><div class="ss-form-entry">
<input type="submit" name="submit" value="Send"></div></div></form>
<script type="text/javascript">
(function() {
var divs = document.getElementById('ss-form').
getElementsByTagName('div');
var numDivs = divs.length;
for (var j = 0; j < numDivs; j++) {
if (divs[j].className == 'errorbox-bad') {
divs[j].lastChild.firstChild.lastChild.focus();
return;
}
}
for (var i = 0; i < numDivs; i++) {
var div = divs[i];
if (div.className == 'ss-form-entry' &&
div.firstChild &&
div.firstChild.className == 'ss-q-title') {
div.lastChild.focus();
return;
}
}
})();
</script></div>
<div class="ss-footer"><div class="ss-attribution"></div>
<div class="ss-legal"><span class="ss-powered-by">Drevet av <a href="http://docs.google.com">Google Dokumenter</a></span>
<span class="ss-terms"><small><a href="https://spreadsheets.google.com/spreadsheet/reportabuse?formkey=dGtlWGJjbWhuSlAyMHhLdXc2eE0wX2c6MQ&amp;source=https%253A%252F%252Fspreadsheets.google.com%252Fspreadsheet%252Fviewform%253Fformkey%253DdGtlWGJjbWhuSlAyMHhLdXc2eE0wX2c6MQ">Rapporter misbruk</a>
-
<a href="http://www.google.com/accounts/TOS">Vilkår for bruk</a>
-
<a href="http://www.google.com/google-d-s/terms.html">Ytterligere vilkår</a></small></span></div></div></div></body></html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment