chrome_diff 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +36 -0
- data/README.md +44 -0
- data/lib/chrome_diff.rb +1 -1
- data/lib/chrome_diff/cli.rb +1 -1
- data/lib/chrome_diff/session.rb +6 -6
- data/lib/chrome_diff/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3327e0ea798894487c578c34d28051b76114b70b7e5ee252bf64198b05ba8648
|
4
|
+
data.tar.gz: 768b97a67bf46f6605f7326ab55c49cb74ae3b7a6865f977f3d9d9b23e5b9ba8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75d32c8b2be65dde34e8fb5b586cc7da1e905d043b4a0fa85c11b85bd6578593226558a2ed03e586d6e66facd2761bf65a46baf60acf01b7c7ce2f3e2c81dd86
|
7
|
+
data.tar.gz: 3e7ca23b4f697b5a837adc18fc2e9c2a7ab2721de07146350c145e216830087787955408650d134212c6a81df09d5f59e20cf47a9b6d315f920fb90f775df614
|
@@ -0,0 +1,36 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
strategy:
|
13
|
+
matrix:
|
14
|
+
ruby: [ '2.6', '2.7' ]
|
15
|
+
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@v2
|
18
|
+
- name: Set up Ruby
|
19
|
+
uses: ruby/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
ruby-version: ${{ matrix.ruby }}
|
22
|
+
|
23
|
+
- name: Cache dependencies
|
24
|
+
uses: actions/cache@v2
|
25
|
+
with:
|
26
|
+
path: vendor/bundle
|
27
|
+
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
|
28
|
+
restore-keys: |
|
29
|
+
${{ runner.os }}-gems-
|
30
|
+
- name: Install dependencies with cache
|
31
|
+
run: |
|
32
|
+
bundle config path vendor/bundle
|
33
|
+
bundle install --jobs 4 --retry 3
|
34
|
+
|
35
|
+
- name: Run tests
|
36
|
+
run: bundle exec rspec
|
data/README.md
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
# ChromeDiff
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/chrome_diff.svg)](https://badge.fury.io/rb/chrome_diff)
|
2
3
|
|
3
4
|
Visual diff tool powered by headless chrome.
|
4
5
|
|
6
|
+
This tool controls Chrome by [Chrome DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/) based on [Ferrum](https://github.com/rubycdp/ferrum).
|
7
|
+
|
5
8
|
## Installation
|
6
9
|
|
7
10
|
```console
|
@@ -14,11 +17,52 @@ $ gem install chrome_diff
|
|
14
17
|
|
15
18
|
## Usage
|
16
19
|
|
20
|
+
### Command-line
|
17
21
|
```console
|
18
22
|
$ chrome-diff -f "https://google.com/?q=hello" -t "https://google.com/?q=world"
|
19
23
|
There are some diffefences (1.44%): diff.png
|
20
24
|
```
|
21
25
|
|
26
|
+
#### Options
|
27
|
+
|
28
|
+
```console
|
29
|
+
Usage: chrome-diff [options]
|
30
|
+
-f, --from-url [FROM_URL] From url
|
31
|
+
-t, --to-url [TO_URL] To url
|
32
|
+
-o, --output [OUTPUT] Output file
|
33
|
+
-w, --width [WIDTH] Window width (default 800)
|
34
|
+
-h, --height [HEIGHT] Window height (default 600)
|
35
|
+
-q, --quiet Quiet mode
|
36
|
+
--threshold [THRESHOLD] Threshold percent (default 1%)
|
37
|
+
--debug Debug mode (default false)
|
38
|
+
--no-output Don't output diff file
|
39
|
+
--full-screenshot Capture full screenshot
|
40
|
+
```
|
41
|
+
|
42
|
+
### As library
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
session = ChromeDiff::Session.new
|
46
|
+
session.compare("https://example.com/", "https://www.google.com/")
|
47
|
+
```
|
48
|
+
|
49
|
+
#### Customize
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
session = ChromeDiff::Session.new(width: 800, height: 600, timeout: 5, debug: false)
|
53
|
+
session.compare(from_url: from_url, to_url: to_url, output: "diff.png", threshold: 1, full_screenshot: false)
|
54
|
+
```
|
55
|
+
|
56
|
+
- `width`: window width (default 800px)
|
57
|
+
- `height`: window height (default 600px)
|
58
|
+
- `timeout`: browser timeout (default 5 seconds)
|
59
|
+
- `debug`: debug mode (default false)
|
60
|
+
- `from_url`: from url (required)
|
61
|
+
- `to_url`: to url (required)
|
62
|
+
- `output`: output diff image (default diff.png)
|
63
|
+
- `threshold`: threshold percent (default 1%)
|
64
|
+
- `full_screenshot`: take full screenshot (default false)
|
65
|
+
|
22
66
|
## Contributing
|
23
67
|
|
24
68
|
Bug reports and pull requests are welcome on GitHub at https://github.com/hogelog/chrome_diff.
|
data/lib/chrome_diff.rb
CHANGED
data/lib/chrome_diff/cli.rb
CHANGED
@@ -29,7 +29,7 @@ module ChromeDiff
|
|
29
29
|
parser.on("-w [WIDTH]", "--width", "Window width (default 800)") {|v| opts[:width] = v.to_i }
|
30
30
|
parser.on("-h [HEIGHT]", "--height", "Window height (default 600)") {|v| opts[:height] = v.to_i }
|
31
31
|
parser.on("-q", "--quiet", "Quiet mode") {|v| opts[:quiet] = v }
|
32
|
-
parser.on("--
|
32
|
+
parser.on("--threshold [THRESHOLD]", "Threshold percent (default 1%)") {|v| opts[:threshold] = v.to_f }
|
33
33
|
parser.on("--debug", "Debug mode (default false)") {|v| opts[:debug] = !!v }
|
34
34
|
parser.on("--no-output", "Don't output diff file") {|v| opts[:output] = v }
|
35
35
|
parser.on("--full-screenshot", "Capture full screenshot") {|v| opts[:full_screenshot] = !!v }
|
data/lib/chrome_diff/session.rb
CHANGED
@@ -9,16 +9,16 @@ module ChromeDiff
|
|
9
9
|
class CompareStatus
|
10
10
|
attr_reader :status, :diff, :diff_percent
|
11
11
|
|
12
|
-
def initialize(status, stderr, width, height,
|
12
|
+
def initialize(status, stderr, width, height, threshold)
|
13
13
|
@status = status
|
14
|
-
@
|
14
|
+
@threshold = threshold
|
15
15
|
|
16
16
|
@diff = stderr.to_f.to_i
|
17
17
|
@diff_percent = @diff.to_f / width / height * 100
|
18
18
|
end
|
19
19
|
|
20
20
|
def success?
|
21
|
-
@diff_percent <= @
|
21
|
+
@diff_percent <= @threshold
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -47,8 +47,8 @@ module ChromeDiff
|
|
47
47
|
@browser.resize(width: @width, height: @height)
|
48
48
|
end
|
49
49
|
|
50
|
-
def compare(from_url:, to_url:, output:,
|
51
|
-
|
50
|
+
def compare(from_url:, to_url:, output:, threshold: nil, full_screenshot: nil)
|
51
|
+
threshold ||= ChromeDiff::DEFAULT_OPTIONS[:threshold]
|
52
52
|
result = nil
|
53
53
|
Dir.mktmpdir do |tmpdir|
|
54
54
|
from_file = File.join(tmpdir, "from.png")
|
@@ -59,7 +59,7 @@ module ChromeDiff
|
|
59
59
|
screenshot(to_url, to_file, full_screenshot)
|
60
60
|
|
61
61
|
_stdout, stderr, status = Open3.capture3("compare", "-metric", "AE", from_file, to_file, diff_file)
|
62
|
-
result = CompareStatus.new(status, stderr, @width, @height,
|
62
|
+
result = CompareStatus.new(status, stderr, @width, @height, threshold)
|
63
63
|
|
64
64
|
File.rename(diff_file, output) if output
|
65
65
|
end
|
data/lib/chrome_diff/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chrome_diff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hogelog
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ferrum
|
@@ -74,6 +74,7 @@ executables:
|
|
74
74
|
extensions: []
|
75
75
|
extra_rdoc_files: []
|
76
76
|
files:
|
77
|
+
- ".github/workflows/ruby.yml"
|
77
78
|
- ".gitignore"
|
78
79
|
- ".keep"
|
79
80
|
- ".rspec"
|