Skip to content

Commit

Permalink
fix: add error catch on set page load timeout for edge with w3c support
Browse files Browse the repository at this point in the history
  • Loading branch information
DudaGod committed Apr 5, 2021
1 parent 5c70fe0 commit f7e438b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
11 changes: 10 additions & 1 deletion lib/browser/new-browser.js
Expand Up @@ -25,7 +25,16 @@ module.exports = class NewBrowser extends Browser {
return;
}

await this._session.setTimeout({'pageLoad': this._config.pageLoadTimeout});
try {
await this._session.setTimeout({pageLoad: this._config.pageLoadTimeout});
} catch (e) {
// edge with w3c does not support setting page load timeout
if (this._session.isW3C && this._session.capabilities.browserName === 'MicrosoftEdge') {
logger.warn(`WARNING: Can not set page load timeout: ${e.message}`);
} else {
throw e;
}
}
}

reset() {
Expand Down
38 changes: 35 additions & 3 deletions test/lib/browser/new-browser.js
Expand Up @@ -118,10 +118,42 @@ describe('NewBrowser', () => {
assert.notCalled(session.setTimeouts);
});

it('should set page load timeout if it is specified in a config', async () => {
await mkBrowser_({pageLoadTimeout: 100500}).init();
describe('set page load timeout if it is specified in a config', () => {
let browser;

assert.calledOnceWith(session.setTimeout, {'pageLoad': 100500});
beforeEach(() => {
browser = mkBrowser_({pageLoadTimeout: 100500});
});

it('should set timeout', async () => {
await browser.init();

assert.calledOnceWith(session.setTimeout, {'pageLoad': 100500});
});

[
{name: 'not in edge browser without w3c support', browserName: 'yabro', isW3C: false},
{name: 'not in edge browser with w3c support', browserName: 'yabro', isW3C: true},
{name: 'in edge browser without w3c support', browserName: 'MicrosoftEdge', isW3C: false}
].forEach(({name, browserName, isW3C}) => {
it(`should throw if set timeout failed ${name}`, async () => {
session.capabilities = {browserName};
session.isW3C = isW3C;
session.setTimeout.withArgs({pageLoad: 100500}).throws(new Error('o.O'));

await assert.isRejected(browser.init(), 'o.O');
assert.notCalled(logger.warn);
});
});

it('should not throw if set timeout failed in edge browser with w3c support', async () => {
session.capabilities = {browserName: 'MicrosoftEdge'};
session.isW3C = true;
session.setTimeout.withArgs({pageLoad: 100500}).throws(new Error('o.O'));

await assert.isFulfilled(browser.init());
assert.calledOnceWith(logger.warn, 'WARNING: Can not set page load timeout: o.O');
});
});
});

Expand Down
2 changes: 2 additions & 0 deletions test/lib/browser/utils.js
Expand Up @@ -57,8 +57,10 @@ exports.mkExistingBrowser_ = (opts, browser = 'browser', browserVersion, emitter

exports.mkSessionStub_ = () => {
const session = {};
session.isW3C = false;

session.options = {};
session.capabilities = {};
session.commandList = [];

session.deleteSession = sinon.stub().named('end').resolves();
Expand Down

0 comments on commit f7e438b

Please sign in to comment.