Skip to content

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

chore: locator code style nits (#7972)

Max Schmitt2236d74f3f1a
diff --git a/src/client/locator.ts b/src/client/locator.ts
index 3ec73d4b81..07af9237b3 100644
--- a/src/client/locator.ts
+++ b/src/client/locator.ts
@@ -34,10 +34,10 @@ export class Locator implements api.Locator {
private async _withElement<R, O extends TimeoutOptions>(task: (handle: ElementHandle<SVGElement | HTMLElement>, options?: O) => Promise<R>, options?: O): Promise<R> {
if (!options)
- options = {} as any;
+ options = {} as O;
const timeout = this._frame.page()._timeoutSettings.timeout(options!);
const deadline = timeout ? monotonicTime() + timeout : 0;
- const handle = await this.elementHandle(options);
+ const handle = await this.elementHandle({ timeout });
if (!handle)
throw new Error(`Could not resolve ${this._selector} to DOM Element`);
try {
@@ -68,15 +68,15 @@ export class Locator implements api.Locator {
}
async evaluate<R, Arg>(pageFunction: structs.PageFunctionOn<SVGElement | HTMLElement, Arg, R>, arg?: Arg, options?: TimeoutOptions): Promise<R> {
- return this._withElement(h => h.evaluate(pageFunction as any, arg), { strict: true, ...options });
+ return this._withElement(h => h.evaluate(pageFunction, arg), { strict: true, ...options });
}
- async evaluateAll<R, Arg>(pageFunction: structs.PageFunctionOn<(SVGElement | HTMLElement)[], Arg, R>, arg?: Arg): Promise<R> {
- return this._frame.$$eval(this._selector, pageFunction as any, arg);
+ async evaluateAll<R, Arg>(pageFunction: structs.PageFunctionOn<Element[], Arg, R>, arg?: Arg): Promise<R> {
+ return this._frame.$$eval(this._selector, pageFunction, arg);
}
- async evaluateHandle<R, Arg>(pageFunction: structs.PageFunction<Arg, R>, arg?: Arg, options?: TimeoutOptions): Promise<structs.SmartHandle<R>> {
- return this._withElement(h => h.evaluateHandle(pageFunction as any, arg), { strict: true, ...options });
+ async evaluateHandle<R, Arg>(pageFunction: structs.PageFunctionOn<any, Arg, R>, arg?: Arg, options?: TimeoutOptions): Promise<structs.SmartHandle<R>> {
+ return this._withElement(h => h.evaluateHandle(pageFunction, arg), { strict: true, ...options });
}
async fill(value: string, options: channels.ElementHandleFillOptions = {}): Promise<void> {
@@ -88,8 +88,7 @@ export class Locator implements api.Locator {
}
async elementHandle(options?: TimeoutOptions): Promise<ElementHandle<SVGElement | HTMLElement>> {
- const result = await this._frame.waitForSelector(this._selector, { strict: true, state: 'attached', ...options });
- return result!;
+ return await this._frame.waitForSelector(this._selector, { strict: true, state: 'attached', ...options })!;
}
async elementHandles(): Promise<api.ElementHandle<SVGElement | HTMLElement>[]> {
diff --git a/tests/page/locator-convenience.spec.ts b/tests/page/locator-convenience.spec.ts
index a8cd9ed5b0..e9f146268c 100644
--- a/tests/page/locator-convenience.spec.ts
+++ b/tests/page/locator-convenience.spec.ts
@@ -200,12 +200,12 @@ it('isChecked should work', async ({page}) => {
expect(error.message).toContain('Not a checkbox or radio button');
});
-it('addTextContents should work', async ({page}) => {
+it('allTextContents should work', async ({page}) => {
await page.setContent(`<div>A</div><div>B</div><div>C</div>`);
expect(await page.locator('div').allTextContents()).toEqual(['A', 'B', 'C']);
});
-it('addInnerTexts should work', async ({page}) => {
+it('allInnerTexts should work', async ({page}) => {
await page.setContent(`<div>A</div><div>B</div><div>C</div>`);
expect(await page.locator('div').allInnerTexts()).toEqual(['A', 'B', 'C']);
});