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

This commit is contained in:
Pavel Feldman 2021-12-03 10:22:50 -08:00 committed by GitHub
parent f583f1604c
commit aef0444ff5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View file

@ -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));
}

View file

@ -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');