class AutomationHelpers::Drivers::V4::Browserstack
{AutomationHelpers::Drivers::V4::Browserstack}
The Browserstack
Driver that will connect to a hosted grid Requires a series of pre-set values to be passed in
Attributes
Public Class Methods
#### Initial setup options
-
browser (required) - When instantiating, the first argument must be the symbol that represents what browser to use
-
browserstack_options (required) - A Hash of all required options that will be parsed and used to setup the driver
-
:build_name (
String
) -> The build name to be stored on browserstack servers -
:project_name (
String
) -> The project name to be stored on browserstack servers -
:session_name (
String
) -> The session name to be stored on browserstack servers -
:browserstack_debug_mode (Boolean) -> Set this to true to run in browserstack debug mode (Note this runs slower!)
-
:config (
String
) -> This is an underscore separated key that distils the granular running information i.e. Windows_7_86 means run on Windows Operating System, OS Version 7, Browser Version 86 i.e. OSX_Mojave_12 means run on Mac Operating System, OS Version Mojave, Browser Version 12 i.e. Windows_10_92 means run on Windows Operating System, OS Version 10, Browser Version 92 -
:username (
String
) -> The username forBrowserstack
-
:api_key (
String
) -> The api key forBrowserstack
-
# File lib/automation_helpers/drivers/v4/browserstack.rb, line 37 def initialize(browser, browserstack_options, device_options = {}) @browser = browser @browserstack_options = browserstack_options @device_options = device_options end
Public Instance Methods
@return [Nil]
Register a new driver with the default selenium name for use in a remote browserstack setup
# File lib/automation_helpers/drivers/v4/browserstack.rb, line 46 def register Capybara.register_driver :selenium do |app| Capybara::Selenium::Driver.new( app, browser: :remote, capabilities: [desired_capabilities, options], url: browserstack_hub_url ) end end
Private Instance Methods
# File lib/automation_helpers/drivers/v4/browserstack.rb, line 99 def browser_specific_capabilities Capabilities.for(browser, device_options) end
# File lib/automation_helpers/drivers/v4/browserstack.rb, line 125 def browser_version browserstack_options[:config].split('_')[2] end
# File lib/automation_helpers/drivers/v4/browserstack.rb, line 103 def browser_version_capability return {} if device? { 'browserVersion' => browser_version } end
# File lib/automation_helpers/drivers/v4/browserstack.rb, line 70 def browserstack_capabilities ::Faraday::Utils.deep_merge(configurable_capabilities, static_capabilities) end
# File lib/automation_helpers/drivers/v4/browserstack.rb, line 113 def browserstack_hub_url "https://#{browserstack_options[:username]}:#{browserstack_options[:api_key]}@hub-cloud.browserstack.com/wd/hub" end
# File lib/automation_helpers/drivers/v4/browserstack.rb, line 74 def configurable_capabilities { 'bstack:options' => { 'buildName' => browserstack_options[:build_name], 'projectName' => browserstack_options[:project_name], 'sessionName' => browserstack_options[:session_name], 'debug' => browserstack_options[:browserstack_debug_mode], 'os' => os, 'osVersion' => os_version } } end
# File lib/automation_helpers/drivers/v4/browserstack.rb, line 59 def desired_capabilities Selenium::WebDriver::Remote::Capabilities.new( ::Faraday::Utils.deep_merge( # Browserstack Capabilities and General Capabilities are at different levels, so we merge first browserstack_capabilities.merge(browser_version_capability), # Then we deep merge with anything specifically passed into the driver registration (as these can be nested) browser_specific_capabilities.as_json ) ) end
# File lib/automation_helpers/drivers/v4/browserstack.rb, line 129 def device? %i[android ios].include?(browser) end
# File lib/automation_helpers/drivers/v4/browserstack.rb, line 109 def options Options.for(browser) end
# File lib/automation_helpers/drivers/v4/browserstack.rb, line 117 def os browserstack_options[:config].split('_')[0] end
# File lib/automation_helpers/drivers/v4/browserstack.rb, line 121 def os_version browserstack_options[:config].split('_')[1] end
# File lib/automation_helpers/drivers/v4/browserstack.rb, line 87 def static_capabilities { 'bstack:options' => { 'local' => 'false', 'seleniumVersion' => '4.0.0-alpha-6', 'consoleLogs' => 'verbose', 'networkLogs' => 'true', 'resolution' => '1920x1080' } } end