forked from angular/protractor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprotractor.js
More file actions
107 lines (97 loc) · 2.79 KB
/
protractor.js
File metadata and controls
107 lines (97 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
var url = require('url');
var util = require('util');
exports.wrapDriver = function(webdriver) {
// should this delegate to all functions on the webdriver? Should it
// actually modify the input driver?
var driver = webdriver,
moduleNames = [],
moduleScripts = [];
var PROTRACTOR_URL_LABEL = '_WAITFORMODULES';
var waitForAngular = function() {
return driver.executeAsyncScript(function() {
var callback = arguments[arguments.length - 1];
angular.element(document.body).injector().get('$browser').
notifyWhenNoOutstandingRequests(callback);
});
};
return {
findElement: function(locator, varArgs) {
waitForAngular();
return driver.findElement(locator, varArgs);
},
/**
* @param <string> name
* @param <Function|string> script
*/
addMockModule: function(name, script) {
moduleNames.push(name);
moduleScripts.push(script);
},
clearMockModules: function() {
moduleNames = [];
moduleScripts = [];
},
/**
* Usage:
* protractor.addMockModule(moduleA);
* protractor.addMockModule(moduleB);
* protractor.get('foo.com');
*/
get: function(destination) {
var parsed = url.parse(destination);
parsed.hash = (parsed.hash ? parsed.hash : '#') + PROTRACTOR_URL_LABEL;
var modifiedUrl = url.format(parsed);
driver.get(modifiedUrl);
// At this point, Angular will pause for us, until angular.resumeBootstrapWithExtraModules is called.
for (var i = 0; i < moduleScripts.length; ++i) {
driver.executeScript(moduleScripts[i]); // Should this be async?
}
driver.executeAsyncScript(function() {
var callback = arguments[arguments.length - 1];
// Continue to bootstrap Angular.
angular.resumeBootstrapWithExtraModules(arguments[0]);
callback();
}, moduleNames);
}
};
};
exports.By = {
/** Usage:
* driver.findElement(protractor.By.binding(), "{{myBinding}}");
*/
binding: function() {
return {
using: 'js',
value: function() {
var bindings = document.getElementsByClassName('ng-binding');
var matches = [];
var binding = arguments[0];
for (var i = 0; i < bindings.length; ++i) {
if (angular.element(bindings[i]).data().$binding[0].exp == binding) {
matches.push(bindings[i]);
}
}
return matches[0]; // We can only return one with webdriver.findElement.
}
};
},
select: function(model) {
return {
using: 'css selector',
value: 'select[ng-model=' + model + ']'
};
},
selectedOption: function(model) {
return {
using: 'css selector',
value: 'select[ng-model=' + model + '] option[selected]'
};
},
repeater: null,
input: function(model) {
return {
using: 'css selector',
value: 'input[ng-model=' + model + ']'
};
}
};