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

This commit is contained in:
Pavel Feldman 2021-12-03 10:22:50 -08:00
parent 9fe65beb93
commit 8e29c814df
2 changed files with 8 additions and 2 deletions

View file

@ -1087,10 +1087,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');