capybara-box 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +55 -13
- data/lib/capybara-box/base.rb +13 -1
- data/lib/capybara-box/version.rb +1 -1
- data/spec/lib/capybara_box/base/driver_options_spec.rb +56 -12
- data/spec/lib/capybara_box/base/log_spec.rb +43 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4bdaec6c2c1490b88c611085694f8236508305a
|
4
|
+
data.tar.gz: 9d57739d0736541aa752b0654473ea72ac9aa083
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b627d07d8a80b9e5de260068e1b095d0c18272b7b8acbec9c4c38ab39e56f3aa9c8c79fb0e812d65b367a996532ad50387e5cd76130583130cc6b598690ad9b
|
7
|
+
data.tar.gz: 18e0e3b30f9f7462338fbd62f3af8a839cb4f3092bfdebf389c144cd4f28ad595d4c0e511d9788cf52c76b37040375ba5e995ff633e0d6bad8b9a24bb8d5dd1e
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -9,7 +9,7 @@ Configure Capybara with **Chrome**, **Headless Chrome** or **Firefox** with *Scr
|
|
9
9
|
|
10
10
|
Add the following code on your Gemfile and run bundle install:
|
11
11
|
|
12
|
-
```
|
12
|
+
```ruby
|
13
13
|
group :test do
|
14
14
|
gem 'capybara-box', require: false
|
15
15
|
end
|
@@ -19,7 +19,7 @@ end
|
|
19
19
|
|
20
20
|
Just require the lib **after** Capybara require and you done:
|
21
21
|
|
22
|
-
```
|
22
|
+
```ruby
|
23
23
|
require 'capybara/rails'
|
24
24
|
require 'capybara-box'
|
25
25
|
|
@@ -28,11 +28,21 @@ CapybaraBox::Base.configure
|
|
28
28
|
|
29
29
|
By default, `chrome` is de driver, but you can use `chrome`, `chrome_headless` or `firefox`.
|
30
30
|
|
31
|
+
## Version
|
32
|
+
|
33
|
+
If you do not want install the Chrome Driver on your CI, you can specify the version here and it will be installed automatically for you.
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
CapybaraBox::Base.configure version: '2.32'
|
37
|
+
```
|
38
|
+
|
39
|
+
* This works just for Chrome, for now
|
40
|
+
|
31
41
|
## Screenshot
|
32
42
|
|
33
43
|
You can enable screenshot on failure and send it to S3.
|
34
44
|
|
35
|
-
```
|
45
|
+
```ruby
|
36
46
|
CapybaraBox.configure(
|
37
47
|
screenshot: {
|
38
48
|
s3: {
|
@@ -46,7 +56,7 @@ CapybaraBox.configure(
|
|
46
56
|
|
47
57
|
If you want enable it only on CI, use the `enabled` option:
|
48
58
|
|
49
|
-
```
|
59
|
+
```ruby
|
50
60
|
CapybaraBox.configure(
|
51
61
|
enabled: ENV['CI'],
|
52
62
|
|
@@ -58,26 +68,26 @@ CapybaraBox.configure(
|
|
58
68
|
|
59
69
|
By default, Rack Session manipulation comes as battery, just use it.
|
60
70
|
|
61
|
-
```
|
71
|
+
```ruby
|
62
72
|
page.set_rack_session key: 'value'
|
63
73
|
```
|
64
74
|
|
65
|
-
```
|
75
|
+
```ruby
|
66
76
|
page.get_rack_session :key
|
67
77
|
# 'value'
|
68
78
|
```
|
69
79
|
|
70
80
|
You can disable this feature using the `session` option:
|
71
81
|
|
72
|
-
```
|
73
|
-
CapybaraBox.configure
|
82
|
+
```ruby
|
83
|
+
CapybaraBox.configure session: false
|
74
84
|
```
|
75
85
|
|
76
86
|
## Add Argument
|
77
87
|
|
78
88
|
By default some Switches are enabled for a better performance, you can add yours too:
|
79
89
|
|
80
|
-
```
|
90
|
+
```ruby
|
81
91
|
capybara_box = CapybaraBox.configure
|
82
92
|
capybara_box.add_argument '--incognito'
|
83
93
|
```
|
@@ -86,7 +96,7 @@ capybara_box.add_argument '--incognito'
|
|
86
96
|
|
87
97
|
If you prefere, is possible override all of them:
|
88
98
|
|
89
|
-
```
|
99
|
+
```ruby
|
90
100
|
CapybaraBox.configure arguments: ['--incognito']
|
91
101
|
```
|
92
102
|
|
@@ -96,7 +106,7 @@ Click [here](https://peter.sh/experiments/chromium-command-line-switches) to see
|
|
96
106
|
|
97
107
|
By default some Preferences are enabled for a better performance, you can add yours too:
|
98
108
|
|
99
|
-
```
|
109
|
+
```ruby
|
100
110
|
capybara_box = CapybaraBox.configure
|
101
111
|
capybara_box.add_preference :credentials_enable_service, false
|
102
112
|
```
|
@@ -105,7 +115,7 @@ capybara_box.add_preference :credentials_enable_service, false
|
|
105
115
|
|
106
116
|
If you prefere, is possible override all of them:
|
107
117
|
|
108
|
-
```
|
118
|
+
```ruby
|
109
119
|
CapybaraBox.configure preferences: { credentials_enable_service: false }
|
110
120
|
```
|
111
121
|
|
@@ -117,10 +127,42 @@ By default some timeout configs are enabled only on CI env for a better performa
|
|
117
127
|
It has this restrition because with timeout enabled, debugger cannot evaluate the variables values.
|
118
128
|
You can override all of them too:
|
119
129
|
|
120
|
-
```
|
130
|
+
```ruby
|
121
131
|
CapybaraBox.configure http_client_options: { read_timeout: 60 }
|
122
132
|
```
|
123
133
|
|
134
|
+
## Driver Options
|
135
|
+
|
136
|
+
You can override all driver options:
|
137
|
+
|
138
|
+
```ruby
|
139
|
+
CapybaraBox.configure driver_options: { clear_local_storage: true }
|
140
|
+
```
|
141
|
+
|
142
|
+
## Log
|
143
|
+
|
144
|
+
Log is writen at `log/capybara-box.log` as default.
|
145
|
+
|
146
|
+
You can see each command executed. Time spent between them and debug some hanging command. :tada:
|
147
|
+
|
148
|
+
```
|
149
|
+
[15.479][INFO]: RESPONSE Navigate
|
150
|
+
[15.482][INFO]: COMMAND ExecuteScript {
|
151
|
+
"args": [ ],
|
152
|
+
"script": "return $(\".gridy\").data(\"ready\")"
|
153
|
+
}
|
154
|
+
[15.483][INFO]: Waiting for pending navigations...
|
155
|
+
[15.545][INFO]: Done waiting for pending navigations. Status: ok
|
156
|
+
```
|
157
|
+
|
158
|
+
To disable log on CI, for example, use the `log` options:
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
CapybaraBox.configure log: ENV['CI'].nil?
|
162
|
+
```
|
163
|
+
|
164
|
+
* It works only for **chrome** and **chrome_headless**.
|
165
|
+
|
124
166
|
## Love it!
|
125
167
|
|
126
168
|
Via [PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=X8HEP2878NDEG&item_name=capybara-box) or [Gratipay](https://gratipay.com/~wbotelhos). Thanks! (:
|
data/lib/capybara-box/base.rb
CHANGED
@@ -135,11 +135,17 @@ module CapybaraBox
|
|
135
135
|
def driver_options
|
136
136
|
return @parameters[:driver_options] if @parameters[:driver_options]
|
137
137
|
|
138
|
-
{
|
138
|
+
opts = {
|
139
139
|
browser: browser,
|
140
140
|
clear_local_storage: true,
|
141
141
|
clear_session_storage: true
|
142
142
|
}
|
143
|
+
|
144
|
+
if log?
|
145
|
+
opts[:driver_opts] = { log_path: 'log/capybara-box.log' } if chrome_family?
|
146
|
+
end
|
147
|
+
|
148
|
+
opts
|
143
149
|
end
|
144
150
|
|
145
151
|
def firefox?
|
@@ -200,6 +206,12 @@ module CapybaraBox
|
|
200
206
|
|
201
207
|
private
|
202
208
|
|
209
|
+
def log?
|
210
|
+
return true if @parameters[:log].nil?
|
211
|
+
|
212
|
+
true? @parameters[:log]
|
213
|
+
end
|
214
|
+
|
203
215
|
def true?(value)
|
204
216
|
['true', true].include? value
|
205
217
|
end
|
data/lib/capybara-box/version.rb
CHANGED
@@ -3,21 +3,65 @@ require 'rails_helper'
|
|
3
3
|
RSpec.describe CapybaraBox::Base, '.register' do
|
4
4
|
subject { described_class.new parameters }
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
context 'when is chrome' do
|
7
|
+
let!(:parameters) { { browser: :chrome } }
|
8
|
+
|
9
|
+
it 'uses the default driver options' do
|
10
|
+
expect(subject.driver_options).to eq(
|
11
|
+
browser: :chrome,
|
12
|
+
clear_local_storage: true,
|
13
|
+
clear_session_storage: true,
|
14
|
+
driver_opts: { log_path: 'log/capybara-box.log' }
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when :driver_options is given' do
|
19
|
+
before { parameters[:driver_options] = { key: :value } }
|
20
|
+
|
21
|
+
it 'is used' do
|
22
|
+
expect(subject.driver_options).to eq(key: :value)
|
23
|
+
end
|
24
|
+
end
|
14
25
|
end
|
15
26
|
|
16
|
-
context 'when
|
17
|
-
let!(:parameters) { {
|
27
|
+
context 'when is chrome headless' do
|
28
|
+
let!(:parameters) { { browser: :chrome_headless } }
|
29
|
+
|
30
|
+
it 'uses the default driver options' do
|
31
|
+
expect(subject.driver_options).to eq(
|
32
|
+
browser: :chrome_headless,
|
33
|
+
clear_local_storage: true,
|
34
|
+
clear_session_storage: true,
|
35
|
+
driver_opts: { log_path: 'log/capybara-box.log' }
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when :driver_options is given' do
|
40
|
+
before { parameters[:driver_options] = { key: :value } }
|
41
|
+
|
42
|
+
it 'is used' do
|
43
|
+
expect(subject.driver_options).to eq(key: :value)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'when is firefox' do
|
49
|
+
let!(:parameters) { { browser: :firefox } }
|
50
|
+
|
51
|
+
it 'uses the default driver options' do
|
52
|
+
expect(subject.driver_options).to eq(
|
53
|
+
browser: :firefox,
|
54
|
+
clear_local_storage: true,
|
55
|
+
clear_session_storage: true
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'when :driver_options is given' do
|
60
|
+
before { parameters[:driver_options] = { key: :value } }
|
18
61
|
|
19
|
-
|
20
|
-
|
62
|
+
it 'is used' do
|
63
|
+
expect(subject.driver_options).to eq(key: :value)
|
64
|
+
end
|
21
65
|
end
|
22
66
|
end
|
23
67
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.shared_context 'log_disabled' do
|
4
|
+
context 'when is chrome' do
|
5
|
+
before { parameters[:browser] = :chrome }
|
6
|
+
|
7
|
+
it 'does not includes log config' do
|
8
|
+
expect(subject.driver_options[:driver_opts]).to be_nil
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'when is chrome headless' do
|
13
|
+
before { parameters[:browser] = :chrome_headless }
|
14
|
+
|
15
|
+
it 'does not includes log config' do
|
16
|
+
expect(subject.driver_options[:driver_opts]).to be_nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'when is firefox' do
|
21
|
+
before { parameters[:browser] = :firefox }
|
22
|
+
|
23
|
+
it 'does not includes log config' do
|
24
|
+
expect(subject.driver_options[:driver_opts]).to be_nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
RSpec.describe CapybaraBox::Base, '.log' do
|
30
|
+
subject { described_class.new parameters }
|
31
|
+
|
32
|
+
context 'when log is false' do
|
33
|
+
let!(:parameters) { { log: false } }
|
34
|
+
|
35
|
+
it_behaves_like 'log_disabled'
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when log is "false"' do
|
39
|
+
let!(:parameters) { { log: 'false' } }
|
40
|
+
|
41
|
+
it_behaves_like 'log_disabled'
|
42
|
+
end
|
43
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capybara-box
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Washington Botelho
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara-screenshot
|
@@ -167,6 +167,7 @@ files:
|
|
167
167
|
- spec/lib/capybara_box/base/firefox_spec.rb
|
168
168
|
- spec/lib/capybara_box/base/http_client_options_spec.rb
|
169
169
|
- spec/lib/capybara_box/base/http_client_spec.rb
|
170
|
+
- spec/lib/capybara_box/base/log_spec.rb
|
170
171
|
- spec/lib/capybara_box/base/options_spec.rb
|
171
172
|
- spec/lib/capybara_box/base/preferences_spec.rb
|
172
173
|
- spec/lib/capybara_box/base/register_spec.rb
|
@@ -218,6 +219,7 @@ test_files:
|
|
218
219
|
- spec/lib/capybara_box/base/firefox_spec.rb
|
219
220
|
- spec/lib/capybara_box/base/http_client_options_spec.rb
|
220
221
|
- spec/lib/capybara_box/base/http_client_spec.rb
|
222
|
+
- spec/lib/capybara_box/base/log_spec.rb
|
221
223
|
- spec/lib/capybara_box/base/options_spec.rb
|
222
224
|
- spec/lib/capybara_box/base/preferences_spec.rb
|
223
225
|
- spec/lib/capybara_box/base/register_spec.rb
|