Class: Quke::BrowserstackConfiguration
- Inherits:
-
Object
- Object
- Quke::BrowserstackConfiguration
- Defined in:
- lib/quke/browserstack_configuration.rb
Overview
Determines the configuration for browserstack, when selected as the driver
Instance Attribute Summary collapse
-
#auth_key ⇒ Object
readonly
To run your tests with browserstack you must provide a username and auth_key as a minimum.
-
#capabilities ⇒ Object
readonly
Capabilities are what configure the test in browserstack, for example what OS and browser to use.
-
#local_key ⇒ Object
readonly
To use local testing users must provide a key.
-
#local_testing_args ⇒ Object
readonly
Returns a hash of configurations values that will be passed to the
browserstack
local binary when its started. -
#username ⇒ Object
readonly
To run your tests with browserstack you must provide a username and auth_key as a minimum.
Instance Method Summary collapse
-
#initialize(configuration) ⇒ BrowserstackConfiguration
constructor
Initialize’s the instance based in the
Quke::Configuration
instance passed in. -
#test_locally? ⇒ Boolean
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. -
#url ⇒ Object
Returns a string representing the url used when running tests via Browserstack or nil.
-
#using_browserstack? ⇒ Boolean
Returns true if the driver was set
browserstack
, else false.
Constructor Details
#initialize(configuration) ⇒ BrowserstackConfiguration
Initialize’s the instance based in the Quke::Configuration
instance passed in. – rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity ++
51 52 53 54 55 56 57 58 59 |
# 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 |
Instance Attribute Details
#auth_key ⇒ Object (readonly)
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
14 15 16 |
# File 'lib/quke/browserstack_configuration.rb', line 14 def auth_key @auth_key end |
#capabilities ⇒ Object (readonly)
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
30 31 32 |
# File 'lib/quke/browserstack_configuration.rb', line 30 def capabilities @capabilities end |
#local_key ⇒ Object (readonly)
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
22 23 24 |
# File 'lib/quke/browserstack_configuration.rb', line 22 def local_key @local_key end |
#local_testing_args ⇒ Object (readonly)
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
43 44 45 |
# File 'lib/quke/browserstack_configuration.rb', line 43 def local_testing_args @local_testing_args end |
#username ⇒ Object (readonly)
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
14 15 16 |
# File 'lib/quke/browserstack_configuration.rb', line 14 def username @username end |
Instance Method Details
#test_locally? ⇒ Boolean
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.
68 69 70 |
# File 'lib/quke/browserstack_configuration.rb', line 68 def test_locally? @capabilities["browserstack.local"] == true && using_browserstack? end |
#url ⇒ Object
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:[email protected]/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:[email protected]/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
)
112 113 114 |
# File 'lib/quke/browserstack_configuration.rb', line 112 def url return "http://#{@username}:#{@auth_key}@hub.browserstack.com/wd/hub" unless @username == "" end |
#using_browserstack? ⇒ Boolean
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.
80 81 82 |
# File 'lib/quke/browserstack_configuration.rb', line 80 def using_browserstack? @using_browserstack end |