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

chore(types): webdriver typings for elements and browser #3513

Merged
merged 2 commits into from
Sep 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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