Add an async init hook
See original GitHub issueIt would we good to have an asynchronous called init hook.
I tried to implement a helper for the selenium-standalone package. Ideally it should use the _init hook of a helper. So my code looked like this:
const selenium = require('selenium-standalone');
'use strict';
class SeleniumHelper extends Helper {
_init() {
return selenium.install({logger: function(message) {
console.log(message);
}}, function() {
selenium.start(() => {console.log('blub')});
});
}
}
module.exports = SeleniumHelper;
The problem is here, that the _init hook is called synchronously in the lib/listener/helpers.js
event.dispatcher.on(event.all.before, function () {
runHelpersHook('_init');
});
This means, that the init will not wait for the selenium helper to be correctly initialized, so further steps will fails as selenium wasn’t started. Also the beforeSuite step is not helping as it is also called synchronously. Only the before hook would work.
By changing the above dispatch event to
event.dispatcher.on(event.all.before, function () {
runAsyncHelpersHook('_init');
});
The init would wait for the initialization of the selenium standalone to complete. But as there may be code in the wild relying on synchronous initialization, you may introduce a new hook which is called asynchronously.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
I also need this!
We have a new event/plugin system for that