Class: IntegrationDiff::Runner

Inherits:
Object
  • Object
show all
Includes:
Capybara::DSL
Defined in:
lib/integration_diff/runner.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_name, javascript_driver) ⇒ Runner

Returns a new instance of Runner.



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/integration_diff/runner.rb', line 19

def initialize(project_name, javascript_driver)
  @project_name = project_name
  @javascript_driver = javascript_driver

  dir = IntegrationDiff::Utils.images_dir
  Dir.mkdir('tmp') unless Dir.exist?('tmp')
  Dir.mkdir(dir) unless Dir.exist?(dir)

  self.browser = 'firefox'
  self.device = 'desktop'
  self.os = 'linux'
end

Instance Attribute Details

#browserObject

Returns the value of attribute browser.



16
17
18
# File 'lib/integration_diff/runner.rb', line 16

def browser
  @browser
end

#browser_versionObject

Returns the value of attribute browser_version.



17
18
19
# File 'lib/integration_diff/runner.rb', line 17

def browser_version
  @browser_version
end

#deviceObject

Returns the value of attribute device.



16
17
18
# File 'lib/integration_diff/runner.rb', line 16

def device
  @device
end

#device_nameObject

Returns the value of attribute device_name.



17
18
19
# File 'lib/integration_diff/runner.rb', line 17

def device_name
  @device_name
end

#osObject

Returns the value of attribute os.



16
17
18
# File 'lib/integration_diff/runner.rb', line 16

def os
  @os
end

#os_versionObject

Returns the value of attribute os_version.



17
18
19
# File 'lib/integration_diff/runner.rb', line 17

def os_version
  @os_version
end

Class Method Details

.instanceObject



11
12
13
14
# File 'lib/integration_diff/runner.rb', line 11

def self.instance
  @runner ||= Runner.new(IntegrationDiff.project_name,
                         IntegrationDiff.javascript_driver)
end

Instance Method Details

#screenshot(identifier) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/integration_diff/runner.rb', line 51

def screenshot(identifier)
  raise 'no browser information provided' if browser.nil?
  raise 'no device information provided' if device.nil?
  raise 'no os information provided' if os.nil?

  screenshot_name = IntegrationDiff::Utils.image_file(identifier)
  page.save_screenshot(screenshot_name, full: true)
  @uploader.enqueue(identifier, browser, device, os, browser_version,
                    device_name, os_version)
end

#start_runObject

TODO: Improve error handling here for network timeouts



33
34
35
36
37
38
39
# File 'lib/integration_diff/runner.rb', line 33

def start_run
  draft_run
  @uploader = IntegrationDiff::Uploader.build(@run_id)
rescue StandardError => e
  IntegrationDiff.logger.fatal e.message
  raise e
end

#wrap_runObject

TODO: Improve error handling here for network timeouts



42
43
44
45
46
47
48
49
# File 'lib/integration_diff/runner.rb', line 42

def wrap_run
  @uploader.wrapup

  complete_run if @run_id
rescue StandardError => e
  IntegrationDiff.logger.fatal e.message
  raise e
end