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

Commit

Permalink
chore(types): webdriver typings for elements and browser (#3513)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
cnishina authored Sep 2, 2016
1 parent 8ca9833 commit 143c710
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 118 deletions.
4 changes: 0 additions & 4 deletions exampleTypescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,5 @@
"jasmine": "^2.4.1",
"protractor": "file:../",
"typescript": "^2.0.0"
},
"devDependencies": {
"@types/jasmine": "^2.2.33",
"@types/node": "^6.0.38"
}
}
7 changes: 5 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,11 @@ gulp.task('types', function(done) {
var files = ['browser', 'element', 'locators', 'expectedConditions',
'config', 'plugins', 'ptor'];
var outputFile = path.resolve(folder, 'index.d.ts');
var contents = '/// <reference path="../typings/index.d.ts" />\n';
contents += 'import {By, WebDriver, WebElement, promise} from \'selenium-webdriver\';\n';
var contents = '';
contents += '/// <reference path="../../@types/node/index.d.ts" />\n';
contents += '/// <reference path="../../@types/jasmine/index.d.ts" />\n';
contents += '/// <reference path="../typings/index.d.ts" />\n';
contents += 'import {ActionSequence, By, WebDriver, WebElement, WebElementPromise, promise, promise as wdpromise, until} from \'selenium-webdriver\';\n';
files.forEach(file => {
contents += parseTypingsFile(folder, file);
});
Expand Down
41 changes: 20 additions & 21 deletions lib/browser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Util from NodeJs
import * as net from 'net';
import {ActionSequence, promise as wdpromise, until, WebDriver, WebElement} from 'selenium-webdriver';
import * as url from 'url';
import * as util from 'util';

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

// Explicitly define webdriver.WebDriver.
export class Webdriver {
actions: () => webdriver.ActionSequence = webdriver.WebDriver.actions;
actions: () => ActionSequence = webdriver.WebDriver.actions;
wait:
(condition: webdriver.promise.Promise<any>|webdriver.util.Condition|
Function,
(condition: wdpromise.Promise<any>|until.Condition<any>|Function,
opt_timeout?: number,
opt_message?:
string) => webdriver.promise.Promise<any> = webdriver.WebDriver.wait;
sleep: (ms: number) => webdriver.promise.Promise<any> =
webdriver.WebDriver.sleep;
string) => wdpromise.Promise<any> = webdriver.WebDriver.wait;
sleep: (ms: number) => wdpromise.Promise<any> = webdriver.WebDriver.sleep;
getCurrentUrl:
() => webdriver.promise.Promise<any> = webdriver.WebDriver.getCurrentUrl;
getTitle: () => webdriver.promise.Promise<any> = webdriver.WebDriver.getTitle;
() => wdpromise.Promise<any> = webdriver.WebDriver.getCurrentUrl;
getTitle: () => wdpromise.Promise<any> = webdriver.WebDriver.getTitle;
takeScreenshot:
() => webdriver.promise.Promise<any> = webdriver.WebDriver.takeScreenshot;
() => wdpromise.Promise<any> = webdriver.WebDriver.takeScreenshot;
}

/**
Expand Down Expand Up @@ -127,7 +126,7 @@ export class ProtractorBrowser extends Webdriver {
*
* @type {webdriver.WebDriver}
*/
driver: webdriver.WebDriver;
driver: WebDriver;

/**
* Helper function for finding elements.
Expand Down Expand Up @@ -197,7 +196,7 @@ export class ProtractorBrowser extends Webdriver {
*
* @type {q.Promise} Done when the new browser is ready for use
*/
ready: webdriver.promise.Promise<any>;
ready: wdpromise.Promise<any>;

/*
* Set by the runner.
Expand Down Expand Up @@ -257,7 +256,7 @@ export class ProtractorBrowser extends Webdriver {
[key: string]: any;

constructor(
webdriverInstance: webdriver.WebDriver, opt_baseUrl?: string,
webdriverInstance: WebDriver, opt_baseUrl?: string,
opt_rootElement?: string, opt_untrackOutstandingTimeouts?: boolean) {
super();
// These functions should delegate to the webdriver instance, but should
Expand Down Expand Up @@ -322,7 +321,7 @@ export class ProtractorBrowser extends Webdriver {
* @returns {webdriver.promise.Promise} A promise which resolves to the
* capabilities object.
*/
getProcessedConfig(): webdriver.promise.Promise<any> { return null; }
getProcessedConfig(): wdpromise.Promise<any> { return null; }

/**
* Fork another instance of browser for use in interactive tests.
Expand Down Expand Up @@ -374,7 +373,7 @@ export class ProtractorBrowser extends Webdriver {
*/
private executeScript_(
script: string|Function, description: string,
...scriptArgs: any[]): webdriver.promise.Promise<any> {
...scriptArgs: any[]): wdpromise.Promise<any> {
if (typeof script === 'function') {
script = 'return (' + script + ').apply(null, arguments);';
}
Expand All @@ -401,7 +400,7 @@ export class ProtractorBrowser extends Webdriver {
*/
private executeAsyncScript_(
script: string|Function, description: string,
...scriptArgs: any[]): webdriver.promise.Promise<any> {
...scriptArgs: any[]): wdpromise.Promise<any> {
if (typeof script === 'function') {
script = 'return (' + script + ').apply(null, arguments);';
}
Expand All @@ -423,15 +422,15 @@ export class ProtractorBrowser extends Webdriver {
* @returns {!webdriver.promise.Promise} A promise that will resolve to the
* scripts return value.
*/
waitForAngular(opt_description?: string): webdriver.promise.Promise<any> {
waitForAngular(opt_description?: string): wdpromise.Promise<any> {
let description = opt_description ? ' - ' + opt_description : '';
if (this.ignoreSynchronization) {
return this.driver.controlFlow().execute(() => {
return true;
}, 'Ignore Synchronization Protractor.waitForAngular()');
}

let runWaitForAngularScript: () => webdriver.promise.Promise<any> = () => {
let runWaitForAngularScript: () => wdpromise.Promise<any> = () => {
if (this.plugins_.skipAngularStability()) {
return webdriver.promise.fulfilled();
} else if (this.rootEl) {
Expand Down Expand Up @@ -493,22 +492,22 @@ export class ProtractorBrowser extends Webdriver {
errMsg +=
'\nWhile waiting for element with locator' + description;
}
let pendingTimeoutsPromise: webdriver.promise.Promise<any>;
let pendingTimeoutsPromise: wdpromise.Promise<any>;
if (this.trackOutstandingTimeouts_) {
pendingTimeoutsPromise = this.executeScript_(
'return window.NG_PENDING_TIMEOUTS',
'Protractor.waitForAngular() - getting pending timeouts' +
description);
} else {
pendingTimeoutsPromise = webdriver.promise.fulfilled({});
pendingTimeoutsPromise = wdpromise.fulfilled({});
}
let pendingHttpsPromise = this.executeScript_(
clientSideScripts.getPendingHttpRequests,
'Protractor.waitForAngular() - getting pending https' +
description,
this.rootEl);

return webdriver.promise
return wdpromise
.all([pendingTimeoutsPromise, pendingHttpsPromise])
.then(
(arr: any[]) => {
Expand Down Expand Up @@ -549,7 +548,7 @@ export class ProtractorBrowser extends Webdriver {
* @returns {!webdriver.promise.Promise} A promise that will be resolved to
* the located {@link webdriver.WebElement}.
*/
findElement(locator: Locator): webdriver.WebElement {
findElement(locator: Locator): WebElement {
return this.element(locator).getWebElement();
}

Expand Down
Loading

0 comments on commit 143c710

Please sign in to comment.