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

Commit

Permalink
chore(test): debugging specs
Browse files Browse the repository at this point in the history
using selenium standalon server 2.53.1

- upgrade to selenium-webdriver 3.0.x requires node version 6+, updating
  travis and circle yml to use node 6
- firefox 47 works
- selenium-webdriver/testing uses the global.it and cannot be
  reassigned as Protractor's global it. Required to copy some of their code
  to the lib/frameworks/mocha.js file
- WIP debugging tests... still have tests that are not passing.

using selenium standalone server 3.0.x

- firefox 49 with gecko driver 0.11.1 does not work
- firefox 48 with gecko driver 0.11.1 appears to work for
  a single test but after it quits, selenium standalone
  no longer works with firefox.
- when firefox 48 exists, logs show the following:

    ```
    20:01:14.814 INFO - Executing: [delete session: e353fa1b-e266-4ec3-afb3-88f11a82473a])
    [GFX1-]: Receive IPC close with reason=AbnormalShutdown
    [Child 30665] ###!!! ABORT: Aborting on channel error.: file /builds/slave/m-rel-m64-00000000000000000000/build/src/ipc/glue/MessageChannel.cpp, line 2052
    [Child 30665] ###!!! ABORT: Aborting on channel error.: file /builds/slave/m-rel-m64-00000000000000000000/build/src/ipc/glue/MessageChannel.cpp, line 2052
    ```
  • Loading branch information
cnishina committed Nov 17, 2016
1 parent 06c8703 commit 51eddd4
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 28 deletions.
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
5 changes: 2 additions & 3 deletions lib/driverProviders/attachSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ export class AttachSession extends DriverProvider {
* @return {WebDriver} webdriver instance
*/
getNewDriver(): webdriver.WebDriver {
var httpClient = http.HttpClient(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);
var newDriver = webdriver.WebDriver.attachToSession(executor, this.config_.seleniumSessionId);
this.drivers_.push(newDriver);
return newDriver;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ let clientSideScripts = require('./clientsidescripts');
let logger = new Logger('element');

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

export class WebdriverWebElement {}
Expand Down
132 changes: 118 additions & 14 deletions lib/frameworks/mocha.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var q = require('q');
var promise = require('selenium-webdriver').promise;

/**
* Execute the Runner's test cases through Mocha.
Expand All @@ -17,19 +18,14 @@ exports.run = function(runner, specs) {
// wait until then to load mocha-webdriver adapters as well.
mocha.suite.on('pre-require', function() {
try {
// We need to re-wrap all of the global functions, which selenium-webdriver/
// testing only does when it is required. So first we must remove it from
// the cache.
delete require.cache[require.resolve('selenium-webdriver/testing')];
var mochaAdapters = require('selenium-webdriver/testing');
global.after = mochaAdapters.after;
global.afterEach = mochaAdapters.afterEach;
global.before = mochaAdapters.before;
global.beforeEach = mochaAdapters.beforeEach;

global.it = mochaAdapters.it;
global.it.only = global.iit = mochaAdapters.iit;
global.it.skip = global.xit = mochaAdapters.xit;
global.after = wrapped(global.after);
global.afterEach = wrapped(global.afterEach);
global.before = wrapped(global.before);
global.beforeEach = wrapped(global.beforeEach);

global.it = wrapped(global.it);
global.it.only = wrapped(global.iit);
global.it.skip = wrapped(global.xit);
} catch (err) {
deferred.reject(err);
}
Expand All @@ -38,7 +34,6 @@ exports.run = function(runner, specs) {
mocha.loadFiles();

runner.runTestPreparer().then(function() {

specs.forEach(function(file) {
mocha.addFile(file);
});
Expand Down Expand Up @@ -99,3 +94,112 @@ exports.run = function(runner, specs) {

return deferred.promise;
};



var flow = (function() {
var initial = process.env['SELENIUM_PROMISE_MANAGER'];
try {
process.env['SELENIUM_PROMISE_MANAGER'] = '1';
return promise.controlFlow();
} finally {
if (initial === undefined) {
delete process.env['SELENIUM_PROMISE_MANAGER'];
} else {
process.env['SELENIUM_PROMISE_MANAGER'] = initial;
}
}
})();

/**
* Wraps a function on Mocha's BDD interface so it runs inside a
* webdriver.promise.ControlFlow and waits for the flow to complete before
* continuing.
* @param {!Function} globalFn The function to wrap.
* @return {!Function} The new function.
*/
function wrapped(globalFn) {
return function() {
if (arguments.length === 1) {
return globalFn(makeAsyncTestFn(arguments[0]));

} else if (arguments.length === 2) {
return globalFn(arguments[0], makeAsyncTestFn(arguments[1]));

} else {
throw Error('Invalid # arguments: ' + arguments.length);
}
};
}

/**
* Wraps a function so that all passed arguments are ignored.
* @param {!Function} fn The function to wrap.
* @return {!Function} The wrapped function.
*/
function seal(fn) {
return function() {
fn();
};
}

/**
* Make a wrapper to invoke caller's test function, fn. Run the test function
* within a ControlFlow.
*
* Should preserve the semantics of Mocha's Runnable.prototype.run (See
* https://github.com/mochajs/mocha/blob/master/lib/runnable.js#L192)
*
* @param {!Function} fn
* @return {!Function}
*/
function makeAsyncTestFn(fn) {
var isAsync = fn.length > 0;
var isGenerator = promise.isGenerator(fn);
if (isAsync && isGenerator) {
throw new TypeError(
'generator-based tests must not take a callback; for async testing,'
+ ' return a promise (or yield on a promise)');
}

var ret = /** @type {function(this: mocha.Context)}*/ function(done) {
var self = this;
var runTest = function(resolve, reject) {
try {
if (self.isAsync) {
fn.call(self, function(err) { err ? reject(err) : resolve(); });
} else if (self.isGenerator) {
resolve(promise.consume(fn, self));
} else {
resolve(fn.call(self));
}
} catch (ex) {
reject(ex);
}
};

if (!promise.USE_PROMISE_MANAGER) {
new promise.Promise(runTest).then(seal(done), done);
return;
}

var runnable = this.runnable();
var mochaCallback = runnable.callback;
runnable.callback = function() {
flow.reset();
return mochaCallback.apply(this, arguments);
};

flow.execute(function controlFlowExecute() {
return new promise.Promise(function(fulfill, reject) {
return runTest(fulfill, reject);
}, flow);
}, runnable.fullTitle()).then(seal(done), done);
};

ret.toString = function() {
return fn.toString();
};

return ret;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"saucelabs": "~1.3.0",
"selenium-webdriver": "3.0.1",
"source-map-support": "~0.4.0",
"webdriver-manager": "11.0.0-beta.0"
"webdriver-manager": "10.2.8"
},
"devDependencies": {
"@types/chalk": "^0.4.28",
Expand Down
2 changes: 1 addition & 1 deletion scripts/attachSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var sessionId = '';

// 1. Create a new selenium session.
var postData = JSON.stringify(
{'desiredCapabilities': {'browserName': 'firefox'}});
{'desiredCapabilities': {'browserName': 'chrome'}});
var createOptions = {
hostname: 'localhost',
port: 4444,
Expand Down
2 changes: 1 addition & 1 deletion spec/mocha/lib_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('protractor library', function() {
browser.get('index.html').then(function() { finished = true; });
});

after('verify mocha waited', function() {
after(function() {
if(!finished) { throw new Error('Mocha did not wait for async!'); }
});
});
Expand Down

0 comments on commit 51eddd4

Please sign in to comment.