percy-capybara 4.3.2 → 5.0.0.pre.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/README.md +117 -4
- data/lib/percy/capybara.rb +112 -0
- data/lib/percy/version.rb +3 -0
- metadata +38 -45
- data/.circleci/config.yml +0 -38
- data/.gitignore +0 -17
- data/.rspec +0 -4
- data/.rubocop.yml +0 -14
- data/.yardopts +0 -2
- data/CHANGELOG.md +0 -1
- data/DEVELOPING.md +0 -26
- data/Gemfile +0 -13
- data/Guardfile +0 -14
- data/RELEASING.md +0 -23
- data/Rakefile +0 -1
- data/lib/environment.rb +0 -38
- data/lib/percy.rb +0 -142
- data/lib/version.rb +0 -3
- data/package.json +0 -6
- data/percy-capybara.gemspec +0 -32
- data/spec/lib/percy/environment_spec.rb +0 -26
- data/spec/lib/percy/percy_spec.rb +0 -72
- data/spec/spec_helper.rb +0 -33
- data/yarn.lock +0 -2132
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad47828506156e4e07dfc481315f03b6754e56754728dc781d7d112e4c436429
|
4
|
+
data.tar.gz: 6a44e3220c49e4feb480d91bcdd3a5f4f65564ad75231b9455b377f7a69f7b09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6b98bb4aabe555640e2ad075507e413edc94259396a6d7523531097e0678949a1190dc5e9d5bce963aa0499cfd76b88f07d8d4da359faa52b1c1a54008b0a64
|
7
|
+
data.tar.gz: e97a00541379a162dd5da3314b62a429f79d1bfeaade1b12f689cf8479152f82202c97f86a30a23e205541a33305969686dacbb994ba970690d36c8c09e7b742
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,119 @@
|
|
1
|
-
#
|
1
|
+
# percy-capybara
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/percy-capybara.svg)](https://badge.fury.io/rb/percy-capybara)
|
3
|
+
![Test](https://github.com/percy/percy-capybara/workflows/Test/badge.svg)
|
2
4
|
|
3
|
-
[
|
4
|
-
[![Gem Version](https://badge.fury.io/rb/percy-capybara.svg)](http://badge.fury.io/rb/percy-capybara)
|
5
|
+
[Percy](https://percy.io) visual testing for Ruby Selenium.
|
5
6
|
|
6
|
-
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
npm install `@percy/cli`:
|
10
|
+
|
11
|
+
```sh-session
|
12
|
+
$ npm install --save-dev @percy/cli
|
13
|
+
```
|
14
|
+
|
15
|
+
gem install `percy-capybara` package:
|
16
|
+
|
17
|
+
```ssh-session
|
18
|
+
$ gem install percy-capybara
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
In your test setup file, require `percy/capybara`. For example if you're using
|
24
|
+
rspec, you would add the following to your `spec_helper.rb` file:
|
25
|
+
|
26
|
+
``` ruby
|
27
|
+
require 'percy/capybara'
|
28
|
+
```
|
29
|
+
|
30
|
+
Now you can use `page.percy_snapshot` to capture snapshots.
|
31
|
+
|
32
|
+
> Note: you may need to add `js: true` to your specs, depending on your driver setup
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
describe 'my feature, type: :feature do
|
36
|
+
it 'renders the page' do
|
37
|
+
visit 'https://example.com'
|
38
|
+
page.percy_snapshot('Capybara snapshot')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
Running the test above normally will result in the following log:
|
44
|
+
|
45
|
+
```sh-session
|
46
|
+
[percy] Percy is not running, disabling snapshots
|
47
|
+
```
|
48
|
+
|
49
|
+
When running with [`percy
|
50
|
+
exec`](https://github.com/percy/cli/tree/master/packages/cli-exec#percy-exec), and your project's
|
51
|
+
`PERCY_TOKEN`, a new Percy build will be created and snapshots will be uploaded to your project.
|
52
|
+
|
53
|
+
```sh-session
|
54
|
+
$ export PERCY_TOKEN=[your-project-token]
|
55
|
+
$ percy exec -- [test command]
|
56
|
+
[percy] Percy has started!
|
57
|
+
[percy] Created build #1: https://percy.io/[your-project]
|
58
|
+
[percy] Snapshot taken "Capybara example"
|
59
|
+
[percy] Stopping percy...
|
60
|
+
[percy] Finalized build #1: https://percy.io/[your-project]
|
61
|
+
[percy] Done!
|
62
|
+
```
|
63
|
+
|
64
|
+
## Configuration
|
65
|
+
|
66
|
+
`page.snapshot(name[, options])`
|
67
|
+
|
68
|
+
- `name` (**required**) - The snapshot name; must be unique to each snapshot
|
69
|
+
- `options` - [See per-snapshot configuration options](https://docs.percy.io/docs/cli-configuration#per-snapshot-configuration)
|
70
|
+
|
71
|
+
## Upgrading
|
72
|
+
|
73
|
+
### Manually
|
74
|
+
|
75
|
+
#### Require change
|
76
|
+
|
77
|
+
The name of the require has changed from `require 'percy'` to `require
|
78
|
+
'percy/capybara'`. This is to avoid conflict with our [Ruby Selenium SDK's](https://github.com/percy/percy-selenium-ruby)
|
79
|
+
require statement.
|
80
|
+
|
81
|
+
#### API change
|
82
|
+
|
83
|
+
The previous version of this SDK had the following function signature:
|
84
|
+
|
85
|
+
``` ruby
|
86
|
+
Percy.snapshot(driver, name, options)
|
87
|
+
```
|
88
|
+
|
89
|
+
v5.x of this SDK has a significant change to the API. There no longer is a stand
|
90
|
+
alone module to call and you no longer need to pass the page/driver. It's
|
91
|
+
available on the current Capybara session (`page`):
|
92
|
+
|
93
|
+
``` ruby
|
94
|
+
page.percy_snapshot(name, options)
|
95
|
+
```
|
96
|
+
|
97
|
+
If you were using this SDK outside of Capybara, you'll likely find the [Ruby
|
98
|
+
Selenium SDK a better fit](https://github.com/percy/percy-selenium-ruby)
|
99
|
+
|
100
|
+
#### Installing `@percy/cli` & removing `@percy/agent`
|
101
|
+
|
102
|
+
If you're coming from a 4.x version of this package, make sure to install `@percy/cli` after
|
103
|
+
upgrading to retain any existing scripts that reference the Percy CLI
|
104
|
+
command. You will also want to uninstall `@percy/agent`, as it's been replaced
|
105
|
+
by `@percy/cli`.
|
106
|
+
|
107
|
+
```sh-session
|
108
|
+
$ npm uninstall @percy/agent
|
109
|
+
$ npm install --save-dev @percy/cli
|
110
|
+
```
|
111
|
+
|
112
|
+
#### Migrating config
|
113
|
+
|
114
|
+
If you have a previous Percy configuration file, migrate it to the newest version with the
|
115
|
+
[`config:migrate`](https://github.com/percy/cli/tree/master/packages/cli-config#percy-configmigrate-filepath-output) command:
|
116
|
+
|
117
|
+
```sh-session
|
118
|
+
$ percy config:migrate
|
119
|
+
```
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'capybara/dsl'
|
4
|
+
require_relative './version'
|
5
|
+
|
6
|
+
module PercyCapybara
|
7
|
+
CLIENT_INFO = "percy-capybara/#{VERSION}".freeze
|
8
|
+
ENV_INFO = "capybara/#{Capybara::VERSION} ruby/#{RUBY_VERSION}".freeze
|
9
|
+
|
10
|
+
PERCY_DEBUG = ENV['PERCY_LOGLEVEL'] == 'debug'
|
11
|
+
PERCY_SERVER_ADDRESS = ENV['PERCY_SERVER_ADDRESS'] || 'http://localhost:5338'
|
12
|
+
PERCY_LABEL = "[\u001b[35m" + (PERCY_DEBUG ? 'percy:capybara' : 'percy') + "\u001b[39m]"
|
13
|
+
|
14
|
+
private_constant :CLIENT_INFO
|
15
|
+
private_constant :ENV_INFO
|
16
|
+
|
17
|
+
# Take a DOM snapshot and post it to the snapshot endpoint
|
18
|
+
def percy_snapshot(name, options = {})
|
19
|
+
return unless percy_enabled?
|
20
|
+
|
21
|
+
page = Capybara.current_session
|
22
|
+
|
23
|
+
begin
|
24
|
+
page.evaluate_script(fetch_percy_dom)
|
25
|
+
dom_snapshot = page
|
26
|
+
.evaluate_script("(function() { return PercyDOM.serialize(#{options.to_json}) })()")
|
27
|
+
|
28
|
+
response = fetch('percy/snapshot',
|
29
|
+
name: name,
|
30
|
+
url: page.current_url,
|
31
|
+
dom_snapshot: dom_snapshot,
|
32
|
+
client_info: CLIENT_INFO,
|
33
|
+
environment_info: ENV_INFO,)
|
34
|
+
|
35
|
+
unless response.body.to_json['success']
|
36
|
+
raise StandardError, data['error']
|
37
|
+
end
|
38
|
+
rescue StandardError => e
|
39
|
+
log("Could not take DOM snapshot '#{name}'")
|
40
|
+
|
41
|
+
if PERCY_DEBUG then log(e) end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Determine if the Percy server is running, caching the result so it is only checked once
|
46
|
+
private def percy_enabled?
|
47
|
+
return @percy_enabled unless @percy_enabled.nil?
|
48
|
+
|
49
|
+
begin
|
50
|
+
response = fetch('percy/healthcheck')
|
51
|
+
version = response['x-percy-core-version']
|
52
|
+
|
53
|
+
if version.nil?
|
54
|
+
log('You may be using @percy/agent ' \
|
55
|
+
'which is no longer supported by this SDK. ' \
|
56
|
+
'Please uninstall @percy/agent and install @percy/cli instead. ' \
|
57
|
+
'https://docs.percy.io/docs/migrating-to-percy-cli')
|
58
|
+
@percy_enabled = false
|
59
|
+
return false
|
60
|
+
end
|
61
|
+
|
62
|
+
if version.split('.')[0] != '1'
|
63
|
+
log("Unsupported Percy CLI version, #{version}")
|
64
|
+
@percy_enabled = false
|
65
|
+
return false
|
66
|
+
end
|
67
|
+
|
68
|
+
@percy_enabled = true
|
69
|
+
true
|
70
|
+
rescue StandardError => e
|
71
|
+
log('Percy is not running, disabling snapshots')
|
72
|
+
|
73
|
+
if PERCY_DEBUG then log(e) end
|
74
|
+
@percy_enabled = false
|
75
|
+
false
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# Fetch the @percy/dom script, caching the result so it is only fetched once
|
80
|
+
private def fetch_percy_dom
|
81
|
+
return @percy_dom unless @percy_dom.nil?
|
82
|
+
|
83
|
+
response = fetch('percy/dom.js')
|
84
|
+
@percy_dom = response.body
|
85
|
+
end
|
86
|
+
|
87
|
+
private def log(msg)
|
88
|
+
puts "#{PERCY_LABEL} #{msg}"
|
89
|
+
end
|
90
|
+
|
91
|
+
# Make an HTTP request (GET,POST) using Ruby's Net::HTTP. If `data` is present,
|
92
|
+
# `fetch` will POST as JSON.
|
93
|
+
private def fetch(url, data = nil)
|
94
|
+
uri = URI("#{PERCY_SERVER_ADDRESS}/#{url}")
|
95
|
+
|
96
|
+
response = if data
|
97
|
+
Net::HTTP.post(uri, data.to_json)
|
98
|
+
else
|
99
|
+
Net::HTTP.get_response(uri)
|
100
|
+
end
|
101
|
+
|
102
|
+
unless response.is_a? Net::HTTPSuccess
|
103
|
+
raise StandardError, "Failed with HTTP error code: #{response.code}"
|
104
|
+
end
|
105
|
+
|
106
|
+
response
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# Add the `percy_snapshot` method to the the Capybara session class
|
111
|
+
# `page.percy_snapshot('name', { options })`
|
112
|
+
Capybara::Session.class_eval { include PercyCapybara }
|
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: percy-capybara
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.0.pre.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Perceptual Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: capybara
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: selenium-webdriver
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.0.0.beta1
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 4.0.0.beta1
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: bundler
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,20 +94,6 @@ dependencies:
|
|
66
94
|
- - "~>"
|
67
95
|
- !ruby/object:Gem::Version
|
68
96
|
version: '3.31'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: selenium-webdriver
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: percy-style
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,28 +115,10 @@ executables: []
|
|
101
115
|
extensions: []
|
102
116
|
extra_rdoc_files: []
|
103
117
|
files:
|
104
|
-
- ".circleci/config.yml"
|
105
|
-
- ".gitignore"
|
106
|
-
- ".rspec"
|
107
|
-
- ".rubocop.yml"
|
108
|
-
- ".yardopts"
|
109
|
-
- CHANGELOG.md
|
110
|
-
- DEVELOPING.md
|
111
|
-
- Gemfile
|
112
|
-
- Guardfile
|
113
118
|
- LICENSE
|
114
119
|
- README.md
|
115
|
-
-
|
116
|
-
-
|
117
|
-
- lib/environment.rb
|
118
|
-
- lib/percy.rb
|
119
|
-
- lib/version.rb
|
120
|
-
- package.json
|
121
|
-
- percy-capybara.gemspec
|
122
|
-
- spec/lib/percy/environment_spec.rb
|
123
|
-
- spec/lib/percy/percy_spec.rb
|
124
|
-
- spec/spec_helper.rb
|
125
|
-
- yarn.lock
|
120
|
+
- lib/percy/capybara.rb
|
121
|
+
- lib/percy/version.rb
|
126
122
|
homepage: ''
|
127
123
|
licenses:
|
128
124
|
- MIT
|
@@ -137,18 +133,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
137
133
|
requirements:
|
138
134
|
- - ">="
|
139
135
|
- !ruby/object:Gem::Version
|
140
|
-
version:
|
136
|
+
version: 2.3.0
|
141
137
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
138
|
requirements:
|
143
|
-
- - "
|
139
|
+
- - ">"
|
144
140
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
141
|
+
version: 1.3.1
|
146
142
|
requirements: []
|
147
|
-
rubygems_version: 3.
|
143
|
+
rubygems_version: 3.0.3
|
148
144
|
signing_key:
|
149
145
|
specification_version: 4
|
150
|
-
summary: Percy
|
151
|
-
test_files:
|
152
|
-
- spec/lib/percy/environment_spec.rb
|
153
|
-
- spec/lib/percy/percy_spec.rb
|
154
|
-
- spec/spec_helper.rb
|
146
|
+
summary: Percy visual testing for Capybara
|
147
|
+
test_files: []
|
data/.circleci/config.yml
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
version: 2.1
|
2
|
-
|
3
|
-
default_steps: &default_steps
|
4
|
-
steps:
|
5
|
-
- checkout
|
6
|
-
- run: sudo gem update --system
|
7
|
-
- run: ruby -v
|
8
|
-
- run: yarn
|
9
|
-
- run: bundle install
|
10
|
-
- run: yarn percy exec -- bundle exec rspec
|
11
|
-
- run: bundle exec rubocop -D
|
12
|
-
|
13
|
-
jobs:
|
14
|
-
ruby_latest_with_percy:
|
15
|
-
# This is the one environment where we'll capture and upload snapshots in CI.
|
16
|
-
docker:
|
17
|
-
- image: circleci/ruby:latest-node-browsers
|
18
|
-
<<: *default_steps
|
19
|
-
ruby_25:
|
20
|
-
docker:
|
21
|
-
- image: circleci/ruby:2.5-node-browsers
|
22
|
-
environment:
|
23
|
-
PERCY_ENABLE: 0
|
24
|
-
<<: *default_steps
|
25
|
-
ruby_24:
|
26
|
-
docker:
|
27
|
-
- image: circleci/ruby:2.4-node-browsers
|
28
|
-
environment:
|
29
|
-
PERCY_ENABLE: 0
|
30
|
-
<<: *default_steps
|
31
|
-
|
32
|
-
workflows:
|
33
|
-
version: 2
|
34
|
-
test:
|
35
|
-
jobs:
|
36
|
-
- ruby_latest_with_percy
|
37
|
-
- ruby_25
|
38
|
-
- ruby_24
|
data/.gitignore
DELETED
data/.rspec
DELETED