capybara-angular 0.2.5 → 0.2.6
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 +7 -0
- data/capybara-angular.gemspec +1 -0
- data/lib/capybara/angular/version.rb +1 -1
- data/lib/capybara/angular/waiter.js +53 -0
- data/lib/capybara/angular/waiter.rb +16 -37
- data/spec/capybara/angular_spec.rb +22 -0
- data/spec/public/non-angular-page-with-angular-javascript.html +8 -0
- data/spec/public/non-angular-page.html +6 -0
- metadata +22 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07bb2276413ff6990ca7a585e2466bbbaeac3f55
|
4
|
+
data.tar.gz: 46be6bbca846bd8e3724a601b996fc02838c6d35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8141edfd0b75ff1256cc2236dc4547dbc66bd8747434ff3aebc701e40c26aa68047b88ebb0c03aaa2503570ec26444d61fe91f427aa4894845026df0feafd49
|
7
|
+
data.tar.gz: a31a4525de002d97cd9402c28dc2314d50bf6f0cabe96b85780bf7d2a98952a5df11afe8567df5cc1a45404390c407de77062aea08e79653e153bdb6cf8a583f
|
data/README.md
CHANGED
@@ -18,6 +18,13 @@ Use it as you would use regular Capybara API, however this time, you won't face
|
|
18
18
|
include Capybara::Angular::DSL
|
19
19
|
```
|
20
20
|
|
21
|
+
If you need to run some code without caring about AngularJS, you can use `ignoring_angular` like this:
|
22
|
+
```ruby
|
23
|
+
ignoring_angular do
|
24
|
+
# Your AngularJS agnostic code goes here
|
25
|
+
end
|
26
|
+
```
|
27
|
+
|
21
28
|
## Limitations
|
22
29
|
|
23
30
|
At the moment it works with AngularJS applications initialized with `ng-app`.
|
data/capybara-angular.gemspec
CHANGED
@@ -0,0 +1,53 @@
|
|
1
|
+
// This script is injected from waiter.rb. It is responsible for setting
|
2
|
+
// window.capybaraAngularReady when either a) angular is ready, or b)
|
3
|
+
// it determines the page is not an angular page.
|
4
|
+
|
5
|
+
(function () {
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
window.capybaraAngularReady = false;
|
9
|
+
|
10
|
+
function ready() {
|
11
|
+
window.capybaraAngularReady = true;
|
12
|
+
}
|
13
|
+
|
14
|
+
function angularPresent() {
|
15
|
+
return window.angular !== undefined;
|
16
|
+
}
|
17
|
+
|
18
|
+
function element() {
|
19
|
+
return document.querySelector("[ng-app], [data-ng-app]") || document.querySelector("body");
|
20
|
+
}
|
21
|
+
|
22
|
+
function elementPresent() {
|
23
|
+
return element() !== undefined;
|
24
|
+
}
|
25
|
+
|
26
|
+
function setupTestability() {
|
27
|
+
try {
|
28
|
+
angular.getTestability(element()).whenStable(ready);
|
29
|
+
} catch (err) {
|
30
|
+
ready();
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
function setupInjector() {
|
35
|
+
try {
|
36
|
+
angular.element(element()).injector().get("$browser").notifyWhenNoOutstandingRequests(ready);
|
37
|
+
} catch (err) {
|
38
|
+
ready();
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
function setup() {
|
43
|
+
if (!angularPresent() || !elementPresent()) {
|
44
|
+
ready();
|
45
|
+
} else if (angular.getTestability) {
|
46
|
+
setupTestability();
|
47
|
+
} else {
|
48
|
+
setupInjector();
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
setup();
|
53
|
+
}());
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module Capybara
|
2
2
|
module Angular
|
3
3
|
class Waiter
|
4
|
+
WAITER_JS = IO.read(File.expand_path "../waiter.js", __FILE__)
|
5
|
+
|
4
6
|
attr_accessor :page
|
5
7
|
|
6
8
|
def initialize(page)
|
@@ -8,23 +10,24 @@ module Capybara
|
|
8
10
|
end
|
9
11
|
|
10
12
|
def wait_until_ready
|
11
|
-
return unless
|
12
|
-
|
13
|
-
setup_ready
|
14
|
-
|
13
|
+
return unless driver_supports_js?
|
15
14
|
start = Time.now
|
15
|
+
|
16
16
|
until ready?
|
17
|
+
inject_waiter
|
17
18
|
timeout! if timeout?(start)
|
18
|
-
if page_reloaded_on_wait?
|
19
|
-
return unless angular_app?
|
20
|
-
setup_ready
|
21
|
-
end
|
22
19
|
sleep(0.01)
|
23
20
|
end
|
24
21
|
end
|
25
22
|
|
26
23
|
private
|
27
24
|
|
25
|
+
def driver_supports_js?
|
26
|
+
page.evaluate_script "true"
|
27
|
+
rescue Capybara::NotSupportedByDriverError
|
28
|
+
false
|
29
|
+
end
|
30
|
+
|
28
31
|
def timeout?(start)
|
29
32
|
Time.now - start > Capybara::Angular.default_max_wait_time
|
30
33
|
end
|
@@ -33,37 +36,13 @@ module Capybara
|
|
33
36
|
raise Timeout::Error.new("timeout while waiting for angular")
|
34
37
|
end
|
35
38
|
|
36
|
-
def
|
37
|
-
page.evaluate_script("window.
|
38
|
-
|
39
|
-
|
40
|
-
def angular_app?
|
41
|
-
js = '!!window.angular'
|
42
|
-
page.evaluate_script js
|
43
|
-
|
44
|
-
rescue Capybara::NotSupportedByDriverError
|
45
|
-
false
|
46
|
-
end
|
47
|
-
|
48
|
-
def setup_ready
|
49
|
-
page.execute_script <<-JS
|
50
|
-
var el = document.querySelector('[ng-app], [data-ng-app]') || document.querySelector('body');
|
51
|
-
|
52
|
-
window.angularReady = false;
|
53
|
-
|
54
|
-
if (angular.getTestability) {
|
55
|
-
angular.getTestability(el).whenStable(function() { window.angularReady = true; });
|
56
|
-
} else {
|
57
|
-
var $browser = angular.element(el).injector().get('$browser');
|
58
|
-
|
59
|
-
if ($browser.outstandingRequestCount > 0) { window.angularReady = false; }
|
60
|
-
$browser.notifyWhenNoOutstandingRequests(function() { window.angularReady = true; });
|
61
|
-
}
|
62
|
-
JS
|
39
|
+
def inject_waiter
|
40
|
+
return if page.evaluate_script("window.capybaraAngularReady !== undefined")
|
41
|
+
page.execute_script WAITER_JS
|
63
42
|
end
|
64
43
|
|
65
|
-
def
|
66
|
-
page.evaluate_script("window.
|
44
|
+
def ready?
|
45
|
+
page.evaluate_script("window.capybaraAngularReady === true")
|
67
46
|
end
|
68
47
|
end
|
69
48
|
end
|
@@ -27,6 +27,16 @@ feature 'Waiting for angular' do
|
|
27
27
|
timeout_page_should_have_waited
|
28
28
|
end
|
29
29
|
|
30
|
+
scenario 'when visiting a non-angular page' do
|
31
|
+
open_non_angular_page
|
32
|
+
non_angular_page_should_load
|
33
|
+
end
|
34
|
+
|
35
|
+
scenario 'when visiting a non-angular page that loads angular javascript' do
|
36
|
+
open_non_angular_page_with_angular_javascript
|
37
|
+
non_angular_page_should_load
|
38
|
+
end
|
39
|
+
|
30
40
|
def open_manual_bootstrap_page
|
31
41
|
visit '/manual.html'
|
32
42
|
end
|
@@ -39,7 +49,19 @@ feature 'Waiting for angular' do
|
|
39
49
|
visit '/ng-app-not-on-body.html'
|
40
50
|
end
|
41
51
|
|
52
|
+
def open_non_angular_page
|
53
|
+
visit '/non-angular-page.html'
|
54
|
+
end
|
55
|
+
|
56
|
+
def open_non_angular_page_with_angular_javascript
|
57
|
+
visit '/non-angular-page-with-angular-javascript.html'
|
58
|
+
end
|
59
|
+
|
42
60
|
def timeout_page_should_have_waited
|
43
61
|
expect(page).to have_content('waited')
|
44
62
|
end
|
63
|
+
|
64
|
+
def non_angular_page_should_load
|
65
|
+
expect(page).to have_content('non-angular page')
|
66
|
+
end
|
45
67
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capybara-angular
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pawel Pierzchala
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: puma
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description: Capybara API that knows how to wait for Angular in end to end specs
|
84
98
|
email:
|
85
99
|
- pawelpierzchala@gmail.com
|
@@ -97,6 +111,7 @@ files:
|
|
97
111
|
- lib/capybara/angular.rb
|
98
112
|
- lib/capybara/angular/dsl.rb
|
99
113
|
- lib/capybara/angular/version.rb
|
114
|
+
- lib/capybara/angular/waiter.js
|
100
115
|
- lib/capybara/angular/waiter.rb
|
101
116
|
- spec/capybara/angular_spec.rb
|
102
117
|
- spec/public/js/angular-1.5.8.js
|
@@ -104,6 +119,8 @@ files:
|
|
104
119
|
- spec/public/manual.html
|
105
120
|
- spec/public/ng-app-not-on-body.html
|
106
121
|
- spec/public/ng-app.html
|
122
|
+
- spec/public/non-angular-page-with-angular-javascript.html
|
123
|
+
- spec/public/non-angular-page.html
|
107
124
|
homepage: ''
|
108
125
|
licenses:
|
109
126
|
- MIT
|
@@ -124,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
141
|
version: '0'
|
125
142
|
requirements: []
|
126
143
|
rubyforge_project:
|
127
|
-
rubygems_version: 2.6.
|
144
|
+
rubygems_version: 2.6.12
|
128
145
|
signing_key:
|
129
146
|
specification_version: 4
|
130
147
|
summary: Stable Capybara API for AngularJS applications
|
@@ -135,3 +152,5 @@ test_files:
|
|
135
152
|
- spec/public/manual.html
|
136
153
|
- spec/public/ng-app-not-on-body.html
|
137
154
|
- spec/public/ng-app.html
|
155
|
+
- spec/public/non-angular-page-with-angular-javascript.html
|
156
|
+
- spec/public/non-angular-page.html
|