Created
October 3, 2012 19:03
-
-
Save p0deje/3829054 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
require 'benchmark' | |
require 'selenium-webdriver' | |
old_locator = ".//input[not(@type) or (@type!='file' and @type!='radio' and @type!='checkbox' and @type!='submit' and @type!='reset' and @type!='image' and @type!='button' and @type!='hidden' and @type!='datetime' and @type!='date' and @type!='month' and @type!='week' and @type!='time' and @type!='datetime-local' and @type!='range' and @type!='color')]" | |
new_locator = ".//input[not(@type) or (translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')!='file' and translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')!='radio' and translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')!='checkbox' and translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')!='submit' and translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')!='reset' and translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')!='image' and translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')!='button' and translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')!='hidden' and translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')!='datetime' and translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')!='date' and translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')!='month' and translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')!='week' and translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')!='time' and translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')!='datetime-local' and translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')!='range' and translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')!='color')]" | |
[:firefox, :chrome, :ie].each do |name| | |
begin | |
puts "Benchmarking #{name}:" | |
browser = Selenium::WebDriver.for name | |
browser.get("http://localhost/test.html") | |
results = Benchmark.realtime do | |
100.times { browser.find_element(xpath: old_locator) } | |
end | |
puts " Locating without translate elapsed in #{results*1000} ms" | |
results = Benchmark.realtime do | |
100.times { browser.find_element(xpath: new_locator) } | |
end | |
puts " Locating with translate elapsed in #{results*1000} ms" | |
ensure | |
browser.close | |
end | |
end |
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
> ruby bechmark_locate_text_field_with_translate.rb | |
Benchmarking firefox: | |
Locating without translate elapsed in 862.7290725708008 ms | |
Locating with translate elapsed in 864.3319606781006 ms | |
Benchmarking chrome: | |
Locating without translate elapsed in 844.58584255435 ms | |
Locating with translate elapsed in 842.96396875486007 ms | |
Benchmarking ie: | |
Locating without translate elapsed in 3755.399999999999996 ms | |
Locating with translate elapsed in 3755.428 ms |
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
<!DOCTYPE html> | |
<html> | |
<h1>Test</h1> | |
<input type="text"></input> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment