-
Notifications
You must be signed in to change notification settings - Fork 39
/
webdriver-sync.js
213 lines (197 loc) · 5.05 KB
/
webdriver-sync.js
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
'use strict';
var java = require('java');
var imports = require('./imports');
var Long = imports.Long;
var WAIT_DEFAULT_TIMEOUT = 1000;
var WAIT_DEFAULT_PERIOD = 100;
if(!process.env.WEBDRIVER_SYNC_ENABLE_SELENIUM_STDOUT){
imports.helpers.ConsoleControl.stopOutSync();
}
if(!process.env.WEBDRIVER_SYNC_ENABLE_SELENIUM_STDERR){
imports.helpers.ConsoleControl.stopErrSync();
}
module.exports = {
//BUILT IN
get Long() {
return imports.Long;
},
//===BEGIN WRAPPERS==//
//CLASSES
get By() {
return new (require('./classes/By'))();
},
get ChromeDriver() {
return require('./classes/ChromeDriver');
},
get ChromeDriverService() {
return require('./classes/ChromeDriverService');
},
get ChromeOptions() {
return require('./classes/ChromeOptions');
},
get Command() {
return require('./classes/Command');
},
get Cookie() {
return require('./classes/Cookie');
},
get DesiredCapabilities() {
return require('./classes/DesiredCapabilities');
},
get Dimension() {
return require('./classes/Dimension');
},
get DriverService() {
return require('./classes/DriverService');
},
get ErrorHandler() {
return require('./classes/ErrorHandler');
},
get ExpectedConditions() {
return require('./classes/ExpectedConditions');
},
get File() {
return require('./classes/File');
},
get FirefoxDriver() {
return require('./classes/FirefoxDriver');
},
get FirefoxProfile() {
return require('./classes/FirefoxProfile');
},
// get PhantomJSDriver() {
// return require('./classes/PhantomJSDriver');
// },
get HtmlUnitDriver() {
return require('./classes/HtmlUnitDriver');
},
get InternetExplorerDriver() {
return require('./classes/InternetExplorerDriver');
},
get Level() {
return require('./classes/Level');
},
get LogEntry() {
return require('./classes/LogEntry');
},
get LogEntries() {
return require('./classes/LogEntries');
},
get LocalFileDetector() {
return require('./classes/LocalFileDetector');
},
get LoggingPreferences() {
return require('./classes/LoggingPreferences');
},
get Point() {
return require('./classes/Point');
},
get RemoteStatus() {
return require('./classes/RemoteStatus');
},
get RemoteWebDriver() {
return require('./classes/RemoteWebDriver');
},
get Response() {
return require('./classes/Response');
},
get SafariDriver() {
return require('./classes/SafariDriver');
},
get SessionId() {
return require('./classes/SessionId');
},
get UselessFileDetector() {
return require('./classes/UselessFileDetector');
},
// get UserAndPassword() {
// return require('./classes/UserAndPassword');
// },
get WebDriverWait() {
return require('./classes/WebDriverWait');
},
//ENUMS
get Keys() {
return require('./enums/Keys');
},
get Platform() {
return require('./enums/Platform');
},
get TimeUnit() {
return require('./enums/TimeUnit');
},
//INTERFACES
get Logs() {
return require('./interfaces/Logs');
},
get OutputType() {
return require('./interfaces/OutputType');
},
get WebElement() {
return require('./interfaces/WebElement');
},
//===END WRAPPERS==//
//UTILITY METHODS
importTo:function(target){
console.warn('#importTo is deprecated! Use #exportTo instead.');
return this.exportTo(target);
},
/**
* Use this method to expose all Selenium Classes to the given target.
* Useful if you wish to avoid wd.blablabla.
*
* @param {Object} target
*/
exportTo: function(target) {
var prop;
for (prop in this) {
if(this.hasOwnProperty(prop)){
if (prop[0].toLowerCase() !== prop[0]){//upercase so export
target[prop] = this[prop];
}
}
}
},
/**
* @param {number} amount in mills to sleep for.
*/
sleep: function(amount) {
java.callStaticMethodSync(
'java.lang.Thread',
'sleep',
new Long(amount)
);
},
/**
* Utility method for blocking execution until some condition has been
* satisfied.
*
* @param {function} conditionFn Function that determines whether the `wait`
* has completed
* @param {object} [options]
* @param {number} [options.timeout] Time in milliseconds to wait before
* considering the operation failed and
* throwing an error
* @param {number} [options.period] Time in milliseconds to wait between
* invocations of the `conditionFn`
*/
wait: function(conditionFn, options) {
var waitStart = Date.now();
if (!options) {
options = {};
}
if (!('timeout' in options)) {
options.timeout = WAIT_DEFAULT_TIMEOUT;
}
if (!('period' in options)) {
options.period = WAIT_DEFAULT_PERIOD;
}
while (Date.now() - waitStart < options.timeout) {
if (conditionFn()) {
return;
}
module.exports.sleep(options.period);
}
throw new Error('`wd.wait` operation timed out');
}
};