class Quke::BrowserstackConfiguration
Determines the configuration for browserstack, when selected as the driver
Attributes
To run your tests with browserstack you must provide a username and auth_key
as a minimum.
If the user doesn't put these credentials in the config file (because they don't want to commit them to source control), Quke
will also check for the existance of the environment variables BROWSERSTACK_USERNAME and BROWSERSTACK_AUTH_KEY and use them instead
Capabilities are what configure the test in browserstack, for example what OS and browser to use.
Further reference on browserstack capabilities www.browserstack.com/automate/capabilities www.browserstack.com/automate/ruby#configure-capabilities
To use local testing users must provide a key. They will find this in Browserstack once logged in under settings. Its typically the same value as the auth_key
above. If you don't want to put this credential in the config file (because you want to commit it to source control), Quke
will also check for the existance of the environment variable BROWSERSTACK_LOCAL_KEY
Returns a hash of configurations values that will be passed to the browserstack
local binary when its started.
The project uses the gem browserstack-local
to manage starting and stopping the binary Browserstack provide for local testing. When started you can configure how it behaviours by passing in a set of arguments as a hash. This method generates the hash based on a mix of default values and ones taken from the .config.yml
.
See github.com/browserstack/browserstack-local-ruby#arguments www.browserstack.com/local-testing
To run your tests with browserstack you must provide a username and auth_key
as a minimum.
If the user doesn't put these credentials in the config file (because they don't want to commit them to source control), Quke
will also check for the existance of the environment variables BROWSERSTACK_USERNAME and BROWSERSTACK_AUTH_KEY and use them instead
Public Class Methods
Initialize's the instance based in the Quke::Configuration
instance passed in.
# File lib/quke/browserstack_configuration.rb, line 51 def initialize(configuration) @using_browserstack = configuration.data["driver"] == "browserstack" data = validate_input_data(configuration.data) @username = ENV["BROWSERSTACK_USERNAME"] || data["username"] || "" @auth_key = ENV["BROWSERSTACK_AUTH_KEY"] || data["auth_key"] || "" @local_key = ENV["BROWSERSTACK_LOCAL_KEY"] || data["local_key"] || "" @capabilities = data["capabilities"] || {} determine_local_testing_args(configuration) end
Public Instance Methods
Return true if the browserstack.local
value has been set to true in the .config.yml
file and the driver is set to 'browserstack', else false.
It is used when determing whether to start and stop the binary Browserstack provides to support local testing.
# File lib/quke/browserstack_configuration.rb, line 68 def test_locally? @capabilities["browserstack.local"] == true && using_browserstack? end
Returns a string representing the url used when running tests via Browserstack or nil.
It will contain the username and auth_key
set in the .config.yml
, else if username
is blank it will return nil.
An example return value
"http://jdoe:123456789ABCDE@hub.browserstack.com/wd/hub"
It is used when registering the driver with Capybara. So instead of this
Capybara::Selenium::Driver.new( app, browser: :remote, url: 'http://jdoe:123456789ABCDE@hub.browserstack.com/wd/hub', desired_capabilities: my_capabilites )
You can call browserstack_url
to get the url to use
Capybara::Selenium::Driver.new( app, browser: :remote, url: my_config.browserstack_config.url, desired_capabilities: my_capabilites )
# File lib/quke/browserstack_configuration.rb, line 112 def url return "http://#{@username}:#{@auth_key}@hub.browserstack.com/wd/hub" unless @username == "" end
Returns true if the driver was set browserstack
, else false.
This class needs to know whether browserstack was selected as the driver to use in order to correctly determine is the browserstack local testing binary needs to be stopped and started for the tests.
However it also serves as a clean and simple way to determine if browserstack is the selected dribver.
# File lib/quke/browserstack_configuration.rb, line 80 def using_browserstack? @using_browserstack end
Private Instance Methods
# File lib/quke/browserstack_configuration.rb, line 125 def determine_local_testing_args(configuration) @local_testing_args = { # Key is the only required arg. Everything else is optional "key" => @local_key, # Always kill other running Browserstack Local instances "force" => "true", # We only want to enable local testing for automate "onlyAutomate" => "true", # Enable verbose logging. It's of no consequence to the tests, but it # could help in the event of errors "v" => "true", # Rather than "logfile" => File.join(Dir.pwd, "/tmp/bowerstack_local_log.txt") } return unless configuration.proxy.use_proxy? @local_testing_args["proxyHost"] = configuration.proxy.host @local_testing_args["proxyPort"] = configuration.proxy.port.to_s end
# File lib/quke/browserstack_configuration.rb, line 118 def validate_input_data(data) return {} if data.nil? return {} unless data["browserstack"] data["browserstack"] end