Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/playwright-core/src/client/locator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,14 @@ export class Locator implements api.Locator {
}

async isHidden(options?: TimeoutOptions): Promise<boolean> {
if (options?.timeout !== undefined)
console.warn('locator.isHidden: "timeout" option is deprecated and has no effect. locator.isHidden() does not wait for the element and returns immediately.');
return await this._frame.isHidden(this._selector, { strict: true, ...options });
}

async isVisible(options?: TimeoutOptions): Promise<boolean> {
if (options?.timeout !== undefined)
console.warn('locator.isVisible: "timeout" option is deprecated and has no effect. locator.isVisible() does not wait for the element and returns immediately.');
return await this._frame.isVisible(this._selector, { strict: true, ...options });
}

Expand Down
34 changes: 34 additions & 0 deletions tests/page/locator-is-visible.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,37 @@ it('isVisible with invalid selector should throw', async ({ page }) => {
const error = await page.locator('hey=what').isVisible().catch(e => e);
expect(error.message).toContain('Unknown engine "hey" while parsing selector hey=what');
});

it('isVisible should warn when deprecated timeout option is used', async ({ page }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/33017' });
await page.setContent(`<div>Hi</div>`);
const warnings: string[] = [];
const origWarn = console.warn;
console.warn = (msg: string) => warnings.push(msg);
try {
const visible = await page.locator('div').isVisible({ timeout: 5000 });
expect(visible).toBe(true);
expect(warnings.length).toBe(1);
expect(warnings[0]).toContain('timeout');
expect(warnings[0]).toContain('deprecated');
} finally {
console.warn = origWarn;
}
});

it('isHidden should warn when deprecated timeout option is used', async ({ page }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/33017' });
await page.setContent(`<div>Hi</div>`);
const warnings: string[] = [];
const origWarn = console.warn;
console.warn = (msg: string) => warnings.push(msg);
try {
const hidden = await page.locator('div').isHidden({ timeout: 5000 });
expect(hidden).toBe(false);
expect(warnings.length).toBe(1);
expect(warnings[0]).toContain('timeout');
expect(warnings[0]).toContain('deprecated');
} finally {
console.warn = origWarn;
}
});