Class: Janus::Screenshot

Inherits:
Object
  • Object
show all
Defined in:
lib/janus/screenshot.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parameters = {}) ⇒ Screenshot



25
26
27
28
# File 'lib/janus/screenshot.rb', line 25

def initialize(parameters = {})
  @test = parameters[:test]
  @image = parameters[:image]
end

Instance Attribute Details

#imageObject

Returns the value of attribute image.



6
7
8
# File 'lib/janus/screenshot.rb', line 6

def image
  @image
end

#testObject

Returns the value of attribute test.



6
7
8
# File 'lib/janus/screenshot.rb', line 6

def test
  @test
end

Class Method Details

.capture(test, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/janus/screenshot.rb', line 8

def self.capture(test, options = {})
  driver = Selenium::WebDriver.for(:remote, {
    url: "http://#{options[:username]}:#{options[:access_key]}@ondemand.saucelabs.com/wd/hub",
    desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome
  })
  driver.get(test.url)

  Screenshot.new(test: test, image: driver.screenshot_as(:png))
end

.load(test, options = {}) ⇒ Object



18
19
20
21
22
23
# File 'lib/janus/screenshot.rb', line 18

def self.load(test, options = {})
  path = File.join(options[:path], "#{test.name}.janus", 'screenshot.png')
  image = IO.read(path, mode: 'rb')

  Screenshot.new(test: test, image: image)
end

Instance Method Details

#save(path) ⇒ Object



30
31
32
33
34
35
# File 'lib/janus/screenshot.rb', line 30

def save(path)
  directory = File.join(path, "#{test.name}.janus")

  FileUtils.mkpath(directory) unless Dir.exists?(directory)
  IO.write(File.join(directory, 'screenshot.png'), @image, mode: 'wb')
end