Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(focus): make sure strictness is respected (#10685)

Pavel Feldmanaef0444ff546
diff --git a/packages/playwright-core/src/server/frames.ts b/packages/playwright-core/src/server/frames.ts
index 2fab5b3f1e..3747010872 100644
--- a/packages/playwright-core/src/server/frames.ts
+++ b/packages/playwright-core/src/server/frames.ts
@@ -1088,10 +1088,10 @@ export class Frame extends SdkObject {
}, this._page._timeoutSettings.timeout(options));
}
- async focus(metadata: CallMetadata, selector: string, options: types.TimeoutOptions = {}) {
+ async focus(metadata: CallMetadata, selector: string, options: types.TimeoutOptions & types.StrictOptions = {}) {
const controller = new ProgressController(metadata, this);
await controller.run(async progress => {
- dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, undefined, handle => handle._focus(progress)));
+ dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, handle => handle._focus(progress)));
await this._page._doSlowMo();
}, this._page._timeoutSettings.timeout(options));
}
diff --git a/tests/page/locator-misc-1.spec.ts b/tests/page/locator-misc-1.spec.ts
index 768cc007cc..4b19c4fb1a 100644
--- a/tests/page/locator-misc-1.spec.ts
+++ b/tests/page/locator-misc-1.spec.ts
@@ -87,6 +87,12 @@ it('should focus a button', async ({ page, server }) => {
expect(await button.evaluate(button => document.activeElement === button)).toBe(true);
});
+it('focus should respect strictness', async ({ page, server }) => {
+ await page.setContent('<div>A</div><div>B</div>');
+ const error = await page.locator('div').focus().catch(e => e);
+ expect(error.message).toContain('strict mode violation');
+});
+
it('should dispatch click event via ElementHandles', async ({ page, server }) => {
await page.goto(server.PREFIX + '/input/button.html');
const button = page.locator('button');