Module: MediawikiSelenium::RemoteBrowserFactory

Defined in:
lib/mediawiki_selenium/remote_browser_factory.rb

Overview

Constructs remote browser sessions to be run via Sauce Labs. Adds the following configuration bindings to the factory.

  • sauce_ondemand_username
  • sauce_ondemand_access_key
  • platform
  • version
  • device_name
  • device_orientation

Constant Summary collapse

REQUIRED_CONFIG =
[:sauce_ondemand_username, :sauce_ondemand_access_key]
URL =
'http://ondemand.saucelabs.com/wd/hub'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extend_object(base) ⇒ Object



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
# File 'lib/mediawiki_selenium/remote_browser_factory.rb', line 19

def self.extend_object(base)
  return if base.is_a?(self)

  super

  base.configure(:sauce_ondemand_username, :sauce_ondemand_access_key) do |user, key, options|
    options[:url] = URI.parse(URL)

    options[:url].user = user
    options[:url].password = key
  end

  base.configure(:platform) do |platform, options|
    options[:desired_capabilities].platform = platform
  end

  base.configure(:version) do |version, options|
    options[:desired_capabilities].version = version
  end

  base.configure(:device_name) do |device_name, options|
    options[:desired_capabilities]['deviceName'] = device_name
  end

  base.configure(:device_orientation) do |device_orientation, options|
    options[:desired_capabilities]['deviceOrientation'] = device_orientation
  end
end

Instance Method Details

#teardown(env, status) ⇒ Object

Submits status and Jenkins build info to Sauce Labs.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/mediawiki_selenium/remote_browser_factory.rb', line 50

def teardown(env, status)
  artifacts = super

  each do |browser|
    sid = browser.driver.session_id
    username = env.lookup(:sauce_ondemand_username)
    key = env.lookup(:sauce_ondemand_access_key)

    RestClient::Request.execute(
      method: :put,
      url: "https://saucelabs.com/rest/v1/#{username}/jobs/#{sid}",
      user: username,
      password: key,
      headers: { content_type: 'application/json' },
      payload: {
        public: true,
        passed: status == :passed,
        build: env.lookup(:build_number, default: nil)
      }.to_json
    )

    artifacts["http://saucelabs.com/jobs/#{sid}"] = 'text/url'
  end

  artifacts
end