Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0a2809e

Browse files
authoredJan 25, 2019
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
}

0 commit comments

Comments
 (0)