Skip to content

Commit

Permalink
Merge pull request #166 from gemini-testing/feature/new.browser.event
Browse files Browse the repository at this point in the history
feat: NEW_BROWSER event
  • Loading branch information
j0tunn authored Aug 8, 2017
2 parents d623eeb + 480401a commit fc43b26
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ Event | Description
`AFTER_FILE_READ` | Will be triggered on test files parsing right after reading the file. The handler accepts data object with `file`, `browser` (browser id string), `hermione` (helper which will be available in test file) and `suite` (collection of tests in a file; provides the ability to subscribe on `test` and `suite` events) fields.
`RUNNER_START` | Will be triggered before test execution. If a handler returns a promise, tests will be executed only after the promise is resolved. The handler accepts an instance of a runner as the first argument. You can use this instance to emit and subscribe to any other available events.
`RUNNER_END` | Will be triggered after test execution. If a handler returns a promise, tests will be executed only after the promise is resolved.
`NEW_BROWSER` | Will be triggered after new browser instance created. The handler accepts an instance of webdriverIO as the first argument and an object with a browser identifier as the second.
`SESSION_START` | Will be triggered after browser session initialization. If a handler returns a promise, tests will be executed only after the promise is resolved. The handler accepts an instance of webdriverIO as the first argument and an object with a browser identifier as the second.
`SESSION_END` | Will be triggered after the browser session ends. If a handler returns a promise, tests will be executed only after the promise is resolved. The handler accepts an instance of webdriverIO as the first argument and an object with a browser identifier as the second.
`BEGIN` | Will be triggered before test execution, but after all the runners are initialized.
Expand Down
9 changes: 6 additions & 3 deletions lib/browser-pool/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ exports.create = function(config, emitter) {
create: (id) => Browser.create(config, id),

start: (browser) => browser.init(),
onStart: (browser) => emitBrowserEvent(emitter, browser, Events.SESSION_START),
onStart: (browser) => {
emitter.emit(Events.NEW_BROWSER, browser.publicAPI, {browserId: browser.id});
return emitSessionEvent(emitter, browser, Events.SESSION_START);
},

onQuit: (browser) => emitBrowserEvent(emitter, browser, Events.SESSION_END),
onQuit: (browser) => emitSessionEvent(emitter, browser, Events.SESSION_END),
quit: (browser) => browser.quit()
};

Expand All @@ -38,6 +41,6 @@ exports.create = function(config, emitter) {
}));
};

function emitBrowserEvent(emitter, browser, event) {
function emitSessionEvent(emitter, browser, event) {
return emitter.emitAndWait(event, browser.publicAPI, {browserId: browser.id});
}
2 changes: 2 additions & 0 deletions lib/constants/runner-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const getSyncEvents = () => ({
BEFORE_FILE_READ: 'beforeFileRead',
AFTER_FILE_READ: 'afterFileRead',

NEW_BROWSER: 'newBrowser',

SUITE_BEGIN: 'beginSuite',
SUITE_END: 'endSuite',

Expand Down
14 changes: 14 additions & 0 deletions test/lib/browser-pool/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ describe('browser-pool', () => {
assert.becomes(getBrowserManager().start(browser), {session: 'id'});
});

it(`onStart should emit NEW_BROWSER event`, () => {
const emitter = new QEmitter();
const onNewBrowser = sandbox.spy();

BrowserPool.create(null, emitter);

const BrowserManager = getBrowserManager();

emitter.on(Events.NEW_BROWSER, onNewBrowser);

return BrowserManager.onStart(stubBrowser('bro', {public: 'api'}))
.then(() => assert.calledOnceWith(onNewBrowser, {public: 'api'}, {browserId: 'bro'}));
});

_.forEach({onStart: Events.SESSION_START, onQuit: Events.SESSION_END}, (event, method) => {
describe(`${method}`, () => {
it(`should emit browser event "${event}"`, () => {
Expand Down

0 comments on commit fc43b26

Please sign in to comment.