watir_angular 0.3.0 → 0.4.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/lib/waitForAngular.js +133 -0
- data/lib/watir_angular.rb +8 -19
- data/watir_angular.gemspec +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db2980821eced85f9586c90b94ce85f1f5c867ce
|
4
|
+
data.tar.gz: 5d3c3432cc04cc41d066f76a471445a20f7b2e1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ea3f508654b0c6d077161376151a1dcacf966240d787c0303507900952e90f1464e8c09b57320a824811f18d99e77e1b1aac852e35b3c72e7ef5e84731c7365
|
7
|
+
data.tar.gz: b3673e5b26784d379a9625d4c9346262c4fa79a588e497c80c7126da68bbfa8e05c85665828a4acb691c8de9edf798fdd3c82de50c582a1213ba65a3f133d5b9
|
@@ -0,0 +1,133 @@
|
|
1
|
+
// Code from: https://github.com/angular/protractor/blob/a62efc6e401bc1aa7408e3008ccdaa219b528636/lib/clientsidescripts.js
|
2
|
+
|
3
|
+
function(rootSelector, callback) {
|
4
|
+
try {
|
5
|
+
// Wait for both angular1 testability and angular2 testability.
|
6
|
+
var ng1Hooks = function getNg1Hooks(selector, injectorPlease) {
|
7
|
+
function tryEl(el) {
|
8
|
+
try {
|
9
|
+
if (!injectorPlease && angular.getTestability) {
|
10
|
+
var $$testability = angular.getTestability(el);
|
11
|
+
if ($$testability) {
|
12
|
+
return {$$testability: $$testability};
|
13
|
+
}
|
14
|
+
} else {
|
15
|
+
var $injector = angular.element(el).injector();
|
16
|
+
if ($injector) {
|
17
|
+
return {$injector: $injector};
|
18
|
+
}
|
19
|
+
}
|
20
|
+
} catch(err) {}
|
21
|
+
}
|
22
|
+
function trySelector(selector) {
|
23
|
+
var els = document.querySelectorAll(selector);
|
24
|
+
for (var i = 0; i < els.length; i++) {
|
25
|
+
var elHooks = tryEl(els[i]);
|
26
|
+
if (elHooks) {
|
27
|
+
return elHooks;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
if (selector) {
|
33
|
+
return trySelector(selector);
|
34
|
+
} else if (window.__TESTABILITY__NG1_APP_ROOT_INJECTOR__) {
|
35
|
+
var $injector = window.__TESTABILITY__NG1_APP_ROOT_INJECTOR__;
|
36
|
+
var $$testability = null;
|
37
|
+
try {
|
38
|
+
$$testability = $injector.get('$$testability');
|
39
|
+
} catch (e) {}
|
40
|
+
return {$injector: $injector, $$testability: $$testability};
|
41
|
+
} else {
|
42
|
+
return tryEl(document.body) ||
|
43
|
+
trySelector('[ng-app]') || trySelector('[ng\\:app]') ||
|
44
|
+
trySelector('[ng-controller]') || trySelector('[ng\\:controller]');
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
var testCallback = callback;
|
49
|
+
|
50
|
+
// Wait for angular1 testability first and run waitForAngular2 as a callback
|
51
|
+
var waitForAngular1 = function(callback) {
|
52
|
+
|
53
|
+
if (window.angular) {
|
54
|
+
var hooks = ng1Hooks(rootSelector);
|
55
|
+
if (!hooks){
|
56
|
+
callback(); // not an angular1 app
|
57
|
+
}
|
58
|
+
else{
|
59
|
+
if (hooks.$$testability) {
|
60
|
+
hooks.$$testability.whenStable(callback);
|
61
|
+
} else if (hooks.$injector) {
|
62
|
+
hooks.$injector.get('$browser')
|
63
|
+
.notifyWhenNoOutstandingRequests(callback);
|
64
|
+
} else if (!!rootSelector) {
|
65
|
+
throw new Error(
|
66
|
+
'Could not automatically find injector on page: "' +
|
67
|
+
window.location.toString() + '". Consider using config.rootEl');
|
68
|
+
} else {
|
69
|
+
throw new Error(
|
70
|
+
'root element (' + rootSelector + ') has no injector.' +
|
71
|
+
' this may mean it is not inside ng-app.');
|
72
|
+
}
|
73
|
+
}
|
74
|
+
}
|
75
|
+
else {callback();} // not an angular1 app
|
76
|
+
};
|
77
|
+
|
78
|
+
// Wait for Angular2 testability and then run test callback
|
79
|
+
var waitForAngular2 = function() {
|
80
|
+
if (window.getAngularTestability) {
|
81
|
+
if (rootSelector) {
|
82
|
+
var testability = null;
|
83
|
+
var el = document.querySelector(rootSelector);
|
84
|
+
try{
|
85
|
+
testability = window.getAngularTestability(el);
|
86
|
+
}
|
87
|
+
catch(e){}
|
88
|
+
if (testability) {
|
89
|
+
return testability.whenStable(function() { testCallback(); });
|
90
|
+
}
|
91
|
+
}
|
92
|
+
|
93
|
+
// Didn't specify root element or testability could not be found
|
94
|
+
// by rootSelector. This may happen in a hybrid app, which could have
|
95
|
+
// more than one root.
|
96
|
+
var testabilities = window.getAllAngularTestabilities();
|
97
|
+
var count = testabilities.length;
|
98
|
+
|
99
|
+
// No angular2 testability, this happens when
|
100
|
+
// going to a hybrid page and going back to a pure angular1 page
|
101
|
+
if (count === 0) {
|
102
|
+
return testCallback();
|
103
|
+
}
|
104
|
+
|
105
|
+
var decrement = function() {
|
106
|
+
count--;
|
107
|
+
if (count === 0) {
|
108
|
+
testCallback();
|
109
|
+
}
|
110
|
+
};
|
111
|
+
testabilities.forEach(function(testability) {
|
112
|
+
testability.whenStable(decrement);
|
113
|
+
});
|
114
|
+
|
115
|
+
}
|
116
|
+
else {testCallback();} // not an angular2 app
|
117
|
+
};
|
118
|
+
|
119
|
+
if (!(window.angular) && !(window.getAngularTestability)) {
|
120
|
+
// no testability hook
|
121
|
+
throw new Error(
|
122
|
+
'both angularJS testability and angular testability are undefined.' +
|
123
|
+
' This could be either ' +
|
124
|
+
'because this is a non-angular page or because your test involves ' +
|
125
|
+
'client-side navigation, which can interfere with Protractor\'s ' +
|
126
|
+
'bootstrapping. See http://git.io/v4gXM for details');
|
127
|
+
} else {waitForAngular1(waitForAngular2);} // Wait for angular1 and angular2
|
128
|
+
// Testability hooks sequentially
|
129
|
+
|
130
|
+
} catch (err) {
|
131
|
+
callback(err.message);
|
132
|
+
}
|
133
|
+
}
|
data/lib/watir_angular.rb
CHANGED
@@ -1,28 +1,17 @@
|
|
1
|
-
# Code on this page is based on code by westlm1@NW110283.nwie.net
|
2
|
-
# From https://github.com/watir/watir/pull/387
|
3
|
-
|
4
1
|
require "watir"
|
5
2
|
|
6
3
|
Watir::Locators::Element::SelectorBuilder.send(:remove_const, :WILDCARD_ATTRIBUTE)
|
7
4
|
Watir::Locators::Element::SelectorBuilder::WILDCARD_ATTRIBUTE = /^(aria|data|ng)_(.+)$/
|
8
5
|
|
9
6
|
module WatirAngular
|
10
|
-
def self.wait_for_angular(browser, timeout
|
11
|
-
wd =
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
rescue Selenium::WebDriver::Error::InvalidElementStateError
|
19
|
-
# no ng-app found on page, continue as normal
|
20
|
-
rescue Selenium::WebDriver::Error::JavascriptError
|
21
|
-
# angular not used in the application, continue as normal
|
22
|
-
rescue Selenium::WebDriver::Error::UnknownError => ex
|
23
|
-
# TODO - this may be a bug in chromedriver that it is not a JavaScriptError
|
24
|
-
raise unless ex.message.include? "angular is not defined"
|
25
|
-
# angular not used in the application, continue as normal
|
7
|
+
def self.wait_for_angular(browser, timeout = nil)
|
8
|
+
browser.wd.manage.timeouts.script_timeout = timeout if timeout
|
9
|
+
file = File.expand_path("../waitForAngular.js", __FILE__)
|
10
|
+
js = File.read(file)
|
11
|
+
script = "return (#{js}).apply(null, arguments)"
|
12
|
+
|
13
|
+
error = browser.wd.execute_async_script(script, 'body')
|
14
|
+
Watir.logger.warn error if error
|
26
15
|
end
|
27
16
|
|
28
17
|
def self.inject_wait(browser)
|
data/watir_angular.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: watir_angular
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Titus Fortner
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: watir
|
@@ -95,6 +95,7 @@ files:
|
|
95
95
|
- LICENSE.txt
|
96
96
|
- README.md
|
97
97
|
- Rakefile
|
98
|
+
- lib/waitForAngular.js
|
98
99
|
- lib/watir_angular.rb
|
99
100
|
- watir_angular.gemspec
|
100
101
|
homepage: http://github.com/titusfortner/watir_angular
|