Last active
April 4, 2019 04:43
-
-
Save mohitmun/5b91124d9cb52647cf2bca388784eaa1 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 'rubygems' | |
require 'appium_lib' | |
require 'benchmark' | |
require 'browserstack-fast-selenium' | |
username = ENV["BROWSERSTACK_USERNAME"] | |
access_key = ENV["BROWSERSTACK_ACCESSKEY"] | |
caps = {} | |
caps['build'] = 'Ruby Appium Sample' | |
caps['name'] = 'single_test' | |
caps['device'] = 'Samsung Galaxy S8 Plus' | |
caps['platformName'] = 'android' | |
caps['browserstack.debug'] = true | |
caps['app'] = 'bs://6b7f1b6680fd787ca4f42a4ffb94024b730eddef' | |
appium_driver = Appium::Driver.new({ | |
'caps' => caps, | |
'appium_lib' => { | |
:server_url => "http://#{username}:#{access_key}@hub-cloud.browserstack.com/wd/hub" | |
}}, true) | |
driver = appium_driver.start_driver | |
wait = Selenium::WebDriver::Wait.new(:timeout => 30) | |
wait.until { driver.find_element(:accessibility_id, "Search Wikipedia").displayed? } | |
element = driver.find_element(:accessibility_id, "Search Wikipedia") | |
element.click | |
wait.until { driver.find_element(:id, "org.wikipedia.alpha:id/search_src_text").displayed? } | |
Benchmark.bmbm do |benchmark| | |
benchmark.report("Appium find_element by ID") { | |
50.times do |i| | |
@search_box = driver.find_element(:id, "org.wikipedia.alpha:id/search_src_text") | |
end | |
} | |
benchmark.report("Appium find_element by XPath") { | |
50.times do |i| | |
@search_box = driver.find_element(:xpath, '//*[@resource-id="org.wikipedia.alpha:id/search_src_text"]') | |
end | |
} | |
end | |
driver.quit | |
puts "Benchmarking for Instagram app" | |
caps['app'] = 'bs://eb0d6132785aa83872f4fc68c841949412491e6f' | |
appium_driver = Appium::Driver.new({ | |
'caps' => caps, | |
'appium_lib' => { | |
:server_url => "http://#{username}:#{access_key}@hub-cloud.browserstack.com/wd/hub" | |
}}, true) | |
driver = appium_driver.start_driver | |
wait = Selenium::WebDriver::Wait.new(:timeout => 30) | |
wait.until {driver.find_element(:id, "com.instagram.android:id/button_positive").displayed?} | |
button = driver.find_element(:id, "com.instagram.android:id/button_positive") | |
button.click | |
Benchmark.bmbm do |benchmark| | |
benchmark.report("Appium find_element by ID") { | |
50.times do |i| | |
driver.find_element(:id, "com.instagram.android:id/facebook_text_switcher") | |
end | |
} | |
benchmark.report("Appium find_element by XPath") { | |
50.times do |i| | |
driver.find_element(:xpath, '//*[@resource-id="com.instagram.android:id/facebook_text_switcher"]') | |
end | |
} | |
end | |
driver.quit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment