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

WIP - start fixing the debugger w/ selenium 3.0 #3788

Closed
wants to merge 3 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 @@ -12,6 +12,7 @@ libpeerconnection.log
xmloutput*
npm-debug.log
.idea/
.vscode/

*.swp

1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ built/spec/
.github/
.gitignore
.idea/
.vscode/
.jshintrc
.npmignore
.travis.yml
Expand Down
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: node_js
sudo: false
node_js:
- "4"
- "6"
- "7"

env:
global:
Expand All @@ -24,9 +24,9 @@ matrix:
- env: "JOB=bstack"
exclude:
- env: JOB=smoke
node_js: "6"
node_js: "7"
- env: JOB=bstack
node_js: "6"
node_js: "7"

addons:
apt:
Expand Down
4 changes: 2 additions & 2 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
machine:
node:
version: 6.9.1
environment:
# Fix issue with selenium-server in containers.
# See http://github.com/SeleniumHQ/docker-selenium/issues/87
DBUS_SESSION_BUS_ADDRESS: /dev/null
post:
- npm install -g npm@3

dependencies:
post:
Expand Down
40 changes: 23 additions & 17 deletions lib/debugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export class DebugHelper {
}
let sandbox = vm_.createContext(context);

let debuggerReadyPromise = webdriver.promise.defer();
flow.execute(() => {
let debuggerReadyPromise = webdriver.promise.defer();
process['debugPort'] = opt_debugPort || process['debugPort'];
this.validatePortAvailability_(process['debugPort']).then((firstTime: boolean) => {
onStartFn(firstTime);
Expand All @@ -95,6 +95,7 @@ export class DebugHelper {
.on('message',
(m: string) => {
if (m === 'ready') {
console.log('***** Debugger ready');
debuggerReadyPromise.fulfill();
}
})
Expand All @@ -105,14 +106,9 @@ export class DebugHelper {
this.dbgCodeExecutor = null;
});
});
});

let pausePromise = flow.execute(() => {
return debuggerReadyPromise.then(() => {
// Necessary for backward compatibility with node < 0.12.0
return this.browserUnderDebug_.executeScriptWithDescription('', 'empty debugger hook');
});
});
return debuggerReadyPromise.promise;
}, 'Set up debugger process');
let firstPromise = this.browserUnderDebug_.executeScriptWithDescription('var startHook = 1', 'kickoff hook');

