compatriot 0.1.9 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -7
- data/README.md +17 -14
- data/compatriot.gemspec +2 -3
- data/lib/compatriot.rb +1 -7
- data/lib/compatriot/version.rb +1 -1
- data/spec/spec_helper.rb +0 -16
- metadata +19 -51
- data/examples/compatriot_tests.rb +0 -9
- data/lib/compatriot/browser.rb +0 -82
- data/lib/compatriot/results_presenter.rb +0 -63
- data/lib/compatriot/runner.rb +0 -65
- data/spec/sample_app/public/images/smileyface.jpg +0 -0
- data/spec/sample_app/sample_app.rb +0 -21
- data/spec/unit/browser_spec.rb +0 -171
- data/spec/unit/runner_spec.rb +0 -64
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cca323e412f69789efb783d7b5fdea2aba03529e
|
4
|
+
data.tar.gz: e526df240f719b44c9f82c25a0b8fe38d621750e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4921fc720a06dd3a686999a8ac282691087f001eb5d2927d93e77ee0e476eaa35b4a5bff370a91a714d06753b574218f23be31c4a9edb5a011e3dd0cca64149d
|
7
|
+
data.tar.gz: 49f95b9f7a9760fcf6c7d29480468167e9f34610f956ad0b3bb4a09a2cef40160c89b1a2977919e2f82b42326f13a5a5856e3fc9a10075924e9455128392088a
|
data/.travis.yml
CHANGED
@@ -1,10 +1,3 @@
|
|
1
|
-
before_script:
|
2
|
-
- "mkdir -p /tmp/bin"
|
3
|
-
- "cd /tmp/bin && wget http://chromium.googlecode.com/files/chromedriver_linux32_16.0.902.0.zip && unzip chromedriver_linux32_16.0.902.0.zip && cd -"
|
4
|
-
- "export PATH=/tmp/bin:$PATH "
|
5
|
-
- "export DISPLAY=:99.0"
|
6
|
-
- "sh -e /etc/init.d/xvfb start"
|
7
|
-
- sleep 3 # give xvfb some time to start
|
8
1
|
script: "bundle exec rake test"
|
9
2
|
rvm:
|
10
3
|
- 2.1.7
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Compatriot
|
2
2
|
==========
|
3
|
-
[![Build Status](https://secure.travis-ci.org/
|
3
|
+
[![Build Status](https://secure.travis-ci.org/compatriot/compatriot.png?branch=master)](http://travis-ci.org/compatriot/compatriot)
|
4
4
|
|
5
5
|
**Compat**ibility + **riot**! It's the **friend** that helps with browser compatibility!
|
6
6
|
This Ruby gem makes cross-browser testing less painful.
|
@@ -12,8 +12,7 @@ Don't let your users find the inconsistencies and get to them first.
|
|
12
12
|
What it does now
|
13
13
|
----------------
|
14
14
|
|
15
|
-
*
|
16
|
-
* Adds a `assert_no_ui_changes` method to your tests
|
15
|
+
* Adds a `assert_no_ui_changes` method to your test assertions
|
17
16
|
* When called from your tests, it takes a screenshot and compares it to a control image to get percentage difference
|
18
17
|
* If the difference is greater then the threshold, it fails the tests
|
19
18
|
* Pairs well with [BrowserStacks automation feature](browserstack.com/automate) to run across many environments
|
@@ -21,14 +20,10 @@ What it does now
|
|
21
20
|
What it will do in the future
|
22
21
|
-----------------------------
|
23
22
|
|
24
|
-
* Have more documentation (a start is [on RelishApp](https://www.relishapp.com/clnclarinet/compatriot)!)
|
25
23
|
* Have a screenshot of sample results in the README
|
26
24
|
* Have more and better tests
|
27
|
-
* Find the largest, darkest contiguous region in the image diff and have a threshold of pass/fail based on that
|
28
25
|
* Perform better on the image processing (by sampling/resizing, using oily_png, etc)
|
29
|
-
*
|
30
|
-
* Steal some of VCR's relish rake tasks
|
31
|
-
|
26
|
+
* Show a better image difference
|
32
27
|
|
33
28
|
How To Use
|
34
29
|
----------
|
@@ -68,15 +63,25 @@ How To Use
|
|
68
63
|
```ruby
|
69
64
|
it 'does not break the ui' do
|
70
65
|
visit some_page_path
|
71
|
-
assert_no_ui_changes
|
66
|
+
assert_no_ui_changes
|
72
67
|
end
|
73
68
|
```
|
74
69
|
|
75
70
|
The first time through it will create the control image in `#{screenshot_directory}/control`. You should then review the screenshots and check them into source control as your baseline.
|
76
|
-
Every run after that, it will take a variable image screenshot in `#{screenshot_directory}/variable` and a difference image in `#{screenshot_directory}/diffs`.
|
71
|
+
Every run after that, it will take a variable image screenshot in `#{screenshot_directory}/variable` and generate a difference image in `#{screenshot_directory}/diffs`.
|
77
72
|
|
78
73
|
`assert_no_ui_changes` takes an optional string parameter to allow you to make multiple assertions in a test and not run into name conflicts.
|
79
74
|
|
75
|
+
example:
|
76
|
+
```ruby
|
77
|
+
it 'has multiple ui change assertions' do
|
78
|
+
visit page_1
|
79
|
+
assert_no_ui_changes 'page 1'
|
80
|
+
visit page_2
|
81
|
+
assert_no_ui_changes 'page 2'
|
82
|
+
end
|
83
|
+
```
|
84
|
+
|
80
85
|
To see the % difference for every assertion, and get the path the the difference, set `config.show_diffs = true` when you configure Compatriot.
|
81
86
|
|
82
87
|
|
@@ -86,6 +91,7 @@ How to run this against multiple environments?
|
|
86
91
|
The intentions for running this against multiple environments is that you would run your test suite once for every environment you wish to run it against.
|
87
92
|
To accomplish this, you should set your `screenshot_directory` to include the current environment name, this way you will store your control images in separate directories.
|
88
93
|
|
94
|
+
*Note: The configuration example above shows you how to set the directory using the specified capabilities.*
|
89
95
|
|
90
96
|
What to do to run its tests
|
91
97
|
---------------------------
|
@@ -105,7 +111,7 @@ How You Can Contribute
|
|
105
111
|
|
106
112
|
We'd really like to know if something is wrong, so please file an issue on the Issue List if you have a problem, suggestion, unsupported use case, etc.
|
107
113
|
|
108
|
-
|
114
|
+
There are many opportunities for improvement. Feel free to:
|
109
115
|
|
110
116
|
* **Fork** the repository
|
111
117
|
* **Clone the repository** locally, or **edit via Github**
|
@@ -126,9 +132,6 @@ Many thanks to the wonderful libraries that make this gem possible:
|
|
126
132
|
* [selenium-webdriver](http://seleniumhq.org/docs/01_introducing_selenium.html#selenium-2-aka-selenium-webdriver)
|
127
133
|
* [chunky_png](https://github.com/wvanbergen/chunky_png) (and especially [this blog post about using chunky_png to create image diffs](http://jeffkreeftmeijer.com/2011/comparing-images-and-creating-image-diffs/?utm_source=rubyweekly&utm_medium=email) by Jeff Kreeftmeijer)
|
128
134
|
* [travis](http://travis-ci.org/) for CI
|
129
|
-
* [relishapp](https://www.relishapp.com/) for documentation
|
130
|
-
* [vcr](https://github.com/myronmarston/vcr) for having such awesome documentation that it inspired me to use Relishapp
|
131
|
-
|
132
135
|
|
133
136
|
Contributors
|
134
137
|
------------
|
data/compatriot.gemspec
CHANGED
@@ -21,13 +21,12 @@ Gem::Specification.new do |gem|
|
|
21
21
|
|
22
22
|
gem.add_development_dependency 'minitest', '~> 5.8', '>= 5.8.2'
|
23
23
|
gem.add_development_dependency 'minitest-reporters', '~> 1.1', '>= 1.1.8'
|
24
|
-
gem.add_development_dependency 'sinatra', '~> 1.4', '>= 1.4.6'
|
25
24
|
gem.add_development_dependency 'mocha', '~> 1.1', '>= 1.1.0'
|
26
25
|
gem.add_development_dependency 'pry'
|
26
|
+
gem.add_development_dependency 'rake', '~> 10.4', '>= 10.4.2'
|
27
|
+
gem.add_development_dependency 'rack', '~> 1.6', '>= 1.6.5'
|
27
28
|
|
28
29
|
gem.add_runtime_dependency 'capybara', '~> 2.5', '>= 2.5.0'
|
29
|
-
gem.add_runtime_dependency 'selenium-webdriver', '~> 2.48', '>= 2.48.1'
|
30
|
-
gem.add_runtime_dependency 'rake', '~> 10.4', '>= 10.4.2'
|
31
30
|
gem.add_runtime_dependency 'chunky_png', '~> 1.3', '>= 1.3.5'
|
32
31
|
gem.add_runtime_dependency 'oily_png', '~> 1.2.0'
|
33
32
|
gem.add_runtime_dependency 'haml', '~> 4.0.7'
|
data/lib/compatriot.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
require "compatriot/assertions"
|
2
2
|
require "compatriot/version"
|
3
|
-
require "compatriot/runner"
|
4
|
-
require "compatriot/browser"
|
5
|
-
require "compatriot/results_presenter"
|
6
3
|
require "compatriot/image_differ/image_differ"
|
7
4
|
require "compatriot/minitest_report_driver"
|
5
|
+
require "capybara"
|
8
6
|
|
9
7
|
module Compatriot
|
10
8
|
class << self
|
@@ -16,10 +14,6 @@ module Compatriot
|
|
16
14
|
yield self
|
17
15
|
end
|
18
16
|
|
19
|
-
def run(paths)
|
20
|
-
Compatriot::Runner.start(app, paths)
|
21
|
-
end
|
22
|
-
|
23
17
|
def take_screenshot(test, description)
|
24
18
|
filename = filename_for_test(test, description)
|
25
19
|
control_image_path = filepath_for_screenshot('control', filename)
|
data/lib/compatriot/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -6,23 +6,8 @@ require "mocha/mini_test"
|
|
6
6
|
|
7
7
|
require 'compatriot'
|
8
8
|
|
9
|
-
require_relative "sample_app/sample_app"
|
10
|
-
|
11
9
|
SCREENSHOTS_DIR = './tmp/test/screenshots'
|
12
10
|
|
13
|
-
# A custom runner to enable before_suite and after_suite setup/teardown.
|
14
|
-
# http://bfts.rubyforge.org/minitest/index.html
|
15
|
-
# Only using it to delete the screenshots that result from running the tests
|
16
|
-
# before running the suite; it's useful to be able to look at the screenshots
|
17
|
-
# after a test run so we're not deleting them then.
|
18
|
-
|
19
|
-
module TestRunner
|
20
|
-
def before_setup
|
21
|
-
super
|
22
|
-
FileUtils.remove_dir(File.join("sample_app", "tmp", "results"), true)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
11
|
module FakeCapybara
|
27
12
|
def self.current_session
|
28
13
|
Page.new
|
@@ -42,7 +27,6 @@ class Page
|
|
42
27
|
end
|
43
28
|
|
44
29
|
class Minitest::Spec
|
45
|
-
include TestRunner
|
46
30
|
include Compatriot::Assertions
|
47
31
|
Compatriot.configure do |config|
|
48
32
|
config.screenshot_directory = SCREENSHOTS_DIR
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: compatriot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carol (Nichols || Goulding)
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-01-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|
@@ -51,26 +51,6 @@ dependencies:
|
|
51
51
|
- - ">="
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: 1.1.8
|
54
|
-
- !ruby/object:Gem::Dependency
|
55
|
-
name: sinatra
|
56
|
-
requirement: !ruby/object:Gem::Requirement
|
57
|
-
requirements:
|
58
|
-
- - "~>"
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: '1.4'
|
61
|
-
- - ">="
|
62
|
-
- !ruby/object:Gem::Version
|
63
|
-
version: 1.4.6
|
64
|
-
type: :development
|
65
|
-
prerelease: false
|
66
|
-
version_requirements: !ruby/object:Gem::Requirement
|
67
|
-
requirements:
|
68
|
-
- - "~>"
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
version: '1.4'
|
71
|
-
- - ">="
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
version: 1.4.6
|
74
54
|
- !ruby/object:Gem::Dependency
|
75
55
|
name: mocha
|
76
56
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,65 +86,65 @@ dependencies:
|
|
106
86
|
- !ruby/object:Gem::Version
|
107
87
|
version: '0'
|
108
88
|
- !ruby/object:Gem::Dependency
|
109
|
-
name:
|
89
|
+
name: rake
|
110
90
|
requirement: !ruby/object:Gem::Requirement
|
111
91
|
requirements:
|
112
92
|
- - "~>"
|
113
93
|
- !ruby/object:Gem::Version
|
114
|
-
version: '
|
94
|
+
version: '10.4'
|
115
95
|
- - ">="
|
116
96
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
118
|
-
type: :
|
97
|
+
version: 10.4.2
|
98
|
+
type: :development
|
119
99
|
prerelease: false
|
120
100
|
version_requirements: !ruby/object:Gem::Requirement
|
121
101
|
requirements:
|
122
102
|
- - "~>"
|
123
103
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
104
|
+
version: '10.4'
|
125
105
|
- - ">="
|
126
106
|
- !ruby/object:Gem::Version
|
127
|
-
version:
|
107
|
+
version: 10.4.2
|
128
108
|
- !ruby/object:Gem::Dependency
|
129
|
-
name:
|
109
|
+
name: rack
|
130
110
|
requirement: !ruby/object:Gem::Requirement
|
131
111
|
requirements:
|
132
112
|
- - "~>"
|
133
113
|
- !ruby/object:Gem::Version
|
134
|
-
version: '
|
114
|
+
version: '1.6'
|
135
115
|
- - ">="
|
136
116
|
- !ruby/object:Gem::Version
|
137
|
-
version:
|
138
|
-
type: :
|
117
|
+
version: 1.6.5
|
118
|
+
type: :development
|
139
119
|
prerelease: false
|
140
120
|
version_requirements: !ruby/object:Gem::Requirement
|
141
121
|
requirements:
|
142
122
|
- - "~>"
|
143
123
|
- !ruby/object:Gem::Version
|
144
|
-
version: '
|
124
|
+
version: '1.6'
|
145
125
|
- - ">="
|
146
126
|
- !ruby/object:Gem::Version
|
147
|
-
version:
|
127
|
+
version: 1.6.5
|
148
128
|
- !ruby/object:Gem::Dependency
|
149
|
-
name:
|
129
|
+
name: capybara
|
150
130
|
requirement: !ruby/object:Gem::Requirement
|
151
131
|
requirements:
|
152
132
|
- - "~>"
|
153
133
|
- !ruby/object:Gem::Version
|
154
|
-
version: '
|
134
|
+
version: '2.5'
|
155
135
|
- - ">="
|
156
136
|
- !ruby/object:Gem::Version
|
157
|
-
version:
|
137
|
+
version: 2.5.0
|
158
138
|
type: :runtime
|
159
139
|
prerelease: false
|
160
140
|
version_requirements: !ruby/object:Gem::Requirement
|
161
141
|
requirements:
|
162
142
|
- - "~>"
|
163
143
|
- !ruby/object:Gem::Version
|
164
|
-
version: '
|
144
|
+
version: '2.5'
|
165
145
|
- - ">="
|
166
146
|
- !ruby/object:Gem::Version
|
167
|
-
version:
|
147
|
+
version: 2.5.0
|
168
148
|
- !ruby/object:Gem::Dependency
|
169
149
|
name: chunky_png
|
170
150
|
requirement: !ruby/object:Gem::Requirement
|
@@ -232,30 +212,22 @@ files:
|
|
232
212
|
- Rakefile
|
233
213
|
- bin/colordiff
|
234
214
|
- compatriot.gemspec
|
235
|
-
- examples/compatriot_tests.rb
|
236
215
|
- lib/compatriot.rb
|
237
216
|
- lib/compatriot/assertions.rb
|
238
|
-
- lib/compatriot/browser.rb
|
239
217
|
- lib/compatriot/image_differ/color_differ.rb
|
240
218
|
- lib/compatriot/image_differ/image_differ.rb
|
241
219
|
- lib/compatriot/minitest_report_driver.rb
|
242
220
|
- lib/compatriot/report_template.html.haml
|
243
221
|
- lib/compatriot/reporter.rb
|
244
|
-
- lib/compatriot/results_presenter.rb
|
245
|
-
- lib/compatriot/runner.rb
|
246
222
|
- lib/compatriot/version.rb
|
247
223
|
- spec/images/1.png
|
248
224
|
- spec/images/2.png
|
249
|
-
- spec/sample_app/public/images/smileyface.jpg
|
250
|
-
- spec/sample_app/sample_app.rb
|
251
225
|
- spec/spec_helper.rb
|
252
226
|
- spec/unit/assertions_spec.rb
|
253
|
-
- spec/unit/browser_spec.rb
|
254
227
|
- spec/unit/compatriot_spec.rb
|
255
228
|
- spec/unit/image_differ/color_differ_spec.rb
|
256
229
|
- spec/unit/image_differ/image_differ_spec.rb
|
257
230
|
- spec/unit/report_spec.rb
|
258
|
-
- spec/unit/runner_spec.rb
|
259
231
|
homepage: https://github.com/carols10cents/compatriot
|
260
232
|
licenses:
|
261
233
|
- MIT
|
@@ -285,13 +257,9 @@ summary: Add assertions that screenshots taken during your tests do not differ f
|
|
285
257
|
test_files:
|
286
258
|
- spec/images/1.png
|
287
259
|
- spec/images/2.png
|
288
|
-
- spec/sample_app/public/images/smileyface.jpg
|
289
|
-
- spec/sample_app/sample_app.rb
|
290
260
|
- spec/spec_helper.rb
|
291
261
|
- spec/unit/assertions_spec.rb
|
292
|
-
- spec/unit/browser_spec.rb
|
293
262
|
- spec/unit/compatriot_spec.rb
|
294
263
|
- spec/unit/image_differ/color_differ_spec.rb
|
295
264
|
- spec/unit/image_differ/image_differ_spec.rb
|
296
265
|
- spec/unit/report_spec.rb
|
297
|
-
- spec/unit/runner_spec.rb
|
data/lib/compatriot/browser.rb
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
require "fileutils"
|
2
|
-
require 'capybara/dsl'
|
3
|
-
|
4
|
-
module Compatriot
|
5
|
-
class Browser
|
6
|
-
include Capybara::DSL
|
7
|
-
|
8
|
-
def self.create_browsers(params = {})
|
9
|
-
params[:browser_names].collect do |b|
|
10
|
-
Compatriot::Browser.new(
|
11
|
-
:name => b,
|
12
|
-
:screenshot_directory => params[:results_directory]
|
13
|
-
)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
attr_reader :name
|
18
|
-
|
19
|
-
def initialize(params = {})
|
20
|
-
@name = params[:name]
|
21
|
-
@screenshot_directory = params[:screenshot_directory]
|
22
|
-
@screenshot_locations = {}
|
23
|
-
|
24
|
-
create_screenshot_path
|
25
|
-
end
|
26
|
-
|
27
|
-
def screenshot_path
|
28
|
-
File.join(@screenshot_directory, @name)
|
29
|
-
end
|
30
|
-
|
31
|
-
def initialize_capybara(app)
|
32
|
-
driver = "selenium_#{@name}".to_sym
|
33
|
-
Capybara.register_driver driver do |a|
|
34
|
-
Capybara::Selenium::Driver.new(a, :browser => @name.to_sym)
|
35
|
-
end
|
36
|
-
Capybara.default_driver = driver
|
37
|
-
Capybara.app = app
|
38
|
-
end
|
39
|
-
|
40
|
-
def take_screenshots(params = {})
|
41
|
-
initialize_capybara(params[:app])
|
42
|
-
params[:paths].map { |path| take_screenshot(path) }
|
43
|
-
|
44
|
-
# Reset the selenium session to avoid timeout errors
|
45
|
-
Capybara.send(:session_pool).delete_if { |key, value| key =~ /selenium/i }
|
46
|
-
end
|
47
|
-
|
48
|
-
def absolute_screenshot_for(path)
|
49
|
-
if @screenshot_locations[path]
|
50
|
-
absolute_dir(@screenshot_locations[path])
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def relative_screenshot_for(path)
|
55
|
-
if @screenshot_locations[path]
|
56
|
-
File.join(name, @screenshot_locations[path])
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def take_screenshot(path)
|
61
|
-
visit path
|
62
|
-
filename = next_filename
|
63
|
-
Capybara.page.driver.browser.save_screenshot(absolute_dir(filename))
|
64
|
-
@screenshot_locations[path] = filename
|
65
|
-
end
|
66
|
-
|
67
|
-
private
|
68
|
-
|
69
|
-
def absolute_dir(filename)
|
70
|
-
File.join(screenshot_path, filename)
|
71
|
-
end
|
72
|
-
|
73
|
-
def next_filename
|
74
|
-
@file_id = (@file_id && @file_id + 1) || 1
|
75
|
-
"#{@file_id}.png"
|
76
|
-
end
|
77
|
-
|
78
|
-
def create_screenshot_path
|
79
|
-
FileUtils.mkdir_p(screenshot_path)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
require 'erb'
|
2
|
-
|
3
|
-
module Compatriot
|
4
|
-
class ResultsPresenter
|
5
|
-
def initialize(results_directory)
|
6
|
-
@results_directory = results_directory
|
7
|
-
end
|
8
|
-
|
9
|
-
def make_index_page(params = {})
|
10
|
-
index_page_file = File.join(@results_directory, "index.html")
|
11
|
-
|
12
|
-
b = binding
|
13
|
-
paths = params[:paths]
|
14
|
-
browsers = params[:browsers]
|
15
|
-
differ = params[:differ]
|
16
|
-
|
17
|
-
html = ERB.new <<-EOF
|
18
|
-
<html>
|
19
|
-
<head>
|
20
|
-
<title>Cross browser test results</title>
|
21
|
-
<style type='text/css'>
|
22
|
-
table, tr, th, td {
|
23
|
-
border: 1px solid #aaa;
|
24
|
-
}
|
25
|
-
img {
|
26
|
-
width: 300px;
|
27
|
-
}
|
28
|
-
</style>
|
29
|
-
</head>
|
30
|
-
<body>
|
31
|
-
<h1>Results</h1>
|
32
|
-
<table>
|
33
|
-
<tr>
|
34
|
-
<th>Path</th>
|
35
|
-
<% browsers.each do |browser| %>
|
36
|
-
<th><%= browser.name %></th>
|
37
|
-
<% end %>
|
38
|
-
<th>Diff</th>
|
39
|
-
</tr>
|
40
|
-
<% paths.each do |path| %>
|
41
|
-
<tr>
|
42
|
-
<td>
|
43
|
-
<%= path %>
|
44
|
-
</td>
|
45
|
-
<% browsers.each do |browser| %>
|
46
|
-
<td>
|
47
|
-
<img src="<%= browser.relative_screenshot_for(path) %>" />
|
48
|
-
</td>
|
49
|
-
<% end %>
|
50
|
-
<td>
|
51
|
-
<img src="<%= differ.diff_for(path) %>" />
|
52
|
-
</td>
|
53
|
-
</tr>
|
54
|
-
<% end %>
|
55
|
-
</table>
|
56
|
-
</body>
|
57
|
-
</html>
|
58
|
-
EOF
|
59
|
-
|
60
|
-
File.open(index_page_file, 'w') {|f| f.write(html.result(b)) }
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
data/lib/compatriot/runner.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'date'
|
3
|
-
|
4
|
-
module Compatriot
|
5
|
-
class Runner
|
6
|
-
def self.start(app, paths, clock = DateTime)
|
7
|
-
runner = new(app, paths, clock)
|
8
|
-
runner.create_results_directory
|
9
|
-
runner.take_screenshots
|
10
|
-
runner.compute_diffs
|
11
|
-
runner.make_index_page
|
12
|
-
runner
|
13
|
-
end
|
14
|
-
|
15
|
-
BROWSERS = ["firefox", "chrome"]
|
16
|
-
|
17
|
-
attr_reader :app, :results_directory
|
18
|
-
|
19
|
-
def initialize(app, paths, clock)
|
20
|
-
@app = app
|
21
|
-
@paths = paths
|
22
|
-
@clock = clock
|
23
|
-
|
24
|
-
timestamp = @clock.now.strftime("%Y-%m-%d-%H-%M-%S")
|
25
|
-
@results_directory = File.join("tmp", "results", timestamp)
|
26
|
-
|
27
|
-
@browsers = Compatriot::Browser.create_browsers(
|
28
|
-
:browser_names => BROWSERS,
|
29
|
-
:results_directory => @results_directory
|
30
|
-
)
|
31
|
-
end
|
32
|
-
|
33
|
-
def take_screenshots
|
34
|
-
@browsers.each do |browser_object|
|
35
|
-
browser_object.take_screenshots(
|
36
|
-
:app => @app,
|
37
|
-
:paths => @paths
|
38
|
-
)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def compute_diffs
|
43
|
-
@differ = Compatriot::ImageDiffer.new(
|
44
|
-
:paths => @paths,
|
45
|
-
:browsers => @browsers,
|
46
|
-
:strategy => Compatriot::ColorDiffer,
|
47
|
-
:results_directory => @results_directory
|
48
|
-
)
|
49
|
-
@differ.compute!
|
50
|
-
end
|
51
|
-
|
52
|
-
def make_index_page
|
53
|
-
presenter = Compatriot::ResultsPresenter.new(@results_directory)
|
54
|
-
presenter.make_index_page(
|
55
|
-
:paths => @paths,
|
56
|
-
:browsers => @browsers,
|
57
|
-
:differ => @differ
|
58
|
-
)
|
59
|
-
end
|
60
|
-
|
61
|
-
def create_results_directory
|
62
|
-
FileUtils.mkdir_p(@results_directory)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
Binary file
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'sinatra/base'
|
2
|
-
require 'rack'
|
3
|
-
require 'yaml'
|
4
|
-
|
5
|
-
class SampleApp < Sinatra::Base
|
6
|
-
set :root, File.dirname(__FILE__)
|
7
|
-
set :static, true
|
8
|
-
|
9
|
-
get '/' do
|
10
|
-
"<h1>Hello world!</h1><div><a href='chrome-css-bug'>Try another page</a></div>"
|
11
|
-
end
|
12
|
-
|
13
|
-
get "/chrome-css-bug" do
|
14
|
-
"<table><tr style='background: url(/images/smileyface.jpg) no-repeat;'><td style='padding:30px;'>One</td><td style='padding:30px;'>Two</td></tr></table>"
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
if __FILE__ == $0
|
20
|
-
Rack::Handler::WEBrick.run SampleApp, :Port => 8070
|
21
|
-
end
|
data/spec/unit/browser_spec.rb
DELETED
@@ -1,171 +0,0 @@
|
|
1
|
-
require_relative '../spec_helper'
|
2
|
-
|
3
|
-
describe Compatriot::Browser do
|
4
|
-
describe "self#create_browsers" do
|
5
|
-
it "creates a browser object for each browser name given to it" do
|
6
|
-
browsers = ["linx", "dolphin HD"] # Selenium totally doesn't work w/these
|
7
|
-
fake_directory = "/some/location"
|
8
|
-
|
9
|
-
linx = stub
|
10
|
-
dolphin = stub
|
11
|
-
|
12
|
-
Compatriot::Browser.expects(:new).with(
|
13
|
-
:name => "linx",
|
14
|
-
:screenshot_directory => fake_directory
|
15
|
-
).returns(linx)
|
16
|
-
|
17
|
-
Compatriot::Browser.expects(:new).with(
|
18
|
-
:name => "dolphin HD",
|
19
|
-
:screenshot_directory => fake_directory
|
20
|
-
).returns(dolphin)
|
21
|
-
|
22
|
-
results = Compatriot::Browser.create_browsers(
|
23
|
-
:browser_names => browsers,
|
24
|
-
:results_directory => fake_directory
|
25
|
-
)
|
26
|
-
results.must_equal([linx, dolphin])
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe "initialize_capybara" do
|
31
|
-
before do
|
32
|
-
Compatriot::Browser.any_instance.stubs(:create_screenshot_path)
|
33
|
-
@b = Compatriot::Browser.new(
|
34
|
-
:name => "foo",
|
35
|
-
:screenshot_directory => "bar"
|
36
|
-
)
|
37
|
-
end
|
38
|
-
|
39
|
-
it "registers a new driver" do
|
40
|
-
Capybara.expects(:register_driver).with(:selenium_foo)
|
41
|
-
|
42
|
-
@b.initialize_capybara(stub)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "sets this driver as the default" do
|
46
|
-
Capybara.expects(:default_driver=).with(:selenium_foo)
|
47
|
-
|
48
|
-
@b.initialize_capybara(stub)
|
49
|
-
end
|
50
|
-
|
51
|
-
it "sets the Capybara app" do
|
52
|
-
app = stub
|
53
|
-
Capybara.expects(:app=).with(app)
|
54
|
-
|
55
|
-
@b.initialize_capybara(app)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe "take_screenshots" do
|
60
|
-
before do
|
61
|
-
Compatriot::Browser.any_instance.stubs(:create_screenshot_path)
|
62
|
-
@b = Compatriot::Browser.new(
|
63
|
-
:name => "foo",
|
64
|
-
:screenshot_directory => "bar"
|
65
|
-
)
|
66
|
-
end
|
67
|
-
|
68
|
-
it "calls initialize_capybara once and take_screenshot for each path" do
|
69
|
-
app = stub
|
70
|
-
@b.expects(:initialize_capybara).with(app)
|
71
|
-
|
72
|
-
@b.expects(:take_screenshot).with("/")
|
73
|
-
@b.expects(:take_screenshot).with("/contact")
|
74
|
-
|
75
|
-
@b.take_screenshots(
|
76
|
-
:app => app,
|
77
|
-
:paths => ["/", "/contact"]
|
78
|
-
)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
describe "take_screenshot" do
|
83
|
-
before do
|
84
|
-
Compatriot::Browser.any_instance.stubs(:create_screenshot_path)
|
85
|
-
@b = Compatriot::Browser.new(
|
86
|
-
:name => "foo",
|
87
|
-
:screenshot_directory => "bar"
|
88
|
-
)
|
89
|
-
app = stub
|
90
|
-
@b.initialize_capybara(app)
|
91
|
-
end
|
92
|
-
|
93
|
-
it "visits the path" do
|
94
|
-
@b.expects(:visit).with("/some_page")
|
95
|
-
|
96
|
-
capybara_browser = stub
|
97
|
-
capybara_browser.stubs(:save_screenshot)
|
98
|
-
Capybara.page.driver.stubs(:browser).returns(capybara_browser)
|
99
|
-
|
100
|
-
@b.take_screenshot("/some_page")
|
101
|
-
end
|
102
|
-
|
103
|
-
it "tells capybara to take a screenshot" do
|
104
|
-
@b.stubs(:visit)
|
105
|
-
|
106
|
-
@b.stubs(:next_filename).returns("/where_to_save")
|
107
|
-
capybara_browser = stub
|
108
|
-
capybara_browser.expects(:save_screenshot).with("bar/foo/where_to_save")
|
109
|
-
Capybara.page.driver.stubs(:browser).returns(capybara_browser)
|
110
|
-
|
111
|
-
@b.take_screenshot("/some_page")
|
112
|
-
end
|
113
|
-
|
114
|
-
it "increments the filenames" do
|
115
|
-
@b.stubs(:visit)
|
116
|
-
|
117
|
-
capybara_browser = stub
|
118
|
-
capybara_browser.stubs(:save_screenshot)
|
119
|
-
Capybara.page.driver.stubs(:browser).returns(capybara_browser)
|
120
|
-
|
121
|
-
@b.take_screenshot("/some_page")
|
122
|
-
@b.take_screenshot("/some_other_page")
|
123
|
-
|
124
|
-
@b.relative_screenshot_for("/some_page").must_equal("foo/1.png")
|
125
|
-
@b.relative_screenshot_for("/some_other_page").must_equal("foo/2.png")
|
126
|
-
end
|
127
|
-
|
128
|
-
end
|
129
|
-
|
130
|
-
describe "relative_screenshot_for" do
|
131
|
-
before do
|
132
|
-
Compatriot::Browser.any_instance.stubs(:create_screenshot_path)
|
133
|
-
@b = Compatriot::Browser.new(
|
134
|
-
:name => "foo",
|
135
|
-
:screenshot_directory => "bar"
|
136
|
-
)
|
137
|
-
app = stub
|
138
|
-
@b.initialize_capybara(app)
|
139
|
-
end
|
140
|
-
|
141
|
-
it "returns nil if there is no screenshot for that path" do
|
142
|
-
@b.relative_screenshot_for("/whatever").must_equal(nil)
|
143
|
-
end
|
144
|
-
|
145
|
-
it "stores the screenshot location by path" do
|
146
|
-
@b.stubs(:visit)
|
147
|
-
@b.stubs(:next_filename).returns("/some/location.png")
|
148
|
-
|
149
|
-
capybara_browser = stub
|
150
|
-
capybara_browser.stubs(:save_screenshot)
|
151
|
-
Capybara.page.driver.stubs(:browser).returns(capybara_browser)
|
152
|
-
|
153
|
-
@b.take_screenshot("/")
|
154
|
-
|
155
|
-
@b.relative_screenshot_for("/").must_equal("foo/some/location.png")
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
describe "screenshot_path" do
|
160
|
-
it "adds the browser name to the screenshot dir and creates it" do
|
161
|
-
FileUtils.expects(:mkdir_p).with("foo/bar/hi")
|
162
|
-
|
163
|
-
c = Compatriot::Browser.new(
|
164
|
-
:name => "hi",
|
165
|
-
:screenshot_directory => "foo/bar"
|
166
|
-
)
|
167
|
-
|
168
|
-
c.screenshot_path.must_equal("foo/bar/hi")
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|
data/spec/unit/runner_spec.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
require_relative '../spec_helper'
|
2
|
-
|
3
|
-
describe Compatriot::Runner do
|
4
|
-
before do
|
5
|
-
Compatriot::Runner.any_instance.stubs(:create_results_directory)
|
6
|
-
Compatriot::Browser.any_instance.stubs(:create_screenshot_path)
|
7
|
-
fake_date = DateTime.parse("2012-01-01 00:00:00 UTC")
|
8
|
-
@fake_date_dir = fake_date.strftime("%Y-%m-%d-%H-%M-%S")
|
9
|
-
@fixed_clock = OpenStruct.new(:now => fake_date)
|
10
|
-
@results_dir_name = File.join("tmp", "results", @fake_date_dir)
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "self#start" do
|
14
|
-
it "creates a Runner instance and calls the other methods on it" do
|
15
|
-
runner = stub
|
16
|
-
|
17
|
-
Compatriot::Runner.expects(:new).returns(runner)
|
18
|
-
runner.expects(:create_results_directory)
|
19
|
-
runner.expects(:take_screenshots)
|
20
|
-
runner.expects(:compute_diffs)
|
21
|
-
runner.expects(:make_index_page)
|
22
|
-
|
23
|
-
Compatriot::Runner.start(stub, stub)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "#take_screenshots" do
|
28
|
-
it "calls take_screenshots for each browser" do
|
29
|
-
firefox_browser = stub
|
30
|
-
chrome_browser = stub
|
31
|
-
|
32
|
-
Compatriot::Browser.expects(:create_browsers).returns([
|
33
|
-
firefox_browser,
|
34
|
-
chrome_browser
|
35
|
-
])
|
36
|
-
|
37
|
-
app = stub
|
38
|
-
paths = stub
|
39
|
-
|
40
|
-
firefox_browser.expects(:take_screenshots).with(
|
41
|
-
:app => app,
|
42
|
-
:paths => paths
|
43
|
-
)
|
44
|
-
chrome_browser.expects(:take_screenshots).with(
|
45
|
-
:app => app,
|
46
|
-
:paths => paths
|
47
|
-
)
|
48
|
-
|
49
|
-
runner = Compatriot::Runner.new(app, paths, @fixed_clock)
|
50
|
-
|
51
|
-
runner.take_screenshots
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
|
56
|
-
describe "#results_directory" do
|
57
|
-
it "names a results directory in tmp/results based on the clock" do
|
58
|
-
runner = Compatriot::Runner.new(SampleApp, ["/"], @fixed_clock)
|
59
|
-
|
60
|
-
runner.results_directory.must_equal(@results_dir_name)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|