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

fix(jasmine): Pass controlflow to jasminewd #3517

Closed
wants to merge 5 commits into from
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ chromedriver.log
libpeerconnection.log
xmloutput*
npm-debug.log
.idea/

*.swp
globals.js
Expand Down
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.31",
"@types/node": "^6.0.35"
}
}
4 changes: 4 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ gulp.task('types', function(done) {
'config', 'plugins', 'ptor'];
var outputFile = path.resolve(folder, 'index.d.ts');
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
102 changes: 62 additions & 40 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 @@ -242,9 +241,13 @@ export class ProtractorBrowser extends Webdriver {
*/
debuggerServerPort_: number;

/**
* Set to true when we validate that the debug port is open. Since the debug
* port is held open forever once the debugger is attached, it's important
* we only do validation once.
*/
debuggerValidated_: boolean;


/**
* If true, Protractor will interpret any angular apps it comes across as
* hybrid angular1/angular2 apps.
Expand All @@ -257,7 +260,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 All @@ -269,7 +272,8 @@ export class ProtractorBrowser extends Webdriver {
// Mix all other driver functionality into Protractor.
Object.getOwnPropertyNames(webdriver.WebDriver.prototype)
.forEach((method: string) => {
if (!this[method] && typeof webdriverInstance[method] == 'function') {
if (!this[method] &&
typeof(webdriverInstance as any)[method] == 'function') {
if (methodsToSync.indexOf(method) !== -1) {
ptorMixin(
this, webdriverInstance, method,
Expand Down Expand Up @@ -321,7 +325,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 @@ -373,7 +377,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 @@ -400,7 +404,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 @@ -422,15 +426,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 @@ -492,22 +496,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 @@ -548,7 +552,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 All @@ -570,9 +574,10 @@ export class ProtractorBrowser extends Webdriver {
*/
isElementPresent(locatorOrElement: webdriver.Locator|
webdriver.WebElement): webdriver.promise.Promise<any> {
let element = (locatorOrElement.isPresent) ? locatorOrElement :
this.element(locatorOrElement);
return element.isPresent();
let element = ((locatorOrElement as any).isPresent) ?
locatorOrElement :
this.element(locatorOrElement);
return (element as any).isPresent();
}

/**
Expand Down Expand Up @@ -870,7 +875,7 @@ export class ProtractorBrowser extends Webdriver {
* Mixin navigation methods back into the navigation object so that
* they are invoked as before, i.e. driver.navigate().refresh()
*/
navigate() {
navigate(): any {
let nav = this.driver.navigate();
ptorMixin(nav, this, 'refresh');
return nav;
Expand Down Expand Up @@ -982,10 +987,12 @@ export class ProtractorBrowser extends Webdriver {
}
});

return doneDeferred.then(null, (err: string) => {
console.error(err);
process.exit(1);
});
return doneDeferred.then(
() => { this.debuggerValidated_ = true; },
(err: string) => {
console.error(err);
process.exit(1);
});
}

private dbgCodeExecutor_: any;
Expand Down Expand Up @@ -1042,10 +1049,10 @@ export class ProtractorBrowser extends Webdriver {

let browserUnderDebug = this;
let debuggerReadyPromise = webdriver.promise.defer();
flow.execute(function() {
flow.execute(() => {
process['debugPort'] = opt_debugPort || process['debugPort'];
browserUnderDebug.validatePortAvailability_(process['debugPort'])
.then(function(firstTime: boolean) {
.then((firstTime: boolean) => {
onStartFn(firstTime);

let args = [process.pid, process['debugPort']];
Expand All @@ -1055,11 +1062,19 @@ export class ProtractorBrowser extends Webdriver {
let nodedebug =
require('child_process').fork(debuggerClientPath, args);
process.on('exit', function() { nodedebug.kill('SIGTERM'); });
nodedebug.on('message', function(m: string) {
if (m === 'ready') {
debuggerReadyPromise.fulfill();
}
});
nodedebug
.on('message',
(m: string) => {
if (m === 'ready') {
debuggerReadyPromise.fulfill();
}
})
.on('exit', () => {
logger.info('Debugger exiting');
// Clear this so that we know it's ok to attach a debugger
// again.
this.dbgCodeExecutor_ = null;
});
});
});

Expand Down Expand Up @@ -1166,6 +1181,8 @@ export class ProtractorBrowser extends Webdriver {
return this.execPromiseResult_;
}
};

return pausePromise;
}

/**
Expand Down Expand Up @@ -1220,7 +1237,12 @@ export class ProtractorBrowser extends Webdriver {
* @param {number=} opt_debugPort Optional port to use for the debugging
* process
*/
pause(opt_debugPort?: number) {
pause(opt_debugPort?: number): webdriver.promise.Promise<any> {
if (this.dbgCodeExecutor_) {
logger.info(
'Encountered browser.pause(), but debugger already attached.');
return webdriver.promise.fulfilled(true);
}
let debuggerClientPath = __dirname + '/debugger/clients/wddebugger.js';
let onStartFn = (firstTime: boolean) => {
logger.info();
Expand All @@ -1239,7 +1261,7 @@ export class ProtractorBrowser extends Webdriver {
logger.info();
}
};
this.initDebugger_(debuggerClientPath, onStartFn, opt_debugPort);
return this.initDebugger_(debuggerClientPath, onStartFn, opt_debugPort);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/debugger/clients/wddebugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ WdDebugger.prototype.initRepl_ = function() {
self.replServer.on('exit', function() {
console.log('Resuming code execution');
self.client.req({command: 'disconnect'}, function() {
// Intentionally blank.
process.exit();
});
});
});
Expand Down
Loading