// Helper used only by debuggers at './debugger/modes/*.js' to insert code
// into the control flow.
Expand All @@ -122,7 +118,8 @@ export class DebugHelper {
// for a result at every run of DeferredExecutor.execute.
let browserUnderDebug = this.browserUnderDebug_;
this.dbgCodeExecutor = {
execPromise_: pausePromise, // Promise pointing to current stage of flow.
execPromise_: firstPromise, // Promise pointing to current stage of flow.
// TODO(juliemr): We might need a pausePromise.then here...
execPromiseResult_: undefined, // Return value of promise.
execPromiseError_: undefined, // Error from promise.

Expand All @@ -139,6 +136,14 @@ export class DebugHelper {
execute_: function(execFn_: Function) {
this.execPromiseResult_ = this.execPromiseError_ = undefined;

// this.execPromise_ = this.execPromise_.then(execFn_).then(
// (result: Object) => {
// this.execPromiseResult_ = result;
// },
// (err: Error) => {
// this.execPromiseError_ = err;
// });

this.execPromise_ = this.execPromise_.then(execFn_).then(
(result: Object) => {
this.execPromiseResult_ = result;
Expand All @@ -147,11 +152,14 @@ export class DebugHelper {
this.execPromiseError_ = err;
});

// This dummy command is necessary so that the DeferredExecutor.execute
// break point can find something to stop at instead of moving on to the
// This dummy command is necessary so that the executor breakpoint
// can find something to stop at instead of moving on to the
// next real command.
this.execPromise_.then(() => {
return browserUnderDebug.executeScriptWithDescription('', 'empty debugger hook');
console.log('**** scheduling another debugger hook');
var r = browserUnderDebug.executeScriptWithDescription('var debuggerHook = 1', 'empty debugger hook');
console.log(flow.getSchedule());
return r;
});
},

Expand Down Expand Up @@ -200,7 +208,7 @@ export class DebugHelper {

// Code finished executing.
resultReady: function() {
return !this.execPromise_.isPending();
return !(this.execPromise_.state_ === 'pending');
},

// Get asynchronous results synchronously.
Expand All @@ -215,8 +223,6 @@ export class DebugHelper {
return this.execPromiseResult_;
}
};

return pausePromise;
}

/**
Expand Down Expand Up @@ -258,7 +264,7 @@ export class DebugHelper {
}
});

return doneDeferred.then(
return doneDeferred.promise.then(
() => {
this.debuggerValidated_ = true;
},
Expand Down
6 changes: 4 additions & 2 deletions lib/debugger/debuggerCommons.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ exports.attachDebugger = function(pid, opt_port) {
process._debugProcess(pid);

client.once('ready', function() {
console.log('---- setting breakpoint in http. Line number???');
client.setBreakpoint({
type: 'scriptRegExp',
target: '.*command\.js', //jshint ignore:line
line: 250
target: 'lib/http\.js', //jshint ignore:line
line: 321
// line: 436? 432?
}, function() {
process.send('ready');
client.reqContinue(function() {
Expand Down
3 changes: 3 additions & 0 deletions lib/debugger/modes/commandRepl.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ CommandRepl.prototype.complete = function(line, callback) {
CommandRepl.prototype.evaluate_ = function(expression, callback) {
var self = this;
var onbreak_ = function() {
console.log('---- in onbreak');
self.client.req({
command: 'evaluate',
arguments: {
Expand All @@ -91,6 +92,7 @@ CommandRepl.prototype.evaluate_ = function(expression, callback) {
} catch (e) {
callback(e, undefined);
}
console.log('---- removing onbreak listener');
self.client.removeListener('break', onbreak_);
});
} else {
Expand All @@ -103,6 +105,7 @@ CommandRepl.prototype.evaluate_ = function(expression, callback) {
});
};

console.log('---- adding onbreak listener');
this.client.on('break', onbreak_);

this.client.req({
Expand Down
5 changes: 3 additions & 2 deletions lib/driverProviders/attachSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {Logger} from '../logger';
import {DriverProvider} from './driverProvider';

let webdriver = require('selenium-webdriver');
let executors = require('selenium-webdriver/executors');
let http = require('selenium-webdriver/http');

let logger = new Logger('attachSession');

Expand Down Expand Up @@ -39,7 +39,8 @@ export class AttachSession extends DriverProvider {
* @return {WebDriver} webdriver instance
*/
getNewDriver(): webdriver.WebDriver {
var executor = executors.createExecutor(this.config_.seleniumAddress);
var httpClient = new http.HttpClient(this.config_.seleniumAddress);
var executor = new http.Executor(httpClient);
var newDriver = webdriver.WebDriver.attachToSession(executor, this.config_.seleniumSessionId);
this.drivers_.push(newDriver);
return newDriver;
Expand Down
11 changes: 8 additions & 3 deletions lib/driverProviders/direct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,19 @@ export class Direct extends DriverProvider {
throw new BrowserError(logger, 'Could not find chromedriver at ' + chromeDriverFile);
}

let service = new chrome.ServiceBuilder(chromeDriverFile).build();
driver = new chrome.Driver(new webdriver.Capabilities(this.config_.capabilities), service);
let chromeService = new chrome.ServiceBuilder(chromeDriverFile).build();
driver = chrome.Driver.createSession(
new webdriver.Capabilities(this.config_.capabilities), chromeService);
break;
case 'firefox':
if (this.config_.firefoxPath) {
this.config_.capabilities['firefox_binary'] = this.config_.firefoxPath;
}
driver = new firefox.Driver(this.config_.capabilities);

// TODO(cnishina): Add in a service builder with marionette. Direct connect
// currently supports FF legacy version 47.
driver =
firefox.Driver.createSession(new webdriver.Capabilities(this.config_.capabilities));
break;
default:
throw new BrowserError(
Expand Down
24 changes: 13 additions & 11 deletions lib/driverProviders/driverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,21 @@ export class DriverProvider {
}

let deferred = q.defer<webdriver.WebDriver>();
if (driver.getSession() === undefined) {
deferred.resolve();
} else {
driver.getSession().then((session_) => {
if (session_) {
driver.quit().then(function() {
driver.getSession()
.then((session_) => {
if (session_) {
driver.quit().then(function() {
deferred.resolve();
});
} else {
deferred.resolve();
});
} else {
}
})
.catch((error: Error) => {
// when the flow is shutdown, do nothing, and resolve.
deferred.resolve();
}
});
}
});

return deferred.promise;
}

Expand Down
14 changes: 7 additions & 7 deletions lib/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ let logger = new Logger('element');

let WEB_ELEMENT_FUNCTIONS = [
'click', 'sendKeys', 'getTagName', 'getCssValue', 'getAttribute', 'getText', 'getSize',
'getLocation', 'isEnabled', 'isSelected', 'submit', 'clear', 'isDisplayed', 'getOuterHtml',
'getInnerHtml', 'getId', 'getRawId', 'serialize', 'takeScreenshot'
'getLocation', 'isEnabled', 'isSelected', 'submit', 'clear', 'isDisplayed', 'getId', 'serialize',
'takeScreenshot'
];

export class WebdriverWebElement {}
Expand Down Expand Up @@ -423,8 +423,8 @@ export class ElementArrayFinder extends WebdriverWebElement {
(arr: WebElement[]) => {
return arr.length;
},
(err: IError) => {
if (err.code && err.code == new webdriver.error.NoSuchElementError()) {
(err: Error) => {
if (err instanceof error.NoSuchElementError) {
return 0;
} else {
throw err;
Expand Down Expand Up @@ -1078,15 +1078,15 @@ export class ElementFinder extends WebdriverWebElement {
return true; // is present, whether it is enabled or not
},
(err: any) => {
if (err.code == webdriver.error.ErrorCode.STALE_ELEMENT_REFERENCE) {
if (err instanceof error.StaleElementReferenceError) {
return false;
} else {
throw err;
}
});
},
(err: any) => {
if (err.code == webdriver.error.ErrorCode.NO_SUCH_ELEMENT) {
(err: Error) => {
if (err instanceof error.NoSuchElementError) {
return false;
} else {
throw err;
Expand Down
4 changes: 3 additions & 1 deletion lib/expectedConditions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {error} from 'selenium-webdriver';

import {ProtractorBrowser} from './browser';
import {ElementFinder} from './element';

Expand Down Expand Up @@ -163,7 +165,7 @@ export class ProtractorExpectedConditions {
return true;
},
(err: any) => {
if (err.code == webdriver.error.ErrorCode.NO_SUCH_ALERT) {
if (err instanceof error.NoSuchAlertError) {
return false;
} else {
throw err;
Expand Down
5 changes: 4 additions & 1 deletion lib/frameworks/explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ exports.run = function(runner) {
if (runner.getConfig().baseUrl) {
browser.get(runner.getConfig().baseUrl);
}
browser.executeScriptWithDescription('var prehook = 1', 'test to be removed, should happen first');
browser.enterRepl();
browser.executeScriptWithDescription('', 'empty debugger hook').then(function() {
browser.executeScriptWithDescription('var lastHook = 1', 'last empty debugger hook').then(function() {
console.log('**** explorer mode is done, resolving');
resolve({
failedCount: 0
});
});
console.log(browser.controlFlow().getSchedule());
});
};
Loading