Module: TestCentricity::WebDriverConnect
- Includes:
- Capybara::DSL
- Defined in:
- lib/testcentricity_web/web_core/webdriver_helper.rb
Instance Attribute Summary collapse
-
#bs_local ⇒ Object
Returns the value of attribute bs_local.
-
#webdriver_path ⇒ Object
Returns the value of attribute webdriver_path.
Class Method Summary collapse
- .close_tunnel ⇒ Object
- .initialize_browser_size ⇒ Object
- .initialize_web_driver(app_host = nil) ⇒ Object
- .set_domain(url) ⇒ Object
-
.set_webdriver_path(project_path) ⇒ Object
Set the WebDriver path for Chrome, Firefox, IE, or Edge browsers.
Instance Attribute Details
#bs_local ⇒ Object
Returns the value of attribute bs_local.
11 12 13 |
# File 'lib/testcentricity_web/web_core/webdriver_helper.rb', line 11 def bs_local @bs_local end |
#webdriver_path ⇒ Object
Returns the value of attribute webdriver_path.
10 11 12 |
# File 'lib/testcentricity_web/web_core/webdriver_helper.rb', line 10 def webdriver_path @webdriver_path end |
Class Method Details
.close_tunnel ⇒ Object
159 160 161 162 163 164 165 166 167 168 |
# File 'lib/testcentricity_web/web_core/webdriver_helper.rb', line 159 def self.close_tunnel unless @bs_local.nil? @bs_local.stop if @bs_local.isRunning raise 'BrowserStack Local instance could not be stopped' else puts 'BrowserStack Local instance has been stopped' end end end |
.initialize_browser_size ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/testcentricity_web/web_core/webdriver_helper.rb', line 131 def self.initialize_browser_size # tile browser windows if running in multiple parallel threads and BROWSER_TILE environment variable is true if ENV['PARALLEL'] && ENV['BROWSER_TILE'] thread = ENV['TEST_ENV_NUMBER'].to_i if thread > 1 Browsers.set_browser_window_position(100 * thread - 1, 100 * thread - 1) sleep(1) end else Browsers.set_browser_window_position(10, 10) sleep(1) end browser = Environ.browser.to_s if Environ.is_desktop? if ENV['BROWSER_SIZE'] == 'max' Browsers.maximize_browser elsif ENV['BROWSER_SIZE'] Browsers.set_browser_window_size(ENV['BROWSER_SIZE']) else Browsers.set_browser_window_size(Browsers.browser_size(browser, ENV['ORIENTATION'])) end elsif Environ.is_mobile? && !Environ.is_device? Browsers.set_browser_window_size(Browsers.browser_size(browser, ENV['ORIENTATION'])) end Environ.session_state = :running end |
.initialize_web_driver(app_host = nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/testcentricity_web/web_core/webdriver_helper.rb', line 13 def self.initialize_web_driver(app_host = nil) Capybara.app_host = app_host unless app_host.nil? browser = ENV['WEB_BROWSER'] # assume that we're testing within a local desktop web browser Environ.driver = :webdriver Environ.platform = :desktop Environ.browser = browser Environ.headless = false Environ.device = :web Environ.device_name = 'browser' case browser.downcase.to_sym when :appium initialize_appium context = 'mobile device emulator' when :browserstack initialize_browserstack context = 'Browserstack cloud service' when :crossbrowser initialize_crossbrowser context = 'CrossBrowserTesting cloud service' when :gridlastic initialize_gridlastic context = 'Gridlastic cloud service' when :saucelabs initialize_saucelabs context = 'Sauce Labs cloud service' when :testingbot initialize_testingbot context = 'TestingBot cloud service' else if ENV['SELENIUM'] == 'remote' initialize_remote context = 'Selenium Grid2' else initialize_local_browser context = 'local browser instance' end end # set browser window size only if testing with a desktop web browser unless Environ.is_device? || Capybara.current_driver == :appium initialize_browser_size end Environ.session_state = :running puts "Using #{Environ.browser} browser via #{context}" end |
.set_domain(url) ⇒ Object
63 64 65 |
# File 'lib/testcentricity_web/web_core/webdriver_helper.rb', line 63 def self.set_domain(url) Capybara.app_host = url end |
.set_webdriver_path(project_path) ⇒ Object
Set the WebDriver path for Chrome, Firefox, IE, or Edge browsers
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/testcentricity_web/web_core/webdriver_helper.rb', line 68 def self.set_webdriver_path(project_path) path_to_driver = nil # check for existence of /webdrivers or /features/support/drivers folders base_path = 'features/support/drivers' unless File.directory?(File.join(project_path, base_path)) base_path = 'webdrivers' unless File.directory?(File.join(project_path, base_path)) raise 'Could not find WebDriver files in /webdrivers or /features/support/drivers folders' end end # set WebDriver path based on browser and operating system case ENV['WEB_BROWSER'].downcase.to_sym when :chrome, :chrome_headless if OS.osx? path_to_driver = 'mac/chromedriver' elsif OS.windows? path_to_driver = 'windows/chromedriver.exe' end @webdriver_path = File.join(project_path, base_path, path_to_driver) Selenium::WebDriver::Chrome.driver_path = @webdriver_path when :firefox, :firefox_headless if OS.osx? path_to_driver = 'mac/geckodriver' elsif OS.windows? path_to_driver = 'windows/geckodriver.exe' end @webdriver_path = File.join(project_path, base_path, path_to_driver) Selenium::WebDriver::Firefox.driver_path = @webdriver_path when :ie path_to_driver = 'windows/IEDriverServer.exe' @webdriver_path = File.join(project_path, base_path, path_to_driver) Selenium::WebDriver::IE.driver_path = @webdriver_path when :edge path_to_driver = 'windows/MicrosoftWebDriver.exe' @webdriver_path = File.join(project_path, base_path, path_to_driver) Selenium::WebDriver::Edge.driver_path = @webdriver_path else if ENV['HOST_BROWSER'] case ENV['HOST_BROWSER'].downcase.to_sym when :chrome if OS.osx? path_to_driver = 'mac/chromedriver' elsif OS.windows? path_to_driver = 'windows/chromedriver.exe' end @webdriver_path = File.join(project_path, base_path, path_to_driver) Selenium::WebDriver::Chrome.driver_path = @webdriver_path when :firefox if OS.osx? path_to_driver = 'mac/geckodriver' elsif OS.windows? path_to_driver = 'windows/geckodriver.exe' end @webdriver_path = File.join(project_path, base_path, path_to_driver) Selenium::WebDriver::Firefox.driver_path = @webdriver_path else raise "#{ENV['HOST_BROWSER']} is not a valid host browser for mobile browser emulation" end end end puts "The webdriver path is: #{@webdriver_path}" unless path_to_driver.nil? end |