Skip to content

Commit

Permalink
Remove ElementHandle from e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
inokawa committed Nov 3, 2024
1 parent 31e0992 commit c38f1db
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions e2e/textarea.spec.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,48 @@
import { test, expect, Page, ElementHandle } from "@playwright/test";
import { test, expect, Page, Locator } from "@playwright/test";

const storyUrl = (id: string) =>
`http://localhost:6006/iframe.html?id=${id}&viewMode=story`;

const getTextarea = async (page: Page) => {
const textarea = await page.waitForSelector("textarea");
const backdrop = await textarea.evaluateHandle((e) => e.previousSibling!);
const textarea = page.locator("textarea");
const backdrop = page.locator("[aria-hidden]");
await Promise.all([textarea.waitFor(), backdrop.waitFor()]);
return [textarea, backdrop] as const;
};

const isFocused = async (handle: ElementHandle) => {
const isFocused = async (handle: Locator) => {
return handle.evaluate((e) => e === document.activeElement);
};

const getValue = async (
textarea: ElementHandle<HTMLTextAreaElement>,
backdrop: ElementHandle
textarea: Locator,
backdrop: Locator
): Promise<[string, string]> => {
const backdropValue = (await backdrop.textContent())!;

return [await textarea.inputValue(), backdropValue.replace(/\u200b$/, "")];
};

const getSelection = async (textarea: ElementHandle<HTMLTextAreaElement>) => {
return textarea.evaluate((e) => [e.selectionStart, e.selectionEnd]);
const getSelection = async (textarea: Locator) => {
return textarea.evaluate((e) => [
(e as HTMLInputElement).selectionStart,
(e as HTMLInputElement).selectionEnd,
]);
};

const getSize = async (textarea: ElementHandle): Promise<[number, number]> => {
const getSize = async (textarea: Locator): Promise<[number, number]> => {
const rect = (await textarea.boundingBox())!;
return [rect.width, rect.height];
};

const getScrollPosition = async (
handle: ElementHandle
handle: Locator
): Promise<[number, number]> => {
return handle.evaluate((e: HTMLElement) => [e.scrollLeft, e.scrollTop]);
};

const getBackdropPosition = async (
handle: ElementHandle
handle: Locator
): Promise<[number, number]> => {
return handle.evaluate((e: HTMLElement) => {
const transform = window.getComputedStyle(e.children[0]).transform;
Expand Down

0 comments on commit c38f1db

Please sign in to comment.