5 changed files with 99 additions and 2 deletions
@ -0,0 +1,42 @@ |
|||||||
|
<!DOCTYPE html> |
||||||
|
<html> |
||||||
|
<head> |
||||||
|
<meta name="viewport" content="width=device-width"> |
||||||
|
<meta charset="utf-8"> |
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> |
||||||
|
<title>Diff with CSS Example</title> |
||||||
|
<style> |
||||||
|
body{ |
||||||
|
/*background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAHElEQVQYlWO4ePFiAzGY4eLFiw0MxIBRhVRRCADsljgKUbBKPgAAAABJRU5ErkJggg==) repeat;*/ |
||||||
|
} |
||||||
|
img{ |
||||||
|
height: 6in; |
||||||
|
} |
||||||
|
.diff { |
||||||
|
width: 4in; |
||||||
|
height: 6in; |
||||||
|
background-repeat: none, none; |
||||||
|
background-size: contain, contain; |
||||||
|
background-blend-mode: difference; |
||||||
|
display: inline-block; |
||||||
|
} |
||||||
|
|
||||||
|
</style> |
||||||
|
</head> |
||||||
|
<body> |
||||||
|
|
||||||
|
<% images.each_with_index do |(expected, actual), i| %> |
||||||
|
|
||||||
|
<img src="<%= expected %>"/> |
||||||
|
<img src="<%= actual %>"/> |
||||||
|
<style> |
||||||
|
.mine<%= i %> { |
||||||
|
background-image: url(<%= expected %>), url(<%= actual %>);" |
||||||
|
} |
||||||
|
</style> |
||||||
|
<div class="diff mine<%= i %>"/> |
||||||
|
|
||||||
|
<% end %> |
||||||
|
|
||||||
|
</body> |
||||||
|
</html> |
||||||
@ -0,0 +1,42 @@ |
|||||||
|
require 'launchy' |
||||||
|
require 'erb' |
||||||
|
require 'yaml' |
||||||
|
|
||||||
|
# An pixel-by-pixel comparison of sample images for visual regression testing |
||||||
|
class SanityTest |
||||||
|
|
||||||
|
@@ERB = "#{File.expand_path(File.dirname(__FILE__))}/sanity.html.erb" |
||||||
|
@@HTML = "#{File.expand_path(File.dirname(__FILE__))}/sanity.html" |
||||||
|
@@COMPARES = "#{File.expand_path(File.dirname(__FILE__))}/tests.yml" |
||||||
|
@@SAMPLES = "file:///#{File.expand_path("samples/")}" |
||||||
|
|
||||||
|
def images |
||||||
|
require 'pp' |
||||||
|
comps = YAML.load_file(@@COMPARES) |
||||||
|
pp comps |
||||||
|
comps.each do | test, data | |
||||||
|
pp data |
||||||
|
end |
||||||
|
[ |
||||||
|
["#{@@SAMPLES}/images/_images_00_expected.png", "#{@@SAMPLES}/images/_images_00.png"] |
||||||
|
] |
||||||
|
end |
||||||
|
|
||||||
|
def run |
||||||
|
puts @@SAMPLES |
||||||
|
puts 'Building sanity test...' |
||||||
|
process_erb(File.read(@@ERB)) |
||||||
|
Launchy.open('file:///' + @@HTML) |
||||||
|
puts 'Done.' |
||||||
|
end |
||||||
|
|
||||||
|
private |
||||||
|
|
||||||
|
def process_erb(sanity_template) |
||||||
|
renderer = ERB.new(sanity_template) |
||||||
|
File.open(@@HTML, 'w+') do |html| |
||||||
|
html.write(renderer.result(binding)) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
end |
||||||
Loading…
Reference in new issue