feat(FrameManage): improve errors from frame.waitFor* methods (#2292)

This patch adds title for WaitTask, using it later in generating error messages and
making exceptions much more traceable.

Fixes #2037
This commit is contained in:
Yaniv Efraim
2018-03-30 22:37:56 +03:00
committed by Andrey Lushnikov
parent 8b0fd0ae4a
commit dde45faaeb
2 changed files with 18 additions and 5 deletions

View File

@@ -676,7 +676,7 @@ class Frame {
waitForFunction(pageFunction, options = {}, ...args) {
const timeout = helper.isNumber(options.timeout) ? options.timeout : 30000;
const polling = options.polling || 'raf';
return new WaitTask(this, pageFunction, polling, timeout, ...args).promise;
return new WaitTask(this, pageFunction, 'function', polling, timeout, ...args).promise;
}
/**
@@ -696,7 +696,8 @@ class Frame {
const waitForVisible = !!options.visible;
const waitForHidden = !!options.hidden;
const polling = waitForVisible || waitForHidden ? 'raf' : 'mutation';
return this.waitForFunction(predicate, {timeout: options.timeout, polling}, selectorOrXPath, isXPath, waitForVisible, waitForHidden);
const timeout = helper.isNumber(options.timeout) ? options.timeout : 30000;
return new WaitTask(this, predicate, `${isXPath ? 'XPath' : 'selector'} "${selectorOrXPath}"`, polling, timeout, selectorOrXPath, isXPath, waitForVisible, waitForHidden).promise;
/**
* @param {string} selectorOrXPath
@@ -769,7 +770,7 @@ class WaitTask {
* @param {number} timeout
* @param {!Array<*>} args
*/
constructor(frame, predicateBody, polling, timeout, ...args) {
constructor(frame, predicateBody, title, polling, timeout, ...args) {
if (helper.isString(polling))
console.assert(polling === 'raf' || polling === 'mutation', 'Unknown polling option: ' + polling);
else if (helper.isNumber(polling))
@@ -791,7 +792,7 @@ class WaitTask {
// Since page navigation requires us to re-install the pageScript, we should track
// timeout on our end.
if (timeout)
this._timeoutTimer = setTimeout(() => this.terminate(new Error(`waiting failed: timeout ${timeout}ms exceeded`)), timeout);
this._timeoutTimer = setTimeout(() => this.terminate(new Error(`waiting for ${title} failed: timeout ${timeout}ms exceeded`)), timeout);
this.rerun();
}