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

Commit 0a2809e

Browse files
authored
chore(types): fix types to use not @types/selenium-webdriver (#5127)
- Remove the USE_PROMISE_MANAGER test in spec/ts/basic - Remove the check if we are using the control flow or not
1 parent 84cdc50 commit 0a2809e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2844
-3841
lines changed

gulpfile.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ gulp.task('built:copy', () => {
6565
.pipe(gulp.dest('built/'));
6666
});
6767

68+
gulp.task('built:copy:typings', () => {
69+
return gulp.src(['lib/selenium-webdriver/**/*.d.ts'])
70+
.pipe(gulp.dest('built/selenium-webdriver/'));
71+
});
72+
6873
gulp.task('webdriver:update', (done) => {
6974
runSpawn(done, 'node', ['bin/webdriver-manager', 'update']);
7075
});
@@ -88,7 +93,7 @@ gulp.task('prepublish', gulp.series('checkVersion', 'tsc', 'built:copy'));
8893
gulp.task('pretest', gulp.series(
8994
'checkVersion',
9095
gulp.parallel('webdriver:update', 'tslint', 'format'),
91-
'tsc', 'built:copy', 'tsc:spec'));
96+
'tsc', 'built:copy', 'built:copy:typings', 'tsc:spec'));
9297

9398
gulp.task('default', gulp.series('prepublish'));
9499

lib/browser.ts

+18-54
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import {BPClient} from 'blocking-proxy';
2-
import {By, Command as WdCommand, ICommandName, Navigation, promise as wdpromise, Session, WebDriver, WebElement, WebElementPromise} from 'selenium-webdriver';
2+
import {By, Navigation, WebDriver, WebElement, WebElementPromise} from 'selenium-webdriver';
3+
import {Command, ICommandName} from 'selenium-webdriver/lib/command';
34
import * as url from 'url';
4-
import {extend as extendWD, ExtendedWebDriver} from 'webdriver-js-extender';
5+
6+
const CommandName = require('selenium-webdriver/lib/command').Name as ICommandName;
57

68
import {build$, build$$, ElementArrayFinder, ElementFinder} from './element';
79
import {IError} from './exitCodes';
@@ -11,9 +13,6 @@ import {Logger} from './logger';
1113
import {Plugins} from './plugins';
1214

1315
const clientSideScripts = require('./clientsidescripts');
14-
// TODO: fix the typings for selenium-webdriver/lib/command
15-
const Command = require('selenium-webdriver/lib/command').Command as typeof WdCommand;
16-
const CommandName = require('selenium-webdriver/lib/command').Name as ICommandName;
1716

1817
// jshint browser: true
1918

@@ -33,15 +32,6 @@ for (let foo in require('selenium-webdriver')) {
3332
exports[foo] = require('selenium-webdriver')[foo];
3433
}
3534

