Module: GreenOnion

Defined in:
lib/green_onion.rb,
lib/green_onion/cli.rb,
lib/green_onion/errors.rb,
lib/green_onion/browser.rb,
lib/green_onion/compare.rb,
lib/green_onion/version.rb,
lib/green_onion/screenshot.rb,
lib/green_onion/configuration.rb,
lib/green_onion/drivers/webkit.rb,
lib/green_onion/drivers/selenium.rb

Defined Under Namespace

Classes: Browser, CLI, Compare, Configuration, Errors, Screenshot, Selenium, Webkit

Constant Summary collapse

VERSION =
"0.1.4"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.compareObject (readonly)

Returns the value of attribute compare.



12
13
14
# File 'lib/green_onion.rb', line 12

def compare
  @compare
end

.screenshotObject (readonly)

Returns the value of attribute screenshot.



12
13
14
# File 'lib/green_onion.rb', line 12

def screenshot
  @screenshot
end

Class Method Details

.configurationObject



19
20
21
# File 'lib/green_onion.rb', line 19

def configuration
  @configuration ||= Configuration.new
end

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

Pass configure block to set Configuration object

Yields:



15
16
17
# File 'lib/green_onion.rb', line 15

def configure
  yield configuration
end

.skin(url) ⇒ Object

Bring the Screenshot and Compare classes together to create a skin



24
25
26
27
28
29
30
31
32
33
# File 'lib/green_onion.rb', line 24

def skin(url)
  @screenshot = Screenshot.new(
    :dir => @configuration.skins_dir,
    :skin_name => @configuration.skin_name,
    :browser => @configuration.browser
  )
  @compare = Compare.new

  @screenshot.test_screenshot(url)
end

.skin_percentage(url, threshold = @configuration.threshold) ⇒ Object

Finds the percentage of change between skins Threshold can be set in configuration, or as an argument itself, and can be specific to an instance



37
38
39
40
41
# File 'lib/green_onion.rb', line 37

def skin_percentage(url, threshold=@configuration.threshold)
  raise Errors::ThresholdOutOfRange.new "The threshold need to be a number between 1 and 100" if threshold > 100
  skin(url)
  skin_picker(url, { :percentage => true }, threshold)
end

.skin_picker(url, type, threshold = 100) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/green_onion.rb', line 56

def skin_picker(url, type, threshold=100)
  if(@screenshot.paths_hash.length > 1)
    puts "\n" + url.color(:cyan)
    if type[:percentage]
      @compare.percentage_diff(@screenshot.paths_hash[:original], @screenshot.paths_hash[:fresh])
      threshold_alert(@compare.percentage_changed, threshold)
    end
    if type[:visual]
      @compare.visual_diff(@screenshot.paths_hash[:original], @screenshot.paths_hash[:fresh])
    end
  else
    puts "\n#{url}".color(:cyan) + " has been saved to #{@screenshot.paths_hash[:original]}".color(:yellow)
  end
end

.skin_visual(url) ⇒ Object

Creates a diffed screenshot between skins



44
45
46
47
# File 'lib/green_onion.rb', line 44

def skin_visual(url)
  skin(url)
  skin_picker(url, { :visual => true })
end

.skin_visual_and_percentage(url, threshold = @configuration.threshold) ⇒ Object

Creates a diffed screenshot between skins AND prints percentage changed



50
51
52
53
54
# File 'lib/green_onion.rb', line 50

def skin_visual_and_percentage(url, threshold=@configuration.threshold)
  raise Errors::ThresholdOutOfRange.new "The threshold need to be a number between 1 and 100" if threshold > 100
  skin(url)
  skin_picker(url, { :percentage => true, :visual => true }, threshold)
end

.threshold_alert(actual, threshold) ⇒ Object

This is used in skin_percentage to better alert if a set of skins are ok or not



72
73
74
75
76
77
78
79
80
# File 'lib/green_onion.rb', line 72

def threshold_alert(actual, threshold)
  if actual > threshold
    $stderr.puts "#{actual - threshold}% above threshold set @ #{threshold}%".color(:red)
    $stderr.puts "pixels changed (%):     #{@compare.percentage_changed}%"
    $stderr.puts "pixels changed/total:  #{@compare.changed_px}/#{@compare.total_px}"
  else
    puts "pixels changed/total:  #{@compare.changed_px}/#{@compare.total_px}"
  end
end