fix(expect): do not produce logs twice (#22171)

This commit is contained in:
Dmitry Gozman 2023-04-03 15:05:40 -07:00 committed by GitHub
parent 590013e27b
commit 26c00a97a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 2 deletions

View File

@ -1381,9 +1381,10 @@ export class Frame extends SdkObject {
private async _expectInternal(metadata: CallMetadata, selector: string, options: FrameExpectParams, oneShot: boolean, timeout: number, lastIntermediateResult: { received?: any, isSet: boolean }): Promise<{ matches: boolean, received?: any, log?: string[], timedOut?: boolean }> {
const controller = new ProgressController(metadata, this);
return controller.run(async progress => {
if (oneShot)
if (oneShot) {
progress.log(`${metadata.apiName}${timeout ? ` with timeout ${timeout}ms` : ''}`);
progress.log(`waiting for ${this._asLocator(selector)}`);
progress.log(`waiting for ${this._asLocator(selector)}`);
}
return await this.retryWithProgressAndTimeouts(progress, [100, 250, 500, 1000], async continuePolling => {
const selectorInFrame = await this.selectors.resolveFrameForSelector(selector, { strict: true });
progress.throwIfAborted();

View File

@ -341,3 +341,32 @@ test.describe('toBeInViewport', () => {
await expect(page.locator('h1')).toBeInViewport();
});
});
test('toHaveCount should not produce logs twice', async ({ page }) => {
await page.setContent('<select><option>One</option></select>');
const error = await expect(page.locator('option')).toHaveCount(2, { timeout: 2000 }).catch(e => e);
const waitingForMessage = `waiting for locator('option')`;
expect(error.message).toContain(waitingForMessage);
expect(error.message).toContain(`locator resolved to 1 element`);
expect(error.message).toContain(`unexpected value "1"`);
expect(error.message.replace(waitingForMessage, '<redacted>')).not.toContain(waitingForMessage);
});
test('toHaveText should not produce logs twice', async ({ page }) => {
await page.setContent('<div>hello</div>');
const error = await expect(page.locator('div')).toHaveText('world', { timeout: 2000 }).catch(e => e);
const waitingForMessage = `waiting for locator('div')`;
expect(error.message).toContain(waitingForMessage);
expect(error.message).toContain(`locator resolved to <div>hello</div>`);
expect(error.message).toContain(`unexpected value "hello"`);
expect(error.message.replace(waitingForMessage, '<redacted>')).not.toContain(waitingForMessage);
});
test('toHaveText that does not match should not produce logs twice', async ({ page }) => {
await page.setContent('<div>hello</div>');
const error = await expect(page.locator('span')).toHaveText('world', { timeout: 2000 }).catch(e => e);
const waitingForMessage = `waiting for locator('span')`;
expect(error.message).toContain(waitingForMessage);
expect(error.message).not.toContain('locator resolved to');
expect(error.message.replace(waitingForMessage, '<redacted>')).not.toContain(waitingForMessage);
});