36-
37-
// Explicitly define types for webdriver.WebDriver and ExtendedWebDriver.
38-
// We do this because we use composition over inheritance to implement polymorphism, and therefore
39-
// we don't want to inherit WebDriver's constructor.
40-
export class AbstractWebDriver {}
41-
export interface AbstractWebDriver extends WebDriver {}
42-
export class AbstractExtendedWebDriver extends AbstractWebDriver {}
43-
export interface AbstractExtendedWebDriver extends ExtendedWebDriver {}
44-
4535
/**
4636
* Mix a function from one object onto another. The function will still be
4737
* called in the context of the original object. Any arguments of type
@@ -109,7 +99,7 @@ function buildElementHelper(browser: ProtractorBrowser): ElementHelper {
10999
* @param {boolean=} opt_untrackOutstandingTimeouts Whether Protractor should
110100
* stop tracking outstanding $timeouts.
111101
*/
112-
export class ProtractorBrowser extends AbstractExtendedWebDriver {
102+
export class ProtractorBrowser {
113103
/**
114104
* @type {ProtractorBy}
115105
*/
@@ -121,12 +111,11 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
121111
ExpectedConditions: ProtractorExpectedConditions;
122112

123113
/**
124-
* The wrapped webdriver instance. Use this to interact with pages that do
125-
* not contain Angular (such as a log-in screen).
114+
* The browser's WebDriver instance
126115
*
127-
* @type {webdriver_extensions.ExtendedWebDriver}
116+
* @type {webdriver.WebDriver}
128117
*/
129-
driver: ExtendedWebDriver;
118+
driver: WebDriver;
130119

131120
/**
132121
* The client used to control the BlockingProxy. If unset, BlockingProxy is
@@ -278,8 +267,7 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
278267
* Information about mock modules that will be installed during every
279268
* get().
280269
*
281-
* @type {Array<{name: string, script: function|string, args:
282-
* Array.<string>}>}
270+
* @type {Array<{name: string, script: function|string, args: Array.<string>}>}
283271
*/
284272
mockModules_: {name: string, script: string|Function, args: any[]}[];
285273

@@ -304,32 +292,23 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
304292
constructor(
305293
webdriverInstance: WebDriver, opt_baseUrl?: string, opt_rootElement?: string|Promise<string>,
306294
opt_untrackOutstandingTimeouts?: boolean, opt_blockingProxyUrl?: string) {
307-
super();
308295
// These functions should delegate to the webdriver instance, but should
309296
// wait for Angular to sync up before performing the action. This does not
310297
// include functions which are overridden by protractor below.
311298
let methodsToSync = ['getCurrentUrl', 'getPageSource', 'getTitle'];
312-
let extendWDInstance: ExtendedWebDriver;
313-
try {
314-
extendWDInstance = extendWD(webdriverInstance);
315-
} catch (e) {
316-
// Probably not a driver that can be extended (e.g. gotten using
317-
// `directConnect: true` in the config)
318-
extendWDInstance = webdriverInstance as ExtendedWebDriver;
319-
}
320299

321300
// Mix all other driver functionality into Protractor.
322301
Object.getOwnPropertyNames(WebDriver.prototype).forEach(method => {
323-
if (!this[method] && typeof(extendWDInstance as any)[method] === 'function') {
302+
if (!this[method] && typeof(webdriverInstance as any)[method] === 'function') {
324303
if (methodsToSync.indexOf(method) !== -1) {
325-
ptorMixin(this, extendWDInstance, method, this.waitForAngular.bind(this));
304+
ptorMixin(this, webdriverInstance, method, this.waitForAngular.bind(this));
326305
} else {
327-
ptorMixin(this, extendWDInstance, method);
306+
ptorMixin(this, webdriverInstance, method);
328307
}
329308
}
330309
});
331310

332-
this.driver = extendWDInstance;
311+
this.driver = webdriverInstance;
333312
if (opt_blockingProxyUrl) {
334313
logger.info('Starting BP client for ' + opt_blockingProxyUrl);
335314
this.bpClient = new BPClient(opt_blockingProxyUrl);
@@ -490,10 +469,9 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
490469
}
491470

492471
// TODO(selenium4): schedule does not exist on driver. Should use execute instead.
493-
return (this.driver as any)
494-
.execute(new Command(CommandName.EXECUTE_SCRIPT)
495-
.setParameter('script', script)
496-
.setParameter('args', scriptArgs));
472+
return this.driver.execute((new Command(CommandName.EXECUTE_SCRIPT) as Command)
473+
.setParameter('script', script)
474+
.setParameter('args', scriptArgs));
497475
}
498476

499477
/**
@@ -620,7 +598,7 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
620598
}
621599

622600
/**
623-
* Waits for Angular to finish rendering before searching for elements.
601+
* Waits for Angular to finish renderActionSequenceing before searching for elements.
624602
* @see webdriver.WebDriver.findElement
625603
* @returns {!webdriver.WebElementPromise} A promise that will be resolved to
626604
* the located {@link webdriver.WebElement}.
@@ -882,7 +860,7 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
882860
* await browser.get('http://angular.github.io/protractor/#/tutorial');
883861
* await browser.setLocation('api');
884862
* expect(await browser.getCurrentUrl())
885-
* .toBe('http://angular.github.io/protractor/#/api');
863+
* .toBe('http://angular.g../../ithub.io/protractor/#/api');
886864
*
887865
* @param {string} url In page URL using the same syntax as $location.url()
888866
* @returns {!Promise} A promise that will resolve once
@@ -921,18 +899,4 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
921899
return await this.executeScriptWithDescription(
922900
clientSideScripts.getLocationAbsUrl, 'Protractor.getLocationAbsUrl()', rootEl);
923901
}
924-
925-
/**
926-
* Determine if the control flow is enabled.
927-
*
928-
* @returns true if the control flow is enabled, false otherwise.
929-
*/
930-
controlFlowIsEnabled() {
931-
if ((wdpromise as any).USE_PROMISE_MANAGER !== undefined) {
932-
return (wdpromise as any).USE_PROMISE_MANAGER;
933-
} else {
934-
// True for old versions of `selenium-webdriver`, probably false in >=5.0.0
935-
return !!wdpromise.ControlFlow;
936-
}
937-
}
938902
}

lib/driverProviders/attachSession.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
* it down, and setting up the driver correctly.
55
*/
66
import {Session, WebDriver} from 'selenium-webdriver';
7+
import {Executor, HttpClient} from 'selenium-webdriver/http';
78

89
import {Config} from '../config';
910
import {Logger} from '../logger';
10-
1111
import {DriverProvider} from './driverProvider';
1212

13-
const http = require('selenium-webdriver/http');
14-
1513
let logger = new Logger('attachSession');
1614

1715
export class AttachSession extends DriverProvider {
@@ -36,9 +34,9 @@ export class AttachSession extends DriverProvider {
3634
* @return {WebDriver} webdriver instance
3735
*/
3836
async getNewDriver(): Promise<WebDriver> {
39-
const httpClient = new http.HttpClient(this.config_.seleniumAddress);
40-
const executor = new http.Executor(httpClient);
41-
const session = new Session(this.config_.seleniumSessionId, null);
37+
const httpClient: HttpClient = new HttpClient(this.config_.seleniumAddress);
38+
const executor: Executor = new Executor(httpClient);
39+
const session: Session = new Session(this.config_.seleniumSessionId, null);
4240

4341
const newDriver = new WebDriver(session, executor);
4442
this.drivers_.push(newDriver);

lib/driverProviders/direct.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
*/
66
import * as fs from 'fs';
77
import {Capabilities, WebDriver} from 'selenium-webdriver';
8-
import {Driver as DriverForChrome, ServiceBuilder as ChromeServiceBuilder} from 'selenium-webdriver/chrome';
9-
import {Driver as DriverForFirefox, ServiceBuilder as FirefoxServiceBuilder} from 'selenium-webdriver/firefox';
8+
import {Driver as DriverForChrome, ServiceBuilder as ServiceBuilderForChrome} from 'selenium-webdriver/chrome';
9+
import {Driver as DriverForFirefox, ServiceBuilder as SerivceBuilderForFirefox} from 'selenium-webdriver/firefox';
10+
1011
import {ChromeDriver, GeckoDriver} from 'webdriver-manager';
1112

1213
import {Config} from '../config';
@@ -73,7 +74,8 @@ export class Direct extends DriverProvider {
7374
'. Run \'webdriver-manager update\' to download binaries.');
7475
}
7576

76-
let chromeService = new ChromeServiceBuilder(chromeDriverFile).build();
77+
const chromeService =
78+
(new ServiceBuilderForChrome(chromeDriverFile) as ServiceBuilderForChrome).build();
7779
driver = await DriverForChrome.createSession(
7880
new Capabilities(this.config_.capabilities), chromeService);
7981
break;
@@ -97,7 +99,7 @@ export class Direct extends DriverProvider {
9799
'. Run \'webdriver-manager update\' to download binaries.');
98100
}
99101

100-
let firefoxService = new FirefoxServiceBuilder(geckoDriverFile).build();
102+
let firefoxService = new SerivceBuilderForFirefox(geckoDriverFile).build();
101103
driver = await DriverForFirefox.createSession(
102104
new Capabilities(this.config_.capabilities), firefoxService);
103105
break;

lib/driverProviders/driverProvider.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
* it down, and setting up the driver correctly.
55
*/
66
import {Builder, WebDriver} from 'selenium-webdriver';
7-
87
import {BlockingProxyRunner} from '../bpRunner';
98
import {Config} from '../config';
109
import {BrowserError} from '../exitCodes';
1110
import {Logger} from '../logger';
1211

1312
let logger = new Logger('driverProvider');
13+
1414
export abstract class DriverProvider {
1515
drivers_: WebDriver[];
1616
config_: Config;
@@ -43,9 +43,9 @@ export abstract class DriverProvider {
4343
* Create a new driver.
4444
*
4545
* @public
46-
* @return webdriver instance
46+
* @return a promise to a webdriver instance
4747
*/
48-
async getNewDriver() {
48+
async getNewDriver(): Promise<WebDriver> {
4949
let builder: Builder;
5050
if (this.config_.useBlockingProxy) {
5151
builder =

lib/driverProviders/local.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {DriverProvider} from './driverProvider';
1919
let logger = new Logger('local');
2020

2121
export class Local extends DriverProvider {
22-
server_: any;
22+
server_: SeleniumServer;
2323
constructor(config: Config) {
2424
super(config);
2525
this.server_ = null;

lib/driverProviders/mock.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {Config} from '../config';
99
import {DriverProvider} from './driverProvider';
1010

1111
export class MockExecutor {
12-
execute(command: any): any {}
12+
execute(_: any): any {}
1313
}
1414

1515
export class Mock extends DriverProvider {
@@ -39,8 +39,8 @@ export class Mock extends DriverProvider {
3939
* @return webdriver instance
4040
*/
4141
async getNewDriver(): Promise<WebDriver> {
42-
let mockSession = new Session('test_session_id', {});
43-
let newDriver = new WebDriver(mockSession, new MockExecutor());
42+
const mockSession: Session = new Session('test_session_id', {});
43+
const newDriver: WebDriver = new WebDriver(mockSession, new MockExecutor());
4444
this.drivers_.push(newDriver);
4545
return newDriver;
4646
}

lib/driverProviders/sauce.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* it down, and setting up the driver correctly.
55
*/
66

7-
import {Session, WebDriver} from 'selenium-webdriver';
7+
import {WebDriver} from 'selenium-webdriver';
88
import * as util from 'util';
99

1010
import {Config} from '../config';
@@ -33,14 +33,13 @@ export class Sauce extends DriverProvider {
3333
* @return {Promise} A promise that will resolve when the update is complete.
3434
*/
3535
updateJob(update: any): Promise<any> {
36-
let mappedDrivers = this.drivers_.map((driver: WebDriver) => {
37-
driver.getSession().then((session: Session) => {
38-
logger.info('SauceLabs results available at http://saucelabs.com/jobs/' + session.getId());
39-
this.sauceServer_.updateJob(session.getId(), update, (err: Error) => {
40-
if (err) {
41-
throw new Error('Error updating Sauce pass/fail status: ' + util.inspect(err));
42-
}
43-
});
36+
let mappedDrivers = this.drivers_.map(async (driver: WebDriver) => {
37+
const session = await driver.getSession();
38+
logger.info('SauceLabs results available at http://saucelabs.com/jobs/' + session.getId());
39+
this.sauceServer_.updateJob(session.getId(), update, (err: Error) => {
40+
if (err) {
41+
throw new Error('Error updating Sauce pass/fail status: ' + util.inspect(err));
42+
}
4443
});
4544
});
4645
return Promise.all(mappedDrivers);

lib/element.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ export class ElementFinder extends WebdriverWebElement {
889889
const id = this.elementArrayFinder_.getWebElements().then((parentWebElements: WebElement[]) => {
890890
return parentWebElements[0];
891891
});
892-
return new WebElementPromise(this.browser_.driver, id);
892+
return new WebElementPromise(this.browser_.driver, id) as WebElementPromise;
893893
}
894894

895895
/**

lib/index.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import {ElementHelper, ProtractorBrowser} from './browser';
22
import {ElementArrayFinder, ElementFinder} from './element';
33
import {ProtractorExpectedConditions} from './expectedConditions';
4-
import {Locator, ProtractorBy} from './locators';
4+
import {ProtractorBy} from './locators';
55
import {PluginConfig, ProtractorPlugin} from './plugins';
66
import {Ptor} from './ptor';
77

8-
// Re-export selenium-webdriver types.
9-
// TODO(selenium4): Actions class typings missing. ActionSequence is deprecated.
10-
export {/*Actions,*/ Browser, Builder, Button, Capabilities, Capability, error, EventEmitter, FileDetector, Key, logging, promise, Session, until, WebDriver, WebElement, WebElementPromise} from 'selenium-webdriver';
8+
// Re-export selenium-webdriver types from typings directory.
9+
export {Actions, Browser, Builder, Button, Capabilities, Capability, error, EventEmitter, FileDetector, Key, logging, promise, Session, until, WebDriver, WebElement, WebElementPromise} from 'selenium-webdriver';
1110
// Re-export public types.
1211
export {ElementHelper, ProtractorBrowser} from './browser';
1312
export {Config} from './config';
@@ -20,14 +19,13 @@ export {Runner} from './runner';
2019
export type PluginConfig = PluginConfig;
2120
export type ProtractorPlugin = ProtractorPlugin;
2221

23-
export let utils = {
22+
export const utils = {
2423
firefox: require('selenium-webdriver/firefox'),
2524
http: require('selenium-webdriver/http'),
2625
remote: require('selenium-webdriver/remote')
2726
};
2827

29-
export let Command = require('selenium-webdriver/lib/command').Command;
30-
export let CommandName = require('selenium-webdriver/lib/command').Name;
28+
export {Command, Name as CommandName} from 'selenium-webdriver/lib/command';
3129

3230
// Export API instances based on the global Protractor object.
3331
// We base this on NodeJS `global` because we do not want to mask

lib/locators.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class WebdriverBy {
1010
css: (css: string) => By = By.css;
1111
id: (id: string) => By = By.id;
1212
linkText: (linkText: string) => By = By.linkText;
13-
js: (js: string|Function, ...var_args: any[]) => By = By.js;
13+
js: (js: string|Function, ...var_args: any[]) => (webdriver: WebDriver) => Promise<any> = By.js;
1414
name: (name: string) => By = By.name;
1515
partialLinkText: (partialText: string) => By = By.partialLinkText;
1616
tagName: (tagName: string) => By = By.tagName;

0 commit comments

Comments
 (0)