Class: Appium::SauceLabs

Inherits:
Object
  • Object
show all
Defined in:
lib/appium_lib/sauce_labs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(appium_lib_opts) ⇒ Appium::SauceLabs

Create a SauceLabs instance to manage sauce labs related attributes.

Examples:


opts_blank = {}
sauce_labs_blank = Appium::SauceLabs.new(opts_blank)
sauce_labs_blank.username   #=> nil
sauce_labs_blank.access_key #=> nil
sauce_labs_blank.endpoint   #=> "ondemand.saucelabs.com:443/wd/hub"

opts = { sauce_username: "user-name",
         sauce_access_key: "access-key-to-sauce-labs",
         sauce_endpoint: "ondemand.other_saucelabs.com:443/wd/hub",
       }
sauce_labs = Appium::SauceLabs.new(opts)
sauce_labs.username   #=> "user-name"
sauce_labs.access_key #=> "access-key-to-sauce-labs"
sauce_labs.endpoint   #=> "ondemand.other-saucelabs.com:443/wd/hub"

Parameters:

  • appium_lib_opts (Hash)

    Appium library parameter



47
48
49
50
51
52
53
54
55
56
# File 'lib/appium_lib/sauce_labs.rb', line 47

def initialize(appium_lib_opts)
  @username   = appium_lib_opts.fetch :sauce_username, ENV.fetch('SAUCE_USERNAME', nil)
  @username   = nil if !@username || (@username.is_a?(String) && @username.empty?)

  @access_key = appium_lib_opts.fetch :sauce_access_key, ENV.fetch('SAUCE_ACCESS_KEY', nil)
  @access_key = nil if !@access_key || (@access_key.is_a?(String) && @access_key.empty?)

  @endpoint   = appium_lib_opts.fetch :sauce_endpoint, ENV.fetch('SAUCE_ENDPOINT', nil)
  @endpoint   = 'ondemand.saucelabs.com:443/wd/hub' if !@endpoint || (@endpoint.is_a?(String) && @endpoint.empty?)
end

Instance Attribute Details

#access_keyObject (readonly)

Access Key for use on Sauce Labs. Set ‘false` to disable Sauce, even when SAUCE_ACCESS_KEY is in ENV.



20
21
22
# File 'lib/appium_lib/sauce_labs.rb', line 20

def access_key
  @access_key
end

#endpointObject (readonly)

Override the Sauce Appium endpoint to allow e.g. TestObject tests. Default is ‘ondemand.saucelabs.com:443/wd/hub’.



22
23
24
# File 'lib/appium_lib/sauce_labs.rb', line 22

def endpoint
  @endpoint
end

#usernameObject (readonly)

Username for use on Sauce Labs. Set ‘false` to disable Sauce, even when SAUCE_USERNAME is in ENV.



18
19
20
# File 'lib/appium_lib/sauce_labs.rb', line 18

def username
  @username
end

Instance Method Details

#sauce_server_url?Boolean

Return true if an instance of Appium::SauceLabs has sauce_username and sauce_access_key.

Examples:


sauce_labs_blank.sauce_server_url? #=> false
sauce_labs.sauce_server_url?       #=> true

Returns:

  • (Boolean)


67
68
69
# File 'lib/appium_lib/sauce_labs.rb', line 67

def sauce_server_url?
  !username.nil? && !access_key.nil?
end

#server_urlString

Return a particular server url to access to. Default is the local address.

Examples:


sauce_labs_blank.server_url #=> "http://127.0.0.1:4723/wd/hub"
sauce_labs.server_url #=> "https://user-name:[email protected]:443/wd/hub"

Returns:

  • (String)


80
81
82
# File 'lib/appium_lib/sauce_labs.rb', line 80

def server_url
  sauce_server_url? ? "https://#{username}:#{access_key}@#{endpoint}" : 'http://127.0.0.1:4723/wd/hub'
end