Skip to content

Commit a6147b3

Browse files
committed
Native support for the SafariDriver in WebDriverJS
1 parent 3511a36 commit a6147b3

File tree

11 files changed

+689
-25
lines changed

11 files changed

+689
-25
lines changed

Rakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ namespace :node do
577577
"//cpp:noblur",
578578
"//cpp:noblur64",
579579
"//javascript/firefox-driver:webdriver",
580+
"//javascript/safari-driver:client",
580581
"//javascript/webdriver:asserts_lib",
581582
"//javascript/webdriver:webdriver_lib",
582583
"//javascript/webdriver:unit_test_lib"
@@ -595,6 +596,7 @@ namespace :node do
595596
" --resource=build/cpp/amd64/libnoblur64.so:firefox/amd64/libnoblur64.so" <<
596597
" --resource=build/cpp/i386/libnoblur.so:firefox/i386/libnoblur.so" <<
597598
" --resource=build/javascript/firefox-driver/webdriver.xpi:firefox/webdriver.xpi" <<
599+
" --resource=build/javascript/safari-driver/client.js:safari/client.js" <<
598600
" --resource=third_party/closure/LICENSE:goog/LICENSE" <<
599601
" --resource=common/src/web/:test/data/" <<
600602
" --exclude_resource=common/src/web/Bin" <<

javascript/node/selenium-webdriver/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ major version release (i.e. 1.0.0).
1212

