Module: SeleniumConnect

Extended by:
SeleniumConnect
Included in:
SeleniumConnect
Defined in:
lib/selenium-connect.rb,
lib/selenium-connect/runner.rb,
lib/selenium-connect/server.rb,
lib/selenium-connect/runners/ie.rb,
lib/selenium-connect/configuration.rb,
lib/selenium-connect/runners/chrome.rb,
lib/selenium-connect/runners/firefox.rb,
lib/selenium-connect/runners/phantomjs.rb,
lib/selenium-connect/runners/saucelabs.rb,
lib/selenium-connect/runners/no_browser.rb

Overview

Selenium Connect main module

Defined Under Namespace

Classes: Configuration, Runner, Server

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



14
15
16
# File 'lib/selenium-connect.rb', line 14

def config
  @config
end

#config_fileObject (readonly)

Returns the value of attribute config_file.



14
15
16
# File 'lib/selenium-connect.rb', line 14

def config_file
  @config_file
end

#driverObject (readonly)

Returns the value of attribute driver.



14
15
16
# File 'lib/selenium-connect.rb', line 14

def driver
  @driver
end

#locationObject (readonly)

Returns the value of attribute location.



14
15
16
# File 'lib/selenium-connect.rb', line 14

def location
  @location
end

#serverObject (readonly)

Returns the value of attribute server.



14
15
16
# File 'lib/selenium-connect.rb', line 14

def server
  @server
end

Instance Method Details

#configurationObject



20
21
22
# File 'lib/selenium-connect.rb', line 20

def configuration
  @config = Configuration.new
end

#configure {|configuration| ... } ⇒ Object

Yields:



16
17
18
# File 'lib/selenium-connect.rb', line 16

def configure
  yield configuration
end

#debug_configObject



28
29
30
# File 'lib/selenium-connect.rb', line 28

def debug_config
  config
end

#fetch_logsObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/selenium-connect.rb', line 57

def fetch_logs
  # this could be pulled out into the specific sauce runner
  job_id = driver.session_id
  sauce_client = Sauce::Client.new
  sauce_job = Sauce::Job.find(job_id)
  # poll while job is in progress
  while sauce_job.status == 'in progress'
    sleep 5
    sauce_job.refresh!
  end

  url = "#{sauce_client.api_url}jobs/#{job_id}/assets/selenium-server.log"
  response = RestClient::Request.new(
    method: :get,
    url: url
  ).execute

  log_file = File.join(Dir.getwd, config.log, "sauce_job_#{job_id}.log") if config.log

  File.open(log_file, 'w') do |log|
    log.write response
  end
  { sauce_job: sauce_job }
end

#finishObject Also known as: stop



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/selenium-connect.rb', line 40

def finish
  # TODO this should grow into a standardized artifact returned
  # by the driver
  return_data = {}
  begin
    driver.quit
    return_data = fetch_logs if config.host == 'saucelabs'
  # rubocop:disable HandleExceptions
  rescue Selenium::WebDriver::Error::WebDriverError
    # rubocop:enable HandleExceptions
    # no-op
  end
  server.stop if localhost?

  return_data
end

#localhost?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/selenium-connect.rb', line 24

def localhost?
  config.host == 'localhost'
end

#runObject Also known as: start



32
33
34
35
36
37
38
# File 'lib/selenium-connect.rb', line 32

def run
  if localhost?
    @server = Server.new(config)
    server.start
  end
  @driver = Runner.new(config).driver
end