-
-
Save jollychang/3851827 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SUMMARY | |
# This gist shows a performance test between a few different variations of Selenium, | |
# running against Rsel's unit-test sinatra site (https://github.com/a-e/rsel) | |
# It repeats these steps 20 times: | |
# | |
# - Click "About this site" link | |
# - Go back to the homepage | |
# - Click "Form test" link | |
# - Fill in a text field using an XPath locator | |
# - Go back to the homepage | |
# - Click "Table test" link | |
# - Go back to the homepage | |
# | |
# For each of three drivers: | |
# | |
# - Selenuim::Client::Driver (the deprecated API, using RC against a selenium-server running locally) | |
# - Selenium::WebDriver.for(:remote) (the new WebDriver API, also using RC against the same selenium-server) | |
# - Selenium::WebDriver.for(:firefox) (the new WebDriver API, driving Firefox directly) | |
# | |
# THE RESULTS | |
# (3 runs) | |
# ~/git/rsel/perf $ ./perf-test.rb | |
# Selenium::Client::Driver | |
# Loop time: 7.334946s | |
# Total time: 14.707187s | |
# Selenium::WebDriver.for(:remote) | |
# Loop time: 13.867896s | |
# Total time: 19.199194s | |
# Selenium::WebDriver.for(:firefox) | |
# Loop time: 12.82659s | |
# Total time: 19.909601s | |
# | |
# ~/git/rsel/perf $ ./perf-test.rb | |
# Selenium::Client::Driver | |
# Loop time: 7.275329s | |
# Total time: 14.86167s | |
# Selenium::WebDriver.for(:remote) | |
# Loop time: 13.906527s | |
# Total time: 18.953618s | |
# Selenium::WebDriver.for(:firefox) | |
# Loop time: 12.972183s | |
# Total time: 19.719022s | |
# | |
# ~/git/rsel/perf $ ./perf-test.rb | |
# Selenium::Client::Driver | |
# Loop time: 7.057336s | |
# Total time: 14.321859s | |
# Selenium::WebDriver.for(:remote) | |
# Loop time: 13.524225s | |
# Total time: 18.673041s | |
# Selenium::WebDriver.for(:firefox) | |
# Loop time: 13.35662s | |
# Total time: 19.994786s | |
# THE SCRIPT | |
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'time' | |
require 'selenium-client' | |
require 'selenium-webdriver' | |
first_name = ".//*[self::input | self::textarea | self::select][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')][((./@id = 'First name' or ./@name = 'First name') or ./@id = //label[normalize-space(string(.)) = 'First name']/@for)] | .//label[normalize-space(string(.)) = 'First name']//.//*[self::input | self::textarea | self::select][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')] | .//*[self::input | self::textarea | self::select][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')][((./@id = 'First name' or ./@name = 'First name') or ./@id = //label[contains(normalize-space(string(.)), 'First name')]/@for)] | .//label[contains(normalize-space(string(.)), 'First name')]//.//*[self::input | self::textarea | self::select][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')]" | |
start = Time.now | |
browser = Selenium::Client::Driver.new( | |
:host => 'localhost', | |
:port => 4444, | |
:browser => '*firefox', | |
:url => 'http://localhost:8070') | |
browser.start_new_browser_session | |
browser.open('/') | |
loop_start = Time.now | |
20.times do | |
browser.click('link=About this site') | |
browser.open('/') | |
browser.click('link=Form test', :wait_for => :page) | |
browser.type("xpath=" + first_name, 'Eric') | |
browser.open('/') | |
browser.click('link=Table test') | |
browser.open('/') | |
end | |
loop_time = Time.now - loop_start | |
browser.close_current_browser_session | |
total_time = Time.now - start | |
puts "Selenium::Client::Driver" | |
puts "Loop time: #{loop_time}s" | |
puts "Total time: #{total_time}s" | |
start = Time.now | |
driver = Selenium::WebDriver.for(:remote) | |
driver.navigate.to 'http://localhost:8070' | |
loop_start = Time.now | |
20.times do | |
driver.find_element(:link, 'About this site').click | |
driver.navigate.back | |
driver.find_element(:link, 'Form test').click | |
driver.find_element(:xpath, first_name).send_keys('Eric') | |
driver.navigate.back | |
driver.find_element(:link, 'Table test').click | |
driver.navigate.back | |
end | |
loop_time = Time.now - loop_start | |
driver.quit | |
total_time = Time.now - start | |
puts "Selenium::WebDriver.for(:remote)" | |
puts "Loop time: #{loop_time}s" | |
puts "Total time: #{total_time}s" | |
start = Time.now | |
driver = Selenium::WebDriver.for(:firefox) | |
driver.navigate.to 'http://localhost:8070' | |
loop_start = Time.now | |
20.times do | |
driver.find_element(:link, 'About this site').click | |
driver.navigate.back | |
driver.find_element(:link, 'Form test').click | |
driver.find_element(:xpath, first_name).send_keys('Eric') | |
driver.navigate.back | |
driver.find_element(:link, 'Table test').click | |
driver.navigate.back | |
end | |
loop_time = Time.now - loop_start | |
driver.quit | |
total_time = Time.now - start | |
puts "Selenium::WebDriver.for(:firefox)" | |
puts "Loop time: #{loop_time}s" | |
puts "Total time: #{total_time}s" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment