capybara-timeout_reporter 0.0.2 → 0.0.3
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/README.md +69 -1
- data/capybara-timeout_reporter.gemspec +1 -1
- data/lib/capybara/timeout_reporter.rb +4 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62b6f37fe93057ed0c1681182ec3fb4e532856c4
|
4
|
+
data.tar.gz: 80f921a198fea2ceb8c738732aa9804c4f471ed4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c677a85c395346f16872102ec32fbc755c7e9de6ec035db9495d9a020b656e2749011d84cc0ba84517d83e022b5a3de419a60ac1f5e33ec2c76a796a84e3a1a8
|
7
|
+
data.tar.gz: d8142a55529e44ad4419e8f34454e60d0276b48037847dfa52486607ac3111ea56ac2dfd4df5c37ae2b8f81787a4f622b4cdf18e88f49239d363da6081e22132
|
data/README.md
CHANGED
@@ -1,10 +1,78 @@
|
|
1
1
|
# Capybara::TimeoutReporter
|
2
2
|
|
3
|
+
[](http://badge.fury.io/rb/capybara-timeout_reporter)
|
4
|
+
|
3
5
|
Speed up your Capybara tests by detecting and fixing finders that reach sync timeout.
|
4
6
|
|
7
|
+
# Description
|
8
|
+
|
9
|
+
Capybara gem is very popular in ruby community for browser-based UI test automation of web apps. Capybara has quite powerful [synchronization mechanism](https://github.com/jnicklas/capybara#asynchronous-javascript-ajax-and-friends) built in, which allows you to write tests that wait automatically until AJAX requests are completed, elements become visible, etc. However, very often engineers do not keep this Capybara feature in mind and write code like this:
|
10
|
+
|
11
|
+
```
|
12
|
+
# this line will be executing for 'Capybara.default_wait_time' seconds
|
13
|
+
refute page.has_css?('.some-non-existent-class')
|
14
|
+
```
|
15
|
+
|
16
|
+
Or like this:
|
17
|
+
|
18
|
+
```
|
19
|
+
if page.has_css?('.some_class')
|
20
|
+
# no timeout occured in this case
|
21
|
+
else
|
22
|
+
# "has_css?(...)" will be executing for 'Capybara.default_wait_time' seconds in this case
|
23
|
+
end
|
24
|
+
```
|
25
|
+
|
26
|
+
Wrong usage of Capybara makes your tests slow!
|
27
|
+
|
28
|
+
capybara-timeout_reporter gem helps you to detect all places where your finders are reaching a timeout and report them.
|
29
|
+
|
30
|
+
|
31
|
+
# Installation
|
32
|
+
|
33
|
+
```
|
34
|
+
gem install capybara-timeout_reporter
|
35
|
+
```
|
36
|
+
or if you're using bundler, add this line to Gemfile:
|
37
|
+
|
38
|
+
```
|
39
|
+
gem 'capybara-timeout_reporter
|
40
|
+
```
|
41
|
+
|
42
|
+
# Usage
|
43
|
+
|
44
|
+
Just load it after capybara gem:
|
45
|
+
|
46
|
+
```
|
47
|
+
require 'capybara'
|
48
|
+
# load timeout_reporter after capybara
|
49
|
+
require 'capybara/timeout_reporter'
|
50
|
+
```
|
51
|
+
|
52
|
+
## Basic usage
|
53
|
+
|
54
|
+
Default beviour, in case of Capybara sync timeout the following warning will be printed into STDOUT:
|
55
|
+
|
56
|
+
```
|
57
|
+
[WARNING] Capybara find timed out after <number_of_seconds> seconds in </path/to/file.rb>:<line_number>
|
58
|
+
```
|
59
|
+
|
60
|
+
## Advanced usage
|
61
|
+
|
62
|
+
```
|
63
|
+
# somewhere in your test_helper.rb, spec_helper.rb, evn.rb, etc.
|
64
|
+
Capybara::TimeoutReporter.on_timeout = Proc.new do |timeout_value, src_line|
|
65
|
+
# do whatever you want, for example:
|
66
|
+
# - raise an exception, if you want to make this strict
|
67
|
+
# - add an entry to test report, if you have one
|
68
|
+
# - write to a log file
|
69
|
+
# - collect all timeouts and then report a total time wasted
|
70
|
+
end
|
71
|
+
```
|
72
|
+
|
5
73
|
## Contributing
|
6
74
|
|
7
|
-
1. Fork it `https://github.com/
|
75
|
+
1. Fork it `https://github.com/vgrigoruk/capybara-timeout_reporter/fork`
|
8
76
|
2. Create your feature branch (`git checkout -b new-feature`)
|
9
77
|
3. Commit your changes (`git commit -am 'Added feature'`)
|
10
78
|
4. Push to the branch (`git push origin new-feature`)
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "capybara-timeout_reporter"
|
5
|
-
spec.version = "0.0.
|
5
|
+
spec.version = "0.0.3"
|
6
6
|
spec.authors = ["Vitalii Grygoruk"]
|
7
7
|
spec.email = ["vitaliy[dot]grigoruk[at]gmail[dot]com"]
|
8
8
|
spec.summary = %q{Detecting and reporting capybara sync timeouts}
|
@@ -8,10 +8,10 @@ module Capybara
|
|
8
8
|
|
9
9
|
class << self
|
10
10
|
attr_accessor :on_timeout
|
11
|
-
end
|
12
11
|
|
13
|
-
|
14
|
-
|
12
|
+
def on_timeout=(proc)
|
13
|
+
@on_timeout = proc
|
14
|
+
end
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -22,7 +22,7 @@ module Capybara
|
|
22
22
|
synchronize_without_warning(seconds, options, &block)
|
23
23
|
rescue Capybara::ElementNotFound => e
|
24
24
|
if Time.now-start_time > seconds
|
25
|
-
trace_line = Thread.current.backtrace.find { |l| !l.include?('gems/capybara')}
|
25
|
+
trace_line = Thread.current.backtrace.find { |l| !l.include?('gems/capybara') }
|
26
26
|
src_line = trace_line.match(/(.*):.*/).captures.first
|
27
27
|
Capybara::TimeoutReporter.on_timeout.call(seconds, src_line)
|
28
28
|
end
|