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

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



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/mediawiki_selenium/remote_browser_factory.rb', line 20

def 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
end

Instance Method Details

#teardown(env, status) ⇒ Object

Submits status and Jenkins build info to Sauce Labs.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/mediawiki_selenium/remote_browser_factory.rb', line 44

def teardown(env, status)
  each do |browser|
    sid = browser.driver.session_id
    url = browser.driver.send(:bridge).http.send(:server_url)
    username = url.user
    key = url.password

    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
    )

    Cucumber::Formatter::Sauce.current_session_id = sid
  end
end