Class: LooksGood::ImageFromElement

Inherits:
Image
  • Object
show all
Defined in:
lib/looks_good/image.rb

Instance Attribute Summary collapse

Attributes inherited from Image

#file_name, #path, #type

Instance Method Summary collapse

Methods inherited from Image

#exists?, #save

Constructor Details

#initialize(element, file_name) ⇒ ImageFromElement

Returns a new instance of ImageFromElement.



34
35
36
37
38
# File 'lib/looks_good/image.rb', line 34

def initialize(element, file_name)
  super(image, file_name)
  @element = element
  @image = capture_image
end

Instance Attribute Details

#imageObject

Returns the value of attribute image.



32
33
34
# File 'lib/looks_good/image.rb', line 32

def image
  @image
end

Instance Method Details

#verify_and_saveObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/looks_good/image.rb', line 40

def verify_and_save
  LooksGood::Configuration.max_no_tries.times do
    comparable = capture_image
    matches = LooksGood::Comparison.new(self,Image.new(comparable,@file_name)).matches?
    if matches
      self.save
      puts "Saved #{self.path} as reference"
      return()
    else
      @image = comparable  
    end  
  end
  raise 'Could not save a stable image. This could be due to animations or page load times. Saved a reference image, delete it to re-try'
end