Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit 143c710

Browse files
authored
chore(types): webdriver typings for elements and browser (#3513)
- include node and jasmine dependency to built/index.d.ts - update example and spec/install to not need @types/jasmine and @types/node to install - add more selenium-webdriver to gulp task - added an interface in globals for Error to include a code and stack - improve webdriver typings to elements and browser
1 parent 8ca9833 commit 143c710

File tree

8 files changed

+129
-118
lines changed

8 files changed

+129
-118
lines changed

exampleTypescript/package.json

-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,5 @@
1313
"jasmine": "^2.4.1",
1414
"protractor": "file:../",
1515
"typescript": "^2.0.0"
16-
},
17-
"devDependencies": {
18-
"@types/jasmine": "^2.2.33",
19-
"@types/node": "^6.0.38"
2016
}
2117
}

gulpfile.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,11 @@ gulp.task('types', function(done) {
8888
var files = ['browser', 'element', 'locators', 'expectedConditions',
8989
'config', 'plugins', 'ptor'];
9090
var outputFile = path.resolve(folder, 'index.d.ts');
91-
var contents = '/// <reference path="../typings/index.d.ts" />\n';
92-
contents += 'import {By, WebDriver, WebElement, promise} from \'selenium-webdriver\';\n';
91+
var contents = '';
92+
contents += '/// <reference path="../../@types/node/index.d.ts" />\n';
93+
contents += '/// <reference path="../../@types/jasmine/index.d.ts" />\n';
94+
contents += '/// <reference path="../typings/index.d.ts" />\n';
95+
contents += 'import {ActionSequence, By, WebDriver, WebElement, WebElementPromise, promise, promise as wdpromise, until} from \'selenium-webdriver\';\n';
9396
files.forEach(file => {
9497
contents += parseTypingsFile(folder, file);
9598
});

lib/browser.ts

+20-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Util from NodeJs
22
import * as net from 'net';
3+
import {ActionSequence, promise as wdpromise, until, WebDriver, WebElement} from 'selenium-webdriver';
34
import * as url from 'url';
45
import * as util from 'util';
56

@@ -33,20 +34,18 @@ for (let foo in webdriver) {
3334

3435
// Explicitly define webdriver.WebDriver.
3536
export class Webdriver {
36-
actions: () => webdriver.ActionSequence = webdriver.WebDriver.actions;
37+
actions: () => ActionSequence = webdriver.WebDriver.actions;
3738
wait:
38-
(condition: webdriver.promise.Promise<any>|webdriver.util.Condition|
39-
Function,
39+
(condition: wdpromise.Promise<any>|until.Condition<any>|Function,
4040
opt_timeout?: number,
4141
opt_message?:
42-
string) => webdriver.promise.Promise<any> = webdriver.WebDriver.wait;
43-
sleep: (ms: number) => webdriver.promise.Promise<any> =
44-
webdriver.WebDriver.sleep;
42+
string) => wdpromise.Promise<any> = webdriver.WebDriver.wait;
43+
sleep: (ms: number) => wdpromise.Promise<any> = webdriver.WebDriver.sleep;
4544
getCurrentUrl:
46-
() => webdriver.promise.Promise<any> = webdriver.WebDriver.getCurrentUrl;
47-
getTitle: () => webdriver.promise.Promise<any> = webdriver.WebDriver.getTitle;
45+
() => wdpromise.Promise<any> = webdriver.WebDriver.getCurrentUrl;
46+
getTitle: () => wdpromise.Promise<any> = webdriver.WebDriver.getTitle;
4847
takeScreenshot:
49-
() => webdriver.promise.Promise<any> = webdriver.WebDriver.takeScreenshot;
48+
() => wdpromise.Promise<any> = webdriver.WebDriver.takeScreenshot;
5049
}
5150

5251
/**
@@ -127,7 +126,7 @@ export class ProtractorBrowser extends Webdriver {
127126
*
128127
* @type {webdriver.WebDriver}
129128
*/
130-
driver: webdriver.WebDriver;
129+
driver: WebDriver;
131130

132131
/**
133132
* Helper function for finding elements.
@@ -197,7 +196,7 @@ export class ProtractorBrowser extends Webdriver {
197196
*
198197
* @type {q.Promise} Done when the new browser is ready for use
199198
*/
200-
ready: webdriver.promise.Promise<any>;
199+
ready: wdpromise.Promise<any>;
201200

202201
/*
203202
* Set by the runner.
@@ -257,7 +256,7 @@ export class ProtractorBrowser extends Webdriver {
257256
[key: string]: any;
258257

259258
constructor(
260-
webdriverInstance: webdriver.WebDriver, opt_baseUrl?: string,
259+
webdriverInstance: WebDriver, opt_baseUrl?: string,
261260
opt_rootElement?: string, opt_untrackOutstandingTimeouts?: boolean) {
262261
super();
263262
// These functions should delegate to the webdriver instance, but should
@@ -322,7 +321,7 @@ export class ProtractorBrowser extends Webdriver {
322321
* @returns {webdriver.promise.Promise} A promise which resolves to the
323322
* capabilities object.
324323
*/
325-
getProcessedConfig(): webdriver.promise.Promise<any> { return null; }
324+
getProcessedConfig(): wdpromise.Promise<any> { return null; }
326325

327326
/**
328327
* Fork another instance of browser for use in interactive tests.
@@ -374,7 +373,7 @@ export class ProtractorBrowser extends Webdriver {
374373
*/
375374
private executeScript_(
376375
script: string|Function, description: string,
377-
...scriptArgs: any[]): webdriver.promise.Promise<any> {
376+
...scriptArgs: any[]): wdpromise.Promise<any> {
378377
if (typeof script === 'function') {
379378
script = 'return (' + script + ').apply(null, arguments);';
380379
}
@@ -401,7 +400,7 @@ export class ProtractorBrowser extends Webdriver {
401400
*/
402401
private executeAsyncScript_(
403402
script: string|Function, description: string,
404-
...scriptArgs: any[]): webdriver.promise.Promise<any> {
403+
...scriptArgs: any[]): wdpromise.Promise<any> {
405404
if (typeof script === 'function') {
406405
script = 'return (' + script + ').apply(null, arguments);';
407406
}
@@ -423,15 +422,15 @@ export class ProtractorBrowser extends Webdriver {
423422
* @returns {!webdriver.promise.Promise} A promise that will resolve to the
424423
* scripts return value.
425424
*/
426-
waitForAngular(opt_description?: string): webdriver.promise.Promise<any> {
425+
waitForAngular(opt_description?: string): wdpromise.Promise<any> {
427426
let description = opt_description ? ' - ' + opt_description : '';
428427
if (this.ignoreSynchronization) {
429428
return this.driver.controlFlow().execute(() => {
430429
return true;
431430
}, 'Ignore Synchronization Protractor.waitForAngular()');
432431
}
433432

434-
let runWaitForAngularScript: () => webdriver.promise.Promise<any> = () => {
433+
let runWaitForAngularScript: () => wdpromise.Promise<any> = () => {
435434
if (this.plugins_.skipAngularStability()) {
436435
return webdriver.promise.fulfilled();
437436
} else if (this.rootEl) {
@@ -493,22 +492,22 @@ export class ProtractorBrowser extends Webdriver {
493492
errMsg +=
494493
'\nWhile waiting for element with locator' + description;
495494
}
496-
let pendingTimeoutsPromise: webdriver.promise.Promise<any>;
495+
let pendingTimeoutsPromise: wdpromise.Promise<any>;
497496
if (this.trackOutstandingTimeouts_) {
498497
pendingTimeoutsPromise = this.executeScript_(
499498
'return window.NG_PENDING_TIMEOUTS',
500499
'Protractor.waitForAngular() - getting pending timeouts' +
501500
description);
502501
} else {
503-
pendingTimeoutsPromise = webdriver.promise.fulfilled({});
502+
pendingTimeoutsPromise = wdpromise.fulfilled({});
504503
}
505504
let pendingHttpsPromise = this.executeScript_(
506505
clientSideScripts.getPendingHttpRequests,
507506
'Protractor.waitForAngular() - getting pending https' +
508507
description,
509508
this.rootEl);
510509

511-
return webdriver.promise
510+
return wdpromise
512511
.all([pendingTimeoutsPromise, pendingHttpsPromise])
513512
.then(
514513
(arr: any[]) => {
@@ -549,7 +548,7 @@ export class ProtractorBrowser extends Webdriver {
549548
* @returns {!webdriver.promise.Promise} A promise that will be resolved to
550549
* the located {@link webdriver.WebElement}.
551550
*/
552-
findElement(locator: Locator): webdriver.WebElement {
551+
findElement(locator: Locator): WebElement {
553552
return this.element(locator).getWebElement();
554553
}
555554

0 commit comments

Comments
 (0)