1313
* Added native support for Internet Explorer - the Java Selenium server is no
1414
longer required.
15+
* Added native support for Safari
1516
* Added native support for Opera 26+
1617
* With the release of [Node 0.12.0](http://blog.nodejs.org/2015/02/06/node-v0-12-0-stable/)
1718
(finally!), the minimum supported version of Node is now `0.10.x`.

javascript/node/selenium-webdriver/builder.js

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ var Builder = function() {
104104
/** @private {opera.Options} */
105105
this.operaOptions_ = null;
106106

107+
/** @private {ie.Options} */
108+
this.ieOptions_ = null;
109+
110+
/** @private {safari.Options} */
111+
this.safariOptions_ = null;
112+
107113
/** @private {boolean} */
108114
this.ignoreEnv_ = false;
109115
};
@@ -258,10 +264,10 @@ Builder.prototype.setAlertBehavior = function(behavior) {
258264

259265

260266
/**
261-
* Sets Chrome-specific options for drivers created by this builder. Any
262-
* logging or proxy settings defined on the given options will take precedence
263-
* over those set through {@link #setLoggingPrefs} and {@link #setProxy},
264-
* respectively.
267+
* Sets Chrome specific {@linkplain selenium-webdriver/chrome.Options options}
268+
* for drivers created by this builder. Any logging or proxy settings defined
269+
* on the given options will take precedence over those set through
270+
* {@link #setLoggingPrefs} and {@link #setProxy}, respectively.
265271
*
266272
* @param {!chrome.Options} options The ChromeDriver options to use.
267273
* @return {!Builder} A self reference.
@@ -273,10 +279,10 @@ Builder.prototype.setChromeOptions = function(options) {
273279

274280

275281
/**
276-
* Sets Firefox-specific options for drivers created by this builder. Any
277-
* logging or proxy settings defined on the given options will take precedence
278-
* over those set through {@link #setLoggingPrefs} and {@link #setProxy},
279-
* respectively.
282+
* Sets Firefox specific {@linkplain selenium-webdriver/firefox.Options options}
283+
* for drivers created by this builder. Any logging or proxy settings defined
284+
* on the given options will take precedence over those set through
285+
* {@link #setLoggingPrefs} and {@link #setProxy}, respectively.
280286
*
281287
* @param {!firefox.Options} options The FirefoxDriver options to use.
282288
* @return {!Builder} A self reference.
@@ -288,10 +294,10 @@ Builder.prototype.setFirefoxOptions = function(options) {
288294

289295

290296
/**
291-
* Sets Opera-specific options for drivers created by this builder. Any
292-
* logging or proxy settings defined on the given options will take precedence
293-
* over those set through {@link #setLoggingPrefs} and {@link #setProxy},
294-
* respectively.
297+
* Sets Opera specific {@linkplain selenium-webdriver/opera.Options options} for
298+
* drivers created by this builder. Any logging or proxy settings defined on the
299+
* given options will take precedence over those set through
300+
* {@link #setLoggingPrefs} and {@link #setProxy}, respectively.
295301
*
296302
* @param {!opera.Options} options The OperaDriver options to use.
297303
* @return {!Builder} A self reference.
@@ -302,6 +308,36 @@ Builder.prototype.setOperaOptions = function(options) {
302308
};
303309

304310

311+
/**
312+
* Sets Internet Explorer specific
313+
* {@linkplain selenium-webdriver/ie.Options options} for drivers created by
314+
* this builder. Any proxy settings defined on the given options will take
315+
* precedence over those set through {@link #setProxy}.
316+
*
317+
* @param {!ie.Options} options The IEDriver options to use.
318+
* @return {!Builder} A self reference.
319+
*/
320+
Builder.prototype.setIeOptions = function(options) {
321+
this.ieOptions_ = options;
322+
return this;
323+
};
324+
325+
326+
/**
327+
* Sets Safari specific {@linkplain selenium-webdriver/safari.Options options}
328+
* for drivers created by this builder. Any logging settings defined on the
329+
* given options will take precedence over those set through
330+
* {@link #setLoggingPrefs}.
331+
*
332+
* @param {!safari.Options} options The Safari options to use.
333+
* @return {!Builder} A self reference.
334+
*/
335+
Builder.prototype.setSafariOptions = function(options) {
336+
this.safariOptions_ = options;
337+
return this;
338+
};
339+
340+
305341
/**
306342
* Sets the control flow that created drivers should execute actions in. If
307343
* the flow is never set, or is set to {@code null}, it will use the active
@@ -355,9 +391,14 @@ Builder.prototype.build = function() {
355391
} else if (browser === Browser.FIREFOX && this.firefoxOptions_) {
356392
capabilities.merge(this.firefoxOptions_.toCapabilities());
357393

394+
} else if (browser === Browser.INTERNET_EXPLORER && this.ieOptions_) {
395+
capabilities.merge(this.ieOptions_.toCapabilities());
396+
358397
} else if (browser === Browser.OPERA && this.operaOptions_) {
359398
capabilities.merge(this.operaOptions_.toCapabilities());
360399

400+
} else if (browser === Browser.SAFARI && this.safariOptions_) {
401+
capabilities.merge(this.safariOptions_.toCapabilities());
361402
}
362403

363404
// Check for a remote browser.
@@ -407,6 +448,12 @@ Builder.prototype.build = function() {
407448
var phantomjs = require('./phantomjs');
408449
return new phantomjs.Driver(capabilities, this.flow_);
409450

451+
case Browser.SAFARI:
452+
// Requiring 'safari' would create a cycle:
453+
// index -> builder -> safari -> index
454+
var safari = require('./safari');
455+
return new safari.Driver(capabilities, this.flow_);
456+
410457
default:
411458
throw new Error('Do not know how to build driver: ' + browser
412459
+ '; did you forget to call usingServer(url)?');

javascript/node/selenium-webdriver/io/index.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,27 @@ exports.exists = function(path) {
146146
};
147147

148148

149+
/**
150+
* Deletes a name from the filesystem and possibly the file it refers to. Has
151+
* no effect if the file does not exist.
152+
* @param {string} path The path to remove.
153+
* @return {!promise.Promise} A promise for when the file has been removed.
154+
*/
155+
exports.unlink = function(path) {
156+
return new promise.Promise(function(fulfill, reject) {
157+
fs.exists(path, function(exists) {
158+
if (exists) {
159+
fs.unlink(path, function(err) {
160+
err && reject(err) || fulfill();
161+
});
162+
} else {
163+
fulfill();
164+
}
165+
});
166+
});
167+
};
168+
169+
149170
/**
150171
* @return {!promise.Promise.<string>} A promise for the path to a temporary
151172
* directory.
@@ -157,12 +178,17 @@ exports.tmpDir = function() {
157178

158179

159180
/**
181+
* @param {{postfix: string}=} opt_options Temporary file options.
160182
* @return {!promise.Promise.<string>} A promise for the path to a temporary
161183
* file.
162184
* @see https://www.npmjs.org/package/tmp
163185
*/
164-
exports.tmpFile = function() {
165-
return promise.checkedNodeCall(tmp.file);
186+
exports.tmpFile = function(opt_options) {
187+
// |tmp.file| checks arguments length to detect options rather than doing a
188+
// truthy check, so we must only pass options if there are some to pass.
189+
return opt_options ?
190+
promise.checkedNodeCall(tmp.file, opt_options) :
191+
promise.checkedNodeCall(tmp.file);
166192
};
167193

168194

javascript/node/selenium-webdriver/lib/test/index.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ var NATIVE_BROWSERS = [
3535
webdriver.Browser.FIREFOX,
3636
webdriver.Browser.IE,
3737
webdriver.Browser.OPERA,
38-
webdriver.Browser.PHANTOM_JS
38+
webdriver.Browser.PHANTOM_JS,
39+
webdriver.Browser.SAFARI
3940
];
4041

4142

@@ -187,12 +188,18 @@ function suite(fn, opt_options) {
187188
browsers.forEach(function(browser) {
188189
testing.describe('[' + browser + ']', function() {
189190

190-
if (_base.isDevMode() && nativeRun &&
191-
browser === webdriver.Browser.FIREFOX) {
192-
testing.before(function() {
193-
return build.of('//javascript/firefox-driver:webdriver')
194-
.onlyOnce().go();
195-
});
191+
if (_base.isDevMode() && nativeRun) {
192+
if (browser === webdriver.Browser.FIREFOX) {
193+
testing.before(function() {
194+
return build.of('//javascript/firefox-driver:webdriver')
195+
.onlyOnce().go();
196+
});
197+
} else if (browser === webdriver.Browser.SAFARI) {
198+
testing.before(function() {
199+
return build.of('//javascript/safari-driver:client')
200+
.onlyOnce().go();
201+
});
202+
}
196203
}
197204

198205
var serverToUse = null;

javascript/node/selenium-webdriver/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"adm-zip": "0.4.4",
2626
"rimraf": "^2.2.8",
2727
"tmp": "0.0.24",
28+
"ws": "^0.7.1",
2829
"xml2js": "0.4.4"
2930
},
3031
"devDependencies": {

0 commit comments

Comments
 (0)