Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save p0deje/3829054 to your computer and use it in GitHub Desktop.
Save p0deje/3829054 to your computer and use it in GitHub Desktop.
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
> 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
<!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