Best Selenium code snippet using Selenium.WebDriver.Remote.url
sauce_labs.rb
Source:sauce_labs.rb
...7 caps.platform = 'Windows 2008'8 caps[:name] = "mySkrill Smoke: FIREFOX WIN7 - #{Time.now.strftime '%Y-%m-%d %H:%M'}"9 @local_browser = Selenium::WebDriver.for(10 :remote,11 :url => "http://myaccount_ci:9bc00106-156c-4838-9865-2f92c46762ca@ondemand.saucelabs.com:80/wd/hub",12 :desired_capabilities => caps)13 when 'firefox_winxp'14 caps = Selenium::WebDriver::Remote::Capabilities.firefox15 caps['platform'] = 'Windows 2003'16 caps['version'] = '17'17 caps[:name] = "mySkrill Smoke: FIREFOX FOR WIN XP - #{Time.now.strftime '%Y-%m-%d %H:%M'}"18 @local_browser = Selenium::WebDriver.for(19 :remote,20 :url => "http://myaccount_ci:9bc00106-156c-4838-9865-2f92c46762ca@ondemand.saucelabs.com:80/wd/hub",21 :desired_capabilities => caps)22 when 'firefox_mac'23 caps = Selenium::WebDriver::Remote::Capabilities.firefox24 caps['platform'] = 'Mac 10.6'25 caps['version'] = '17'26 caps[:name] = "mySkrill Smoke: FIREFOX FOR MAC OSX - #{Time.now.strftime '%Y-%m-%d %H:%M'}"27 @local_browser = Selenium::WebDriver.for(28 :remote,29 :url => "http://myaccount_ci:9bc00106-156c-4838-9865-2f92c46762ca@ondemand.saucelabs.com:80/wd/hub",30 :desired_capabilities => caps)31 when 'chrome_winxp'32 caps = Selenium::WebDriver::Remote::Capabilities.chrome33 caps.platform = 'Windows 2003'34 caps[:name] = "mySkrill Smoke: CHROME FOR WIN XP- #{Time.now.strftime '%Y-%m-%d %H:%M'}"35 @local_browser = Selenium::WebDriver.for(36 :remote,37 :url => "http://myaccount_ci:9bc00106-156c-4838-9865-2f92c46762ca@ondemand.saucelabs.com:80/wd/hub",38 :desired_capabilities => caps)39 when 'chrome_win7'40 caps = Selenium::WebDriver::Remote::Capabilities.chrome41 caps.platform = 'Windows 2008'42 caps[:name] = "mySkrill Smoke: CHROME FOR WIN7 - #{Time.now.strftime '%Y-%m-%d %H:%M'}"43 @local_browser = Selenium::WebDriver.for(44 :remote,45 :url => "http://myaccount_ci:9bc00106-156c-4838-9865-2f92c46762ca@ondemand.saucelabs.com:80/wd/hub",46 :desired_capabilities => caps)47 when 'chrome_mac'48 caps = Selenium::WebDriver::Remote::Capabilities.chrome49 caps['platform'] = 'Mac 10.8'50 caps[:name] = "mySkrill Smoke: CHROME FOR MAC - #{Time.now.strftime '%Y-%m-%d %H:%M'}"51 @local_browser = Selenium::WebDriver.for(52 :remote,53 :url => "http://myaccount_ci:9bc00106-156c-4838-9865-2f92c46762ca@ondemand.saucelabs.com:80/wd/hub",54 :desired_capabilities => caps)55 when 'ie9_win7'56 caps = Selenium::WebDriver::Remote::Capabilities.internet_explorer57 caps.platform = 'Windows 2008'58 caps.version = '9'59 caps[:name] = "mySkrill Smoke: IE9 FOR WIN7 - #{Time.now.strftime '%Y-%m-%d %H:%M'}"60 @local_browser = Selenium::WebDriver.for(61 :remote,62 :url => "http://myaccount_ci:9bc00106-156c-4838-9865-2f92c46762ca@ondemand.saucelabs.com:80/wd/hub",63 :desired_capabilities => caps)64 when 'ie8_win7'65 caps = Selenium::WebDriver::Remote::Capabilities.internet_explorer66 caps.platform = 'Windows 2008'67 caps.version = '8'68 caps[:name] = "mySkrill Smoke: IE8 FOR WIN7 - #{Time.now.strftime '%Y-%m-%d %H:%M'}"69 @local_browser = Selenium::WebDriver.for(70 :remote,71 :url => "http://myaccount_ci:9bc00106-156c-4838-9865-2f92c46762ca@ondemand.saucelabs.com:80/wd/hub",72 :desired_capabilities => caps)73 when 'ie9_winxp'74 caps = Selenium::WebDriver::Remote::Capabilities.internet_explorer75 caps.platform = 'Windows 2003'76 caps.version = '9'77 caps[:name] = "mySkrill Smoke: IE9 FOR WIN XP - #{Time.now.strftime '%Y-%m-%d %H:%M'}"78 @local_browser = Selenium::WebDriver.for(79 :remote,80 :url => "http://myaccount_ci:9bc00106-156c-4838-9865-2f92c46762ca@ondemand.saucelabs.com:80/wd/hub",81 :desired_capabilities => caps)82 when 'ie8_winxp'83 caps = Selenium::WebDriver::Remote::Capabilities.internet_explorer84 caps.platform = 'Windows 2003'85 caps.version = '8'86 caps[:name] = "mySkrill Smoke: IE8 FOR WIN XP - #{Time.now.strftime '%Y-%m-%d %H:%M'}"87 @local_browser = Selenium::WebDriver.for(88 :remote,89 :url => "http://myaccount_ci:9bc00106-156c-4838-9865-2f92c46762ca@ondemand.saucelabs.com:80/wd/hub",90 :desired_capabilities => caps)91 when 'ie7_winxp'92 caps = Selenium::WebDriver::Remote::Capabilities.internet_explorer93 caps.platform = 'Windows 2003'94 caps.version = '7'95 caps[:name] = "mySkrill Smoke: IE7 FOR WIN XP - #{Time.now.strftime '%Y-%m-%d %H:%M'}"96 @local_browser = Selenium::WebDriver.for(97 :remote,98 :url => "http://myaccount_ci:9bc00106-156c-4838-9865-2f92c46762ca@ondemand.saucelabs.com:80/wd/hub",99 :desired_capabilities => caps)100 when 'safari'101 # /* Notice: We don't yet support HTTPS for this platform over Sauce Connect */102 caps = Selenium::WebDriver::Remote::Capabilities.safari103 caps.platform = 'Mac 10.8'104 caps.version = '6'105 caps[:name] = "mySkrill Smoke: SAFARI - #{Time.now.strftime '%Y-%m-%d %H:%M'}"106 @local_browser = Selenium::WebDriver.for(107 :remote,108 :url => "http://myaccount_ci:9bc00106-156c-4838-9865-2f92c46762ca@ondemand.saucelabs.com:80/wd/hub",109 :desired_capabilities => caps)110 when 'ipad'111 # /* Notice: We don't yet support HTTPS for this platform over Sauce Connect */112 caps = Selenium::WebDriver::Remote::Capabilities.ipad113 caps.platform = 'Mac 10.8'114 caps.version = '6'115 caps[:name] = "mySkrill Smoke: iOS 6.0 iPAD - #{Time.now.strftime '%Y-%m-%d %H:%M'}"116 @local_browser = Selenium::WebDriver.for(117 :remote,118 :url => "http://myaccount_ci:9bc00106-156c-4838-9865-2f92c46762ca@ondemand.saucelabs.com:80/wd/hub",119 :desired_capabilities => caps)120 when 'iphone'121 # /* Notice: We don't yet support HTTPS for this platform over Sauce Connect */122 caps = Selenium::WebDriver::Remote::Capabilities.iphone123 caps.platform = 'Mac 10.8'124 caps.version = '6'125 caps[:name] = "mySkrill Smoke: iOS 6.0 iPHONE - #{Time.now.strftime '%Y-%m-%d %H:%M'}"126 @local_browser = Selenium::WebDriver.for(127 :remote,128 :url => "http://myaccount_ci:9bc00106-156c-4838-9865-2f92c46762ca@ondemand.saucelabs.com:80/wd/hub",129 :desired_capabilities => caps)130 when 'ie10_win8'131 caps = Selenium::WebDriver::Remote::Capabilities.internet_explorer132 caps['platform'] = 'Windows 2012'133 caps['version'] = '10'134 caps[:name] = "mySkrill Smoke: IE10 FOR WIN8 - #{Time.now.strftime '%Y-%m-%d %H:%M'}"135 @local_browser = Selenium::WebDriver.for(136 :remote,137 :url => "http://myaccount_ci:9bc00106-156c-4838-9865-2f92c46762ca@ondemand.saucelabs.com:80/wd/hub",138 :desired_capabilities => caps)139 when 'opera_win7'140 caps = Selenium::WebDriver::Remote::Capabilities.opera141 caps['platform'] = 'Windows 2008'142 caps['version'] = '12'143 caps[:name] = "mySkrill Smoke: OPERA FOR WIN7 - #{Time.now.strftime '%Y-%m-%d %H:%M'}"144 @local_browser = Selenium::WebDriver.for(145 :remote,146 :url => "http://myaccount_ci:9bc00106-156c-4838-9865-2f92c46762ca@ondemand.saucelabs.com:80/wd/hub",147 :desired_capabilities => caps)148 end149 end150end...
minitest_helper.rb
Source:minitest_helper.rb
...7require 'timeout'8require 'minitest/reporters'9Minitest::Reporters.use! Minitest::Reporters::DefaultReporter.new10#### HEALTHCENTRAL11HC_BASE_URL = Configuration["healthcentral"]["base_url"]12HC_DRUPAL_URL = Configuration["healthcentral"]["drupal_url"]13IMMERSIVE_URL = Configuration["healthcentral"]["immersive"]14COLLECTION_URL = Configuration["collection_url"]15ASSET_HOST = Configuration["asset_host"]16MED_BASE_URL = Configuration["medtronic"]["base_url"]17#### BERKELEY WELLNESS18BW_BASE_URL = Configuration["berkeley"]["base_url"]19BW_ASSET_HOST = Configuration["berkeley"]["asset_host"]20#### THE BODY21BODY_URL = Configuration["thebody"]["base_url"]22THE_BODY_ASSET_HOST = Configuration["thebody"]["asset_host"]23 24$_cache_buster ||= "?foo=#{rand(36**8).to_s(36)}"25def firefox26 # Selenium::WebDriver::Firefox::Binary.path= '/opt/firefox/firefox'27 # Selenium::WebDriver::Firefox::Binary.path= '/Applications/Firefox.app/Contents/MacOS/firefox'28 @driver = Selenium::WebDriver.for :firefox29 @driver.manage.window.resize_to(1224,1000)30 @driver.manage.timeouts.implicit_wait = 531end32def firefox_with_proxy33 proxy_location = Settings.location34 @server = BrowserMob::Proxy::Server.new(proxy_location)35 @server.start36 @proxy = server.create_proxy37 @profile = Selenium::WebDriver::Firefox::Profile.new38 @profile.proxy = @proxy.selenium_proxy39 @driver = Selenium::WebDriver.for :firefox, :profile => @profile40 @driver.manage.window.resize_to(1224,1000)41 @driver.manage.timeouts.implicit_wait = 542end43def fire_fox_with_secure_proxy44 proxy_location = Settings.location45 $_server ||= BrowserMob::Proxy::Server.new(proxy_location).start46 @proxy = $_server.create_proxy47 @profile = Selenium::WebDriver::Firefox::Profile.new48 @profile.proxy = @proxy.selenium_proxy(:http, :ssl)49 @driver = Selenium::WebDriver.for :firefox, :profile => @profile50 @driver.manage.window.resize_to(1224,1000)51 @driver.manage.timeouts.implicit_wait = 352 @driver.manage.timeouts.page_load = 2453end54def fire_fox_remote_proxy55 proxy_location = Settings.location56 server = BrowserMob::Proxy::Server.new(proxy_location)57 server.start58 @proxy = server.create_proxy59 @profile = Selenium::WebDriver::Firefox::Profile.new60 @profile.proxy = @proxy.selenium_proxy(:http, :ssl)61 caps = Selenium::WebDriver::Remote::Capabilities.new(62 :browser_name => "firefox", :firefox_profile => @profile63 )64 @driver = Selenium::WebDriver.for(65 :remote,66 url: 'http://jenkins.choicemedia.com:4444//wd/hub',67 desired_capabilities: caps) 68 @driver.manage.window.resize_to(1224,1000)69 @driver.manage.timeouts.implicit_wait = 570end71def mobile_fire_fox_with_secure_proxy72 proxy_location = Settings.location73 $_server ||= BrowserMob::Proxy::Server.new(proxy_location).start74 75 @proxy = $_server.create_proxy76 @profile = Selenium::WebDriver::Firefox::Profile.new77 @profile.proxy = @proxy.selenium_proxy(:http, :ssl)78 @profile['general.useragent.override'] = 'Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30'79 @driver = Selenium::WebDriver.for :firefox, :profile => @profile80 @driver.manage.window.resize_to(425,960)81 @driver.manage.timeouts.implicit_wait = 582 @driver.manage.timeouts.page_load = 2483end84def fire_fox_remote85 @driver = Selenium::WebDriver.for(86 :remote,87 url: 'http://jenkins.choicemedia.com:4444//wd/hub',88 desired_capabilities: :firefox)89 @driver.manage.window.resize_to(1224,1000)90 @driver.manage.timeouts.implicit_wait = 591end92def cleanup_driver_and_proxy93 @driver.quit 94 @proxy.close95end96def phantomjs97 @driver = Selenium::WebDriver.for :remote, url: 'http://localhost:8001'98end99def visit(url)100 preload_page(url)101 begin102 @driver.navigate.to url 103 rescue Timeout::Error, Net::ReadTimeout, Selenium::WebDriver::Error::TimeOutError104 end105 begin106 @driver.execute_script("window.stop();")107 rescue Timeout::Error, Net::ReadTimeout, Selenium::WebDriver::Error::JavascriptError108 end109 110 #Avoid race conditions111 sleep 0.75112end113def preload_page(url)114 if ENV['TEST_ENV'] == "production" || ENV['TEST_ENV'] == "staging"115 begin116 RestClient::Request.execute(method: :get, url: url,117 timeout: 10)118 rescue RestClient::RequestTimeout119 end120 end121end122def wait_for_page_to_load123 begin124 Timeout::timeout(3) do125 loop until finished_loading?126 end127 rescue Timeout::Error, Net::ReadTimeout, EOFError128 end129 sleep 0.5130 begin131 @driver.execute_script("window.stop();")132 rescue Timeout::Error, Net::ReadTimeout133 end134end135def finished_loading?136 state = @driver.execute_script "return window.document.readyState"137 sleep 0.5138 if state == "complete"139 true140 else141 false142 end143end144def wait_for145 begin146 Selenium::WebDriver::Wait.new(:timeout => 3).until { yield }147 rescue Selenium::WebDriver::Error::NoSuchElementError, Selenium::WebDriver::Error::TimeOutError148 false149 rescue Net::ReadTimeout150 false151 end152end153#Find an element by css 154#If the element.diplayed? == true then return the element155#Otherwise return nil156def find(css)157 begin158 node = @driver.find_element(:css, css)159 node = nil if ( node.displayed? == false )160 rescue Selenium::WebDriver::Error::NoSuchElementError161 node = nil162 end163 node164end165#Looks for a Selenium element with the given css166#Text fails if the element is not on the page, or does not have text167#168# present_with_text?(".content_pad h1")169#170def present_with_text?(css)171 node = find css172 unless node173 self.errors.add(:functionality, "#{css} missing from page")174 end175 if node 176 unless node.text.length > 0177 self.errors.add(:functionality, "#{css} was blank")178 end179 end180end181def scroll_to_bottom_of_page182 @driver.execute_script("window.scrollTo(0,document.body.scrollHeight);")183end184def open_omniture_debugger185 @driver.execute_script "javascript:void(window.open(\"\",\"dp_debugger\",\"width=600,height=600,location=0,menubar=0,status=1,toolbar=0,resizable=1,scrollbars=1\").document.write(\"<script language='JavaScript' id=dbg src='https://www.adobetag.com/d1/digitalpulsedebugger/live/DPD.js'></\"+\"script>\"))"186 sleep 1187end188def get_omniture_from_debugger189 original_window = @driver.window_handles.first190 second_window = @driver.window_handles.last191 @driver.switch_to.window second_window192 wait_for { @driver.find_element(:css, 'td#request_list_cell').displayed? }193 omniture_node = find 'td#request_list_cell'194 begin195 omniture_text = omniture_node.text if omniture_node196 rescue Selenium::WebDriver::Error::StaleElementReferenceError197 omniture_text = nil198 end199 if omniture_text == nil200 sleep 1201 wait_for { @driver.find_element(:css, 'td#request_list_cell').displayed? }202 omniture_node = find 'td#request_list_cell'203 if omniture_node204 omniture_text = omniture_node.text205 else206 omniture_text = nil207 end208 end209 @driver.switch_to.window original_window210 omniture_text211end212def evaluate_script(script)213 begin214 @driver.execute_script "return #{script}"215 rescue Selenium::WebDriver::Error::JavascriptError216 "javascript error"217 end218end219def page_has_ad(ad_url)220 ads = []221 @proxy.har.entries.each do |entry|222 if entry.request.url.include?(ad_url)223 ads << entry.request.url224 end225 end226 if ads.compact.length >= 1227 true228 else229 false230 end231end...
example-rspec.rb
Source:example-rspec.rb
...144 end145 146 ##############################TESTS##############################147 it "check_SEIDE_version" do148 @base_url = "https://github.com/"149 @driver.get(@base_url + "/SeleniumHQ/selenium/wiki/SeIDE-Release-Notes")150 @driver.find_element(:css, "#user-content-280").click151 @driver.find_element(:xpath, "//div[@id='wiki-body']/div/ul[3]/li").text.should =~ /^[\s\S]*New[\s\S]*$/152 @driver.save_screenshot('screenshots/rsec+selenium+check+seide.png')153 sleep 5154 end155 156 it "check_SSL_certs" do157 #test that self-signed exception is working158 @base_url = "https://self-signed.badssl.com/"159 @driver.get(@base_url)160 @driver.save_screenshot('screenshots/rsec+selenium+baddssl.png')161 sleep 5162 end163end...
test_environment.rb
Source:test_environment.rb
...69 end70 def native_events?71 @native_events ||= !!ENV['native']72 end73 def url_for(filename)74 url = app_server.where_is filename75 url.sub!("127.0.0.1", "10.0.2.2") if browser == :android76 url77 end78 def root79 @root ||= Pathname.new("../../../../../../../").expand_path(__FILE__)80 end81 private82 def create_driver83 instance = case driver84 when :remote85 create_remote_driver86 when :opera87 create_opera_driver88 when :firefox89 create_firefox_driver90 when :chrome91 create_chrome_driver92 when :iphone93 create_iphone_driver94 when :safari95 create_safari_driver96 when :phantomjs97 create_phantomjs_driver98 else99 WebDriver::Driver.for driver100 end101 @create_driver_error_count -= 1 unless @create_driver_error_count == 0102 instance103 rescue => ex104 @create_driver_error = ex105 @create_driver_error_count += 1106 raise ex107 end108 def remote_capabilities109 caps = WebDriver::Remote::Capabilities.send(ENV['WD_REMOTE_BROWSER'] || 'firefox')110 caps.javascript_enabled = true111 caps.css_selectors_enabled = true112 caps113 end114 MAX_ERRORS = 4115 class DriverInstantiationError < StandardError116 end117 def check_for_previous_error118 return unless @create_driver_error && @create_driver_error_count >= MAX_ERRORS119 msg = "previous #{@create_driver_error_count} instantiations of driver #{driver.inspect} failed, not trying again"120 msg << " (#{@create_driver_error.message})"121 raise DriverInstantiationError, msg, @create_driver_error.backtrace122 end123 def create_remote_driver124 WebDriver::Driver.for(:remote,125 :desired_capabilities => remote_capabilities,126 :url => ENV['WD_REMOTE_URL'] || remote_server.webdriver_url,127 :http_client => keep_alive_client || http_client128 )129 end130 def create_opera_driver131 ENV['SELENIUM_SERVER_JAR'] = remote_server_jar132 WebDriver::Driver.for :opera, :logging_level => ENV['log'] ? :config : :severe133 end134 def create_firefox_driver135 if native_events?136 profile = WebDriver::Firefox::Profile.new137 profile.native_events = true138 WebDriver::Driver.for :firefox, :profile => profile139 else140 WebDriver::Driver.for :firefox141 end142 end143 def create_chrome_driver144 binary = ENV['chrome_binary']145 if binary146 WebDriver::Chrome.path = binary147 end148 server = ENV['chromedriver'] || ENV['chrome_server']149 if server150 WebDriver::Chrome.driver_path = server151 end152 args = []153 args << "--no-sandbox" if ENV['TRAVIS']154 WebDriver::Driver.for :chrome,155 :native_events => native_events?,156 :args => args157 # :http_client => keep_alive_client || http_client158 end159 def create_phantomjs_driver160 binary = ENV['phantomjs_binary']161 if binary162 WebDriver::PhantomJS.path = binary163 end164 WebDriver::Driver.for :phantomjs165 end166 def create_iphone_driver167 url = ENV['iphone_url']168 if url169 WebDriver::Driver.for :iphone, :url => url170 else171 WebDriver::Driver.for :iphone172 end173 end174 def create_safari_driver175 if ENV['timeout']176 WebDriver::Driver.for :safari, :timeout => Integer(ENV['timeout'])177 else178 WebDriver::Driver.for :safari179 end180 end181 def keep_alive_client182 require 'selenium/webdriver/remote/http/persistent'183 STDERR.puts "INFO: using net-http-persistent"...
Base.rb
Source:Base.rb
...35 {"androidPackage" =>36 'com.android.chrome'}37 )38 driver = Selenium::WebDriver.for(:remote,39 :url => "http://" + server + ":9515/wd/hub",40 :desired_capabilities => caps)41 when "Android Chrome Remote" then42 caps =43 Selenium::WebDriver::Remote::Capabilities.chrome("chromeOptions" =>44 {"androidPackage" =>45 'com.android.chrome'}46 )47 driver = Selenium::WebDriver.for(:remote,48 :url => "http://" + server_remote + ":9515/wd/hub",49 :desired_capabilities => caps)50 when "firefox grid local" then51 caps =52 Selenium::WebDriver::Remote::Capabilities.firefox(53 :version => "43.0",54 )55 driver = Selenium::WebDriver.for(:remote,56 :url => gridURL,57 :desired_capabilities => caps)58 driver.manage.window.maximize59 when "firefox grid remote" then60 caps =61 Selenium::WebDriver::Remote::Capabilities.firefox(62 :version =>63 "43.0 remote",64 )65 driver = Selenium::WebDriver.for(:remote,66 :url => gridURL,67 :desired_capabilities => caps)68 driver.manage.window.maximize69 when "chrome grid local" then70 caps =71 Selenium::WebDriver::Remote::Capabilities.chrome(72 :version => "47.0.2526.106 m (64-bit)",73 )74 driver = Selenium::WebDriver.for(:remote,75 :url => gridURL,76 :desired_capabilities => caps)77 driver.manage.window.maximize78 when "chrome grid remote" then79 caps =80 Selenium::WebDriver::Remote::Capabilities.chrome(81 :version => "47.0.2526.106 m remote",82 )83 driver = Selenium::WebDriver.for(:remote,84 :url => gridURL,85 :desired_capabilities => caps)86 driver.manage.window.maximize87 when "ie grid local" then88 caps =89 Selenium::WebDriver::Remote::Capabilities.ie(90 :version => "11.0 X64",91 )92 driver = Selenium::WebDriver.for(:remote,93 :url => gridURL,94 :desired_capabilities => caps)95 driver.manage.window.maximize96 when "ie grid remote" then97 caps =98 Selenium::WebDriver::Remote::Capabilities.ie(99 :version => "11.0 Win32",100 )101 driver = Selenium::WebDriver.for(:remote,102 :url => gridURL,103 :desired_capabilities => caps)104 driver.manage.window.maximize105 when "Android Chrome grid local" then106 caps =107 Selenium::WebDriver::Remote::Capabilities.chrome(108 "chromeOptions" =>109 {"androidPackage" => 'com.android.chrome'},110 :version => "android local"111 )112 driver = Selenium::WebDriver.for(:remote,113 :url => gridURL,114 :desired_capabilities => caps)115 when "Android Chrome grid remote" then116 caps =117 Selenium::WebDriver::Remote::Capabilities.chrome(118 "chromeOptions" =>119 {"androidPackage" => 'com.android.chrome'},120 :version => "android remote"121 )122 driver = Selenium::WebDriver.for(:remote,123 :url => gridURL,124 :desired_capabilities => caps)125 end126 return driver127 end128 def driver()129 return @driver130 end131 def quit()132 # æ«ãå¾
ã£ãå¾ãçµäº133 sleep(10)134 @driver.quit135 end136end...
watirspec_helper.rb
Source:watirspec_helper.rb
...124 end125 def chrome_args126 opts = {args: ["--disable-translate"],127 desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome}128 if url = ENV['WATIR_CHROME_SERVER']129 opts[:url] = url130 end131 if driver = ENV['WATIR_CHROME_DRIVER']132 Selenium::WebDriver::Chrome.driver_path = driver133 end134 if path = ENV['WATIR_CHROME_BINARY']135 Selenium::WebDriver::Chrome.path = path136 end137 if ENV['TRAVIS']138 opts[:args] << "--no-sandbox" # https://github.com/travis-ci/travis-ci/issues/938139 end140 opts141 end142 def remote_args143 url = ENV["REMOTE_SERVER_URL"] || "http://127.0.0.1:#{@server.port}/wd/hub"144 opts = {}145 if remote_browser == :ff_legacy146 path = ENV['FF_LEGACY_BINARY']147 opts[:firefox_binary] = path if path148 @remote_browser = :firefox149 @ff_legacy = true150 opts[:marionette] = false151 elsif remote_browser == :firefox152 path = ENV['FIREFOX_BINARY']153 opts[:firefox_binary] = path if path154 end155 caps = Selenium::WebDriver::Remote::Capabilities.send(remote_browser, opts)156 {url: url, desired_capabilities: caps}157 end158 class SelectorListener < Selenium::WebDriver::Support::AbstractEventListener159 def initialize160 @counts = Hash.new(0)161 end162 def before_find(how, what, driver)163 @counts[how] += 1164 end165 def report166 total = @counts.values.inject(0) { |mem, var| mem + var }167 puts "\nSelenium selector stats: "168 @counts.each do |how, count|169 puts "\t#{how.to_s.ljust(20)}: #{count * 100 / total} (#{count})"170 end...
env.rb
Source:env.rb
...51 Capybara.default_wait_time = 1552 Capybara.page.driver.browser.manage.window.maximize53 when "grid-firefox"54 require 'selenium-webdriver'55 # driver = Selenium::WebDriver.for(:remote, :url => "http://127.0.0.1:5555/wd/hub", :desired_capabilities => :firefox)56 caps = Selenium::WebDriver::Remote::Capabilities.firefox("firefoxOptions" => {"args" => [ "--allow-running-insecure-content" ]})57 Capybara.default_driver = :selenium58 Capybara.register_driver :selenium do |app|59 Capybara::Selenium::Driver.new(app,60 :browser => :remote,61 :url => "http://127.0.0.1:5555/wd/hub",62 :desired_capabilities => caps)63 end64 when "grid-chrome"65 require 'selenium-webdriver'66 # driver = Selenium::WebDriver.for(:remote, :url => "http://127.0.0.1:5555/wd/hub", :desired_capabilities => :firefox)67 caps = Selenium::WebDriver::Remote::Capabilities.chrome("chromeOptions" => {"args" => [ "--allow-running-insecure-content" ]})68 Capybara.default_driver = :selenium69 Capybara.register_driver :selenium do |app|70 Capybara::Selenium::Driver.new(app,71 :browser => :remote,72 :url => "http://127.0.0.1:8989/wd/hub",73 :desired_capabilities => caps)74 end75 when "grid-ie"76 require 'selenium-webdriver'77 # driver = Selenium::WebDriver.for(:remote, :url => "http://127.0.0.1:5555/wd/hub", :desired_capabilities => :firefox)78 caps = Selenium::WebDriver::Remote::Capabilities.ie79 Capybara.default_driver = :selenium80 Capybara.register_driver :selenium do |app|81 Capybara::Selenium::Driver.new(app,82 :browser => :remote,83 :url => "http://127.0.0.1:9999/wd/hub",84 :desired_capabilities => caps)85 end86else87Capybara.configure do |config|88 config.default_driver = :selenium89 #config.run_server = false90 config.default_selector = :css91 config.default_wait_time = 1092end93 Capybara.page.driver.browser.manage.window.maximize94 Capybara.register_driver :selenium do |app|95 profile = Selenium::WebDriver::Firefox::Profile.new96 Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile)97 end98end99require File.dirname(__FILE__) + '/lib/configuration';100BASE_URL = Configuration["base_url"]101$base_url = BASE_URL
webdriver.rb
Source:webdriver.rb
...47 # @example48 #49 # WebDriver.for :firefox, :profile => "some-profile"50 # WebDriver.for :firefox, :profile => Profile.new51 # WebDriver.for :remote, :url => "http://localhost:4444/wd/hub", :desired_capabilities => caps52 #53 # One special argument is not passed on to the bridges, :listener. You can pass a listener for this option54 # to get notified of WebDriver events. The passed object must respond to #call or implement the methods from AbstractEventListener.55 #56 # @see Selenium::WebDriver::Support::AbstractEventListener57 #58 def self.for(*args)59 WebDriver::Driver.for(*args)60 end61 end # WebDriver62end # Selenium...
url
Using AI Code Generation
1url = URI.parse("http://localhost:4444/wd/hub")2url = URI.parse("http://localhost:4444/wd/hub")3driver = Selenium::WebDriver.for(:remote, :url => url, :desired_capabilities => caps)4url = URI.parse("http://localhost:4444/wd/hub")5driver = Selenium::WebDriver.for(:remote, :url => url, :http_client => http_client)6url = URI.parse("http://localhost:4444/wd/hub")7driver = Selenium::WebDriver.for(:remote, :url => url, :http_client => http_client)8url = URI.parse("http://localhost:4444/wd/hub")9driver = Selenium::WebDriver.for(:remote, :url => url, :http_client => http_client)10url = URI.parse("http
url
Using AI Code Generation
1uri = URI.parse("http://localhost:4444/wd/hub")2uri = URI.parse("http://localhost:4444/wd/hub")3uri = URI.parse("http://localhost:4444/wd/hub")4uri = URI.parse("http://localhost:4444/wd/hub")5uri = URI.parse("http://localhost:4444/wd/hub")
url
Using AI Code Generation
1url = URI.parse("http://localhost:4444/wd/hub")2url = URI.parse("http://localhost:4444/wd/hub")3driver = Selenium::WebDriver.for(:remote, :url => url, :desired_capabilities => caps)4url = URI.parse("http://localhost:4444/wd/hub")5driver = Selenium::WebDriver.for(:remote, :url => url, :http_client => http_client)6url = URI.parse("http://localhost:4444/wd/hub")7driver = Selenium::WebDriver.for(:remote, :url => url, :http_client => http_client)8url = URI.parse("http://localhost:4444/wd/hub")9driver = Selenium::WebDriver.for(:remote, :url => url, :http_client => http_client)10url = URI.parse("http
url
Using AI Code Generation
1uri = URI.parse("http://localhost:4444/wd/hub")2uri = URI.parse("http://localhost:4444/wd/hub")3uri = URI.parse("http://localhost:4444/wd/hub")4uri = URI.parse("http://localhost:4444/wd/hub")5uri = URI.parse("http://localhost:4444/wd/hub")
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!