Skip to content

AI-native design editor. Open-source Figma alternative.

test(e2e): use Playwright test id locators

Danila Poyarkov2f94ce6510dd
diff --git a/tests/e2e/canvas/manipulation.spec.ts b/tests/e2e/canvas/manipulation.spec.ts
index 7b0078ae5..a210b8ea6 100644
--- a/tests/e2e/canvas/manipulation.spec.ts
+++ b/tests/e2e/canvas/manipulation.spec.ts
@@ -104,7 +104,7 @@ test('resize corner handle drag increases node dimensions', async () => {
})
expect(viewport).not.toBeNull()
- const box = await page.locator('[data-test-id="canvas-element"]').boundingBox()
+ const box = await page.getByTestId('canvas-element').boundingBox()
if (!box) throw new Error('No canvas')
const hx = box.x + expectDefined(viewport, 'viewport state').handleX
@@ -152,7 +152,7 @@ test('rotation handle drag rotates node', async () => {
})
expect(viewport).not.toBeNull()
- const box = await page.locator('[data-test-id="canvas-element"]').boundingBox()
+ const box = await page.getByTestId('canvas-element').boundingBox()
if (!box) throw new Error('No canvas')
const rx = box.x + expectDefined(viewport, 'viewport state').cx
@@ -326,7 +326,7 @@ test('rotation drag exposes live rotation preview state', async () => {
})
expect(viewport).not.toBeNull()
- const box = await page.locator('[data-test-id="canvas-element"]').boundingBox()
+ const box = await page.getByTestId('canvas-element').boundingBox()
if (!box) throw new Error('No canvas')
const rx = box.x + expectDefined(viewport, 'viewport state').cx
diff --git a/tests/e2e/chat/panel.spec.ts b/tests/e2e/chat/panel.spec.ts
index 06f146ca6..9c40c4731 100644
--- a/tests/e2e/chat/panel.spec.ts
+++ b/tests/e2e/chat/panel.spec.ts
@@ -123,7 +123,7 @@ function chatInput() {
}
function apiKeyInput() {
- return page.locator('[data-test-id="api-key-input"]')
+ return page.getByTestId('api-key-input')
}
test('⌘J switches to AI tab', async () => {
@@ -182,7 +182,7 @@ test('assistant responds', async () => {
})
test('model selector is visible and clickable', async () => {
- const trigger = page.locator('[data-test-id="chat-model-selector"]')
+ const trigger = page.getByTestId('chat-model-selector')
await expect(trigger).toBeVisible()
await trigger.click()
@@ -225,7 +225,7 @@ test('transport errors show an actionable toast', async () => {
await chatInput().press('Enter')
await expect(
- page.locator('[data-test-id="toast-item"]').filter({
+ page.getByTestId('toast-item').filter({
hasText: 'Install it with: npm i -g @agentclientprotocol/claude-agent-acp'
})
).toBeVisible({ timeout: 5000 })
@@ -237,7 +237,7 @@ test('"Get API key" link opens external URL via window.open', async () => {
await canvas.waitForInit()
await chatTab().click()
- const link = page.locator('[data-test-id="api-key-get-link"]')
+ const link = page.getByTestId('api-key-get-link')
await expect(link).toBeVisible()
// Intercept window.open to verify it's called with the right URL
diff --git a/tests/e2e/code/panel.spec.ts b/tests/e2e/code/panel.spec.ts
index d167f4896..0958095a2 100644
--- a/tests/e2e/code/panel.spec.ts
+++ b/tests/e2e/code/panel.spec.ts
@@ -19,27 +19,27 @@ test.afterAll(async () => {
})
function codeTab() {
- return page.locator('[data-test-id="properties-tab-code"]')
+ return page.getByTestId('properties-tab-code')
}
function designTab() {
- return page.locator('[data-test-id="properties-tab-design"]')
+ return page.getByTestId('properties-tab-design')
}
function codePanel() {
- return page.locator('[data-test-id="code-panel"]')
+ return page.getByTestId('code-panel')
}
function codePanelEmpty() {
- return page.locator('[data-test-id="code-panel-empty"]')
+ return page.getByTestId('code-panel-empty')
}
function formatToggle() {
- return page.locator('[data-test-id="code-panel-format-toggle"]')
+ return page.getByTestId('code-panel-format-toggle')
}
function copyButton() {
- return page.locator('[data-test-id="code-panel-copy"]')
+ return page.getByTestId('code-panel-copy')
}
test('Code tab shows empty state with no selection', async () => {
diff --git a/tests/e2e/color-picker/basic.spec.ts b/tests/e2e/color-picker/basic.spec.ts
index 9f64a5203..a5f6c2d52 100644
--- a/tests/e2e/color-picker/basic.spec.ts
+++ b/tests/e2e/color-picker/basic.spec.ts
@@ -30,15 +30,15 @@ async function getSelectedFill() {
}
async function openFillPicker() {
- const solidTab = page.locator('[data-test-id="fill-picker-tab-solid"]')
+ const solidTab = page.getByTestId('fill-picker-tab-solid')
if (await solidTab.isVisible().catch(() => false)) return
- const swatch = page.locator('[data-test-id="fill-picker-swatch"]').first()
+ const swatch = page.getByTestId('fill-picker-swatch').first()
await swatch.click()
await expect(solidTab).toBeVisible()
}
async function chooseFormat(label: 'RGB' | 'HSL' | 'HSB' | 'OkHCL') {
- await page.locator('[data-test-id="color-format-select"]').click()
+ await page.getByTestId('color-format-select').click()
await page.getByRole('option', { name: label, exact: true }).click()
}
diff --git a/tests/e2e/color-picker/demo-card.spec.ts b/tests/e2e/color-picker/demo-card.spec.ts
index 96c01de74..f2889715a 100644
--- a/tests/e2e/color-picker/demo-card.spec.ts
+++ b/tests/e2e/color-picker/demo-card.spec.ts
@@ -43,8 +43,8 @@ async function selectDemoCard(page: Parameters<typeof test>[0]['page'], canvas:
})
await canvas.waitForRender()
- await expect(page.locator('[data-test-id="design-panel-single"]')).toBeVisible()
- await expect(page.locator('[data-test-id="design-node-header"]')).toContainText('Card')
+ await expect(page.getByTestId('design-panel-single')).toBeVisible()
+ await expect(page.getByTestId('design-node-header')).toContainText('Card')
}
async function getSelectedFill(page: Parameters<typeof test>[0]['page']) {
@@ -87,8 +87,8 @@ test('demo card fill changes through color picker', async ({ page }) => {
const before = await getSelectedFillOrThrow(page)
- await page.locator('[data-test-id="fill-picker-swatch"]').first().click()
- await expect(page.locator('[data-test-id="fill-picker-tab-solid"]')).toBeVisible()
+ await page.getByTestId('fill-picker-swatch').first().click()
+ await expect(page.getByTestId('fill-picker-tab-solid')).toBeVisible()
await dragSlider(page, canvas, 'color-slider-hue', 0.7)
@@ -102,10 +102,10 @@ test('demo card fill changes from hsb saturation and brightness sliders', async
const canvas = new CanvasHelper(page)
await selectDemoCard(page, canvas)
- await page.locator('[data-test-id="fill-picker-swatch"]').first().click()
- await expect(page.locator('[data-test-id="fill-picker-tab-solid"]')).toBeVisible()
+ await page.getByTestId('fill-picker-swatch').first().click()
+ await expect(page.getByTestId('fill-picker-tab-solid')).toBeVisible()
await canvas.waitForRender()
- await page.locator('[data-test-id="color-format-select"]').click()
+ await page.getByTestId('color-format-select').click()
await page.getByRole('option', { name: 'HSB', exact: true }).click()
await canvas.waitForRender()
diff --git a/tests/e2e/components.spec.ts b/tests/e2e/components.spec.ts
index 754d1d1cb..4c8d1ca64 100644
--- a/tests/e2e/components.spec.ts
+++ b/tests/e2e/components.spec.ts
@@ -69,7 +69,7 @@ test('create component from selection (⌘⌥K)', async () => {
})
test('component shows purple label in design panel', async () => {
- const header = page.locator('[data-test-id="design-node-header"]')
+ const header = page.getByTestId('design-node-header')
await expect(header).toContainText('COMPONENT')
})
@@ -119,17 +119,17 @@ test('instance shows INSTANCE type in design panel', async () => {
}, instance.id)
await canvas.waitForRender()
- const header = page.locator('[data-test-id="design-node-header"]')
+ const header = page.getByTestId('design-node-header')
await expect(header).toContainText('INSTANCE')
})
test('instance has "Go to Main Component" button', async () => {
- const goToBtn = page.locator('[data-test-id="design-go-to-component"]')
+ const goToBtn = page.getByTestId('design-go-to-component')
await expect(goToBtn).toBeVisible()
})
test('instance has "Detach" button', async () => {
- const detachBtn = page.locator('[data-test-id="design-detach-instance"]')
+ const detachBtn = page.getByTestId('design-detach-instance')
await expect(detachBtn).toBeVisible()
})
diff --git a/tests/e2e/components/assets-panel.spec.ts b/tests/e2e/components/assets-panel.spec.ts
index 0ee68d505..613edcf79 100644
--- a/tests/e2e/components/assets-panel.spec.ts
+++ b/tests/e2e/components/assets-panel.spec.ts
@@ -111,44 +111,44 @@ test('assets panel groups component sets and inserts the default variant', async
})
await canvas.waitForRender()
- await page.locator('[data-test-id="left-panel-assets-tab"]').click()
+ await page.getByTestId('left-panel-assets-tab').click()
- const assetsPanel = page.locator('[data-test-id="assets-panel"]')
- const assetItems = page.locator('[data-test-id="asset-item"]')
+ const assetsPanel = page.getByTestId('assets-panel')
+ const assetItems = page.getByTestId('asset-item')
await expect(assetItems).toHaveCount(2)
await expect(assetsPanel).toContainText('Button')
await expect(assetsPanel).toContainText('Card')
await expect(assetsPanel).not.toContainText('Type=Primary')
await expect(assetsPanel).not.toContainText('Type=Secondary')
const buttonAsset = page.locator(`[data-asset-id="${ids.setId}"]`)
- await expect(buttonAsset.locator('[data-test-id="asset-variant-summary"]')).toContainText('Type')
- await expect(buttonAsset.locator('[data-test-id="asset-library-badge"]')).toContainText('Library')
- await expect(buttonAsset.locator('[data-test-id="asset-description"]')).toContainText(
+ await expect(buttonAsset.getByTestId('asset-variant-summary')).toContainText('Type')
+ await expect(buttonAsset.getByTestId('asset-library-badge')).toContainText('Library')
+ await expect(buttonAsset.getByTestId('asset-description')).toContainText(
'Reusable button component'
)
- await expect(buttonAsset.locator('[data-test-id="asset-docs"]')).toBeVisible()
- await expect(buttonAsset.locator('[data-test-id="asset-variant-conflict"]')).toContainText(
+ await expect(buttonAsset.getByTestId('asset-docs')).toBeVisible()
+ await expect(buttonAsset.getByTestId('asset-variant-conflict')).toContainText(
'Duplicate variant values'
)
await buttonAsset.click()
- const details = page.locator('[data-test-id="asset-details-dialog"]')
+ const details = page.getByTestId('asset-details-dialog')
await expect(details).toBeVisible()
await expect(details).toContainText('Button')
- await expect(details.locator('[data-test-id="asset-details-preview"]')).toBeVisible()
- await expect(details.locator('[data-test-id="asset-details-preview-image"]')).toBeVisible()
- await expect(details.locator('[data-test-id="asset-details-description"]')).toContainText(
+ await expect(details.getByTestId('asset-details-preview')).toBeVisible()
+ await expect(details.getByTestId('asset-details-preview-image')).toBeVisible()
+ await expect(details.getByTestId('asset-details-description')).toContainText(
'Reusable button component'
)
- await expect(details.locator('[data-test-id="asset-details-library"]')).toContainText(
+ await expect(details.getByTestId('asset-details-library')).toContainText(
'lk-test-library'
)
- await expect(details.locator('[data-test-id="asset-details-docs"]')).toBeVisible()
- await expect(details.locator('[data-test-id="asset-details-property"]')).toContainText('Type')
- await page.locator('[data-test-id="asset-details-close"]').click()
+ await expect(details.getByTestId('asset-details-docs')).toBeVisible()
+ await expect(details.getByTestId('asset-details-property')).toContainText('Type')
+ await page.getByTestId('asset-details-close').click()
await expect(details).toBeHidden()
- await page.locator('[data-test-id="assets-search"]').fill('card')
+ await page.getByTestId('assets-search').fill('card')
await expect(assetItems).toHaveCount(1)
await expect(assetsPanel).toContainText('Card')
await page.locator(`[data-asset-id="${ids.cardId}"] [data-test-id="asset-insert"]`).click()
@@ -158,11 +158,11 @@ test('assets panel groups component sets and inserts the default variant', async
expect(cardInstance?.type).toBe('INSTANCE')
expect(cardInstance?.componentId).toBe(ids.cardId)
- await page.locator('[data-test-id="assets-search"]').fill('missing asset')
- await expect(page.locator('[data-test-id="assets-empty"]')).toBeVisible()
+ await page.getByTestId('assets-search').fill('missing asset')
+ await expect(page.getByTestId('assets-empty')).toBeVisible()
await expect(assetItems).toHaveCount(0)
- await page.locator('[data-test-id="assets-search"]').fill('button')
+ await page.getByTestId('assets-search').fill('button')
await expect(assetItems).toHaveCount(1)
await page.locator(`[data-asset-id="${ids.setId}"] [data-test-id="asset-insert"]`).click()
await canvas.waitForRender()
@@ -175,7 +175,7 @@ test('assets panel groups component sets and inserts the default variant', async
expect(inserted?.width).toBe(132)
expect(inserted?.childTexts).toEqual(['Secondary'])
- await expect(page.locator('[data-test-id="variant-section"]')).toBeVisible()
+ await expect(page.getByTestId('variant-section')).toBeVisible()
await page.locator('[data-test-id="variant-section"] [data-test-id="app-select-trigger"]').click()
await page.getByRole('option', { name: 'Primary' }).click()
@@ -222,7 +222,7 @@ test('assets insertion accounts for entered container coordinates', async ({ pag
})
await canvas.waitForRender()
- await page.locator('[data-test-id="left-panel-assets-tab"]').click()
+ await page.getByTestId('left-panel-assets-tab').click()
await page.locator(`[data-asset-id="${setup.componentId}"] [data-test-id="asset-insert"]`).click()
await canvas.waitForRender()
@@ -259,8 +259,8 @@ test('demo exposes component set assets', async ({ page }) => {
await page.goto('/demo')
await canvas.waitForInit()
- await page.locator('[data-test-id="left-panel-assets-tab"]').click()
- const assetsPanel = page.locator('[data-test-id="assets-panel"]')
+ await page.getByTestId('left-panel-assets-tab').click()
+ const assetsPanel = page.getByTestId('assets-panel')
await expect(assetsPanel).toContainText('Button')
await expect(assetsPanel).toContainText('2 variants · Variant')
diff --git a/tests/e2e/design/panel.spec.ts b/tests/e2e/design/panel.spec.ts
index 12b3a2dc8..11f1ddbed 100644
--- a/tests/e2e/design/panel.spec.ts
+++ b/tests/e2e/design/panel.spec.ts
@@ -20,27 +20,27 @@ test.afterAll(async () => {
})
function designPanel() {
- return page.locator('[data-test-id="design-panel-single"]')
+ return page.getByTestId('design-panel-single')
}
function nodeHeader() {
- return page.locator('[data-test-id="design-node-header"]')
+ return page.getByTestId('design-node-header')
}
function fillSection() {
- return page.locator('[data-test-id="fill-section"]')
+ return page.getByTestId('fill-section')
}
function strokeSection() {
- return page.locator('[data-test-id="stroke-section"]')
+ return page.getByTestId('stroke-section')
}
function positionSection() {
- return page.locator('[data-test-id="position-section"]')
+ return page.getByTestId('position-section')
}
function effectsSection() {
- return page.locator('[data-test-id="effects-section"]')
+ return page.getByTestId('effects-section')
}
function getNode(id: string) {
@@ -84,7 +84,7 @@ test('selecting a rectangle shows design panel with type and name', async () =>
test('position section shows X, Y, rotation inputs', async () => {
await expect(positionSection()).toBeVisible()
- const inputs = positionSection().locator('[data-test-id="scrub-input"]')
+ const inputs = positionSection().getByTestId('scrub-input')
const count = await inputs.count()
expect(count).toBeGreaterThanOrEqual(3)
})
@@ -92,12 +92,12 @@ test('position section shows X, Y, rotation inputs', async () => {
test('fill section appears with default fill', async () => {
await expect(fillSection()).toBeVisible()
- const fillItems = fillSection().locator('[data-test-id="fill-item"]')
+ const fillItems = fillSection().getByTestId('fill-item')
await expect(fillItems.first()).toBeVisible()
})
test('fill item shows color swatch', async () => {
- const swatch = fillSection().locator('[data-test-id="fill-picker-swatch"]').first()
+ const swatch = fillSection().getByTestId('fill-picker-swatch').first()
await expect(swatch).toBeVisible()
})
@@ -105,7 +105,7 @@ test('clicking color area changes fill color', async () => {
const id = await getSelectedId()
const before = await getNode(expectDefined(id, 'selected id'))
- const swatch = fillSection().locator('[data-test-id="fill-picker-swatch"]').first()
+ const swatch = fillSection().getByTestId('fill-picker-swatch').first()
await swatch.click()
const colorArea = page.locator('.cursor-crosshair').first()
@@ -130,11 +130,11 @@ test('clicking color area changes fill color', async () => {
})
test('adding a stroke creates stroke section item', async () => {
- const addBtn = strokeSection().locator('[data-test-id="stroke-section-add"]')
+ const addBtn = strokeSection().getByTestId('stroke-section-add')
await addBtn.click()
await canvas.waitForRender()
- const strokeItems = strokeSection().locator('[data-test-id="stroke-item"]')
+ const strokeItems = strokeSection().getByTestId('stroke-item')
await expect(strokeItems.first()).toBeVisible()
const id = await getSelectedId()
@@ -143,11 +143,11 @@ test('adding a stroke creates stroke section item', async () => {
})
test('adding an effect creates effect item', async () => {
- const addBtn = effectsSection().locator('[data-test-id="effects-section-add"]')
+ const addBtn = effectsSection().getByTestId('effects-section-add')
await addBtn.click()
await canvas.waitForRender()
- const effectItems = effectsSection().locator('[data-test-id="effect-item"]')
+ const effectItems = effectsSection().getByTestId('effect-item')
await expect(effectItems.first()).toBeVisible()
const id = await getSelectedId()
@@ -156,11 +156,11 @@ test('adding an effect creates effect item', async () => {
})
test('adding a second fill shows two fill items', async () => {
- const addBtn = fillSection().locator('[data-test-id="fill-section-add"]')
+ const addBtn = fillSection().getByTestId('fill-section-add')
await addBtn.click()
await canvas.waitForRender()
- const fillItems = fillSection().locator('[data-test-id="fill-item"]')
+ const fillItems = fillSection().getByTestId('fill-item')
expect(await fillItems.count()).toBe(2)
const id = await getSelectedId()
@@ -169,7 +169,7 @@ test('adding a second fill shows two fill items', async () => {
})
test('visibility toggle in appearance section works', async () => {
- const visBtn = page.locator('[data-test-id="appearance-visibility"]')
+ const visBtn = page.getByTestId('appearance-visibility')
await expect(visBtn).toBeVisible()
const id = await getSelectedId()
@@ -193,7 +193,7 @@ test('fill stroke and effect visibility toggles update on repeated clicks and su
const id = await getSelectedId()
expect(id).toBeTruthy()
- const fillButton = page.locator('[data-test-id="fill-visibility-0"]')
+ const fillButton = page.getByTestId('fill-visibility-0')
await expect(fillButton).toBeVisible()
const initial = await getNode(expectDefined(id, 'selected id'))
@@ -226,11 +226,11 @@ test('fill stroke and effect visibility toggles update on repeated clicks and su
?.visible
).toBe(true)
- const strokeAddButton = strokeSection().locator('[data-test-id="stroke-section-add"]')
+ const strokeAddButton = strokeSection().getByTestId('stroke-section-add')
await strokeAddButton.click()
await canvas.waitForRender()
- const strokeButton = page.locator('[data-test-id="stroke-visibility-0"]')
+ const strokeButton = page.getByTestId('stroke-visibility-0')
await expect(strokeButton).toBeVisible()
expect(
expectDefined(await getNode(expectDefined(id, 'selected id')), 'selected node').strokes[0]
@@ -264,11 +264,11 @@ test('fill stroke and effect visibility toggles update on repeated clicks and su
?.visible
).toBe(true)
- const effectAddButton = effectsSection().locator('[data-test-id="effects-section-add"]')
+ const effectAddButton = effectsSection().getByTestId('effects-section-add')
await effectAddButton.click()
await canvas.waitForRender()
- const effectButton = page.locator('[data-test-id="effect-visibility-0"]')
+ const effectButton = page.getByTestId('effect-visibility-0')
await expect(effectButton).toBeVisible()
expect(
expectDefined(await getNode(expectDefined(id, 'selected id')), 'selected node').effects[0]
@@ -307,7 +307,7 @@ test('deselecting shows empty design panel', async () => {
await page.keyboard.press('Escape')
await canvas.waitForRender()
- await expect(page.locator('[data-test-id="design-panel-empty"]')).toBeVisible()
+ await expect(page.getByTestId('design-panel-empty')).toBeVisible()
})
test('multi-select shows mixed header', async () => {
@@ -316,7 +316,7 @@ test('multi-select shows mixed header', async () => {
await canvas.selectAll()
await canvas.waitForRender()
- const multiHeader = page.locator('[data-test-id="design-multi-header"]')
+ const multiHeader = page.getByTestId('design-multi-header')
await expect(multiHeader).toBeVisible()
await expect(multiHeader).toContainText('Mixed')
await expect(multiHeader).toContainText('layers')
diff --git a/tests/e2e/editor/auto-layout/basic.spec.ts b/tests/e2e/editor/auto-layout/basic.spec.ts
index 45a7009bb..3291cc332 100644
--- a/tests/e2e/editor/auto-layout/basic.spec.ts
+++ b/tests/e2e/editor/auto-layout/basic.spec.ts
@@ -55,7 +55,7 @@ test('Shift+A wraps selection in auto-layout frame', async () => {
test('direction button toggles to VERTICAL', async () => {
await selectFrame()
- await page.locator('[data-test-id="layout-direction-vertical"]').click()
+ await page.getByTestId('layout-direction-vertical').click()
await canvas.waitForRender()
const frame = await getNodeById(page, frameId)
@@ -68,7 +68,7 @@ test('gap ScrubInput sets itemSpacing', async () => {
const before = await getNodeById(page, frameId)
const initialSpacing = expectDefined(before, 'before').itemSpacing
- await canvas.dragScrubInput(page.locator('[data-test-id="layout-gap-input"]'), 40)
+ await canvas.dragScrubInput(page.getByTestId('layout-gap-input'), 40)
const after = await getNodeById(page, frameId)
expect(expectDefined(after, 'after').itemSpacing).toBeGreaterThan(initialSpacing + 5)
@@ -78,14 +78,14 @@ test('gap ScrubInput sets itemSpacing', async () => {
test('gap menu sets auto space-between alignment', async () => {
await selectFrame()
- await page.locator('[data-test-id="layout-gap-menu"]').click()
+ await page.getByTestId('layout-gap-menu').click()
await page.getByRole('option', { name: 'Auto' }).click()
await canvas.waitForRender()
let frame = await getNodeById(page, frameId)
expect(expectDefined(frame, 'frame').primaryAxisAlign).toBe('SPACE_BETWEEN')
await expect(page.locator('[data-test-id="layout-alignment-grid"] button')).toHaveCount(9)
- await page.locator('[data-test-id="layout-gap-menu"]').click()
+ await page.getByTestId('layout-gap-menu').click()
await page
.getByRole('option', { name: String(Math.round(expectDefined(frame, 'frame').itemSpacing)) })
.click()
@@ -100,12 +100,12 @@ test('gap menu sets auto space-between alignment', async () => {
test('wrap mode exposes cross-axis gap control', async () => {
await selectFrame()
- await page.locator('[data-test-id="layout-direction-wrap"]').click()
+ await page.getByTestId('layout-direction-wrap').click()
await canvas.waitForRender()
const before = await getNodeById(page, frameId)
const initialSpacing = expectDefined(before, 'before').counterAxisSpacing
- await canvas.dragScrubInput(page.locator('[data-test-id="layout-cross-gap-input"]'), 40)
+ await canvas.dragScrubInput(page.getByTestId('layout-cross-gap-input'), 40)
const after = await getNodeById(page, frameId)
expect(expectDefined(after, 'after').layoutWrap).toBe('WRAP')
@@ -116,7 +116,7 @@ test('wrap mode exposes cross-axis gap control', async () => {
test('padding controls set horizontal and vertical padding pairs', async () => {
await selectFrame()
- await page.locator('[data-test-id="layout-horizontal-padding-input"]').click()
+ await page.getByTestId('layout-horizontal-padding-input').click()
await canvas.waitForRender()
const horizontalInput = page.locator(
'[data-test-id="layout-horizontal-padding-input"] [data-test-id="scrub-input-field"]'
@@ -125,7 +125,7 @@ test('padding controls set horizontal and vertical padding pairs', async () => {
await horizontalInput.press('Enter')
await canvas.waitForRender()
- await page.locator('[data-test-id="layout-vertical-padding-input"]').click()
+ await page.getByTestId('layout-vertical-padding-input').click()
await canvas.waitForRender()
const verticalInput = page.locator(
'[data-test-id="layout-vertical-padding-input"] [data-test-id="scrub-input-field"]'
@@ -145,7 +145,7 @@ test('padding controls set horizontal and vertical padding pairs', async () => {
test('size dropdown adds and removes min width', async () => {
await selectFrame()
- await page.locator('[data-test-id="layout-width-sizing-menu"]').click()
+ await page.getByTestId('layout-width-sizing-menu').click()
await page.getByText('Add min width').click()
await canvas.waitForRender()
@@ -153,15 +153,15 @@ test('size dropdown adds and removes min width', async () => {
expect(expectDefined(frame, 'frame').minWidth).toBe(
Math.round(expectDefined(frame, 'frame').width)
)
- await expect(page.locator('[data-test-id="layout-min-width-input"]')).toBeVisible()
+ await expect(page.getByTestId('layout-min-width-input')).toBeVisible()
- await page.locator('[data-test-id="layout-width-sizing-menu"]').click()
+ await page.getByTestId('layout-width-sizing-menu').click()
await page.getByText('Remove min width').click()
await canvas.waitForRender()
frame = await getNodeById(page, frameId)
expect(expectDefined(frame, 'frame').minWidth).toBeNull()
- await expect(page.locator('[data-test-id="layout-min-width-input"]')).toHaveCount(0)
+ await expect(page.getByTestId('layout-min-width-input')).toHaveCount(0)
canvas.assertNoErrors()
})
@@ -181,7 +181,7 @@ test('alignment grid center sets CENTER alignment', async () => {
test('remove auto-layout sets layoutMode to NONE', async () => {
await selectFrame()
- await page.locator('[data-test-id="layout-remove-auto"]').click()
+ await page.getByTestId('layout-remove-auto').click()
await canvas.waitForRender()
const frame = await getNodeById(page, frameId)
diff --git a/tests/e2e/editor/auto-layout/padding-editor.spec.ts b/tests/e2e/editor/auto-layout/padding-editor.spec.ts
index 75f2ddd02..4bb45648d 100644
--- a/tests/e2e/editor/auto-layout/padding-editor.spec.ts
+++ b/tests/e2e/editor/auto-layout/padding-editor.spec.ts
@@ -3,14 +3,14 @@ import { expect, test, type Page } from '@playwright/test'
import { CanvasHelper } from '#tests/helpers/canvas'
async function clickCanvas(page: Page, x: number, y: number) {
- const canvas = page.locator('[data-test-id="canvas-element"]')
+ const canvas = page.getByTestId('canvas-element')
const box = await canvas.boundingBox()
if (!box) throw new Error('Canvas has no bounding box')
await page.mouse.click(box.x + x, box.y + y)
}
async function dblclickCanvas(page: Page, x: number, y: number) {
- const canvas = page.locator('[data-test-id="canvas-element"]')
+ const canvas = page.getByTestId('canvas-element')
const box = await canvas.boundingBox()
if (!box) throw new Error('Canvas has no bounding box')
await canvas.dispatchEvent('dblclick', {
@@ -77,10 +77,10 @@ test('double-clicking an auto-layout padding handle opens a scrub editor', async
await canvas.hover(300, 130)
await dblclickCanvas(page, 300, 130)
- const editor = page.locator('[data-test-id="auto-layout-padding-editor"]')
+ const editor = page.getByTestId('auto-layout-padding-editor')
await expect(editor).toBeVisible()
- await canvas.dragScrubInput(editor.locator('[data-test-id="auto-layout-padding-input"]'), 40)
+ await canvas.dragScrubInput(editor.getByTestId('auto-layout-padding-input'), 40)
await expect(editor).toHaveCount(0)
const changedPadding = await framePaddingTop(page, frameId)
@@ -103,7 +103,7 @@ test('clicking the canvas closes the auto-layout padding editor', async ({ page
await canvas.hover(300, 130)
await dblclickCanvas(page, 300, 130)
- const editor = page.locator('[data-test-id="auto-layout-padding-editor"]')
+ const editor = page.getByTestId('auto-layout-padding-editor')
await expect(editor).toBeVisible()
await clickCanvas(page, 80, 80)
@@ -122,7 +122,7 @@ test('auto-layout padding editor follows canvas pan while open', async ({ page }
await canvas.hover(300, 130)
await dblclickCanvas(page, 300, 130)
- const editor = page.locator('[data-test-id="auto-layout-padding-editor"]')
+ const editor = page.getByTestId('auto-layout-padding-editor')
await expect(editor).toBeVisible()
const before = await editor.boundingBox()
if (!before) throw new Error('Padding editor has no bounding box')
diff --git a/tests/e2e/editor/duplicate-undo.spec.ts b/tests/e2e/editor/duplicate-undo.spec.ts
index f5afce68f..690cb7c66 100644
--- a/tests/e2e/editor/duplicate-undo.spec.ts
+++ b/tests/e2e/editor/duplicate-undo.spec.ts
@@ -31,7 +31,7 @@ async function rectangleCount() {
}
async function layerItems() {
- return page.locator('[data-test-id="layers-item"]').allTextContents()
+ return page.getByTestId('layers-item').allTextContents()
}
async function historyState() {
diff --git a/tests/e2e/export/basic.spec.ts b/tests/e2e/export/basic.spec.ts
index a5e89b884..4becea99f 100644
--- a/tests/e2e/export/basic.spec.ts
+++ b/tests/e2e/export/basic.spec.ts
@@ -21,13 +21,13 @@ test.afterAll(async () => {
})
function exportItems() {
- return page.locator('[data-test-id="export-item"]')
+ return page.getByTestId('export-item')
}
test('add export row increases row count', async () => {
const before = await exportItems().count()
- await page.locator('[data-test-id="export-section-add"]').click()
+ await page.getByTestId('export-section-add').click()
await canvas.waitForRender()
const after = await exportItems().count()
@@ -36,7 +36,7 @@ test('add export row increases row count', async () => {
})
test('remove export row decreases row count', async () => {
- await page.locator('[data-test-id="export-section-add"]').click()
+ await page.getByTestId('export-section-add').click()
await canvas.waitForRender()
const before = await exportItems().count()
@@ -49,7 +49,7 @@ test('remove export row decreases row count', async () => {
})
test('format selector changes to JPG', async () => {
- const formatTrigger = exportItems().first().locator('[data-test-id="app-select-trigger"]').last()
+ const formatTrigger = exportItems().first().getByTestId('app-select-trigger').last()
await formatTrigger.click()
await page.locator('[role="option"]').filter({ hasText: 'JPG' }).click()
@@ -60,24 +60,24 @@ test('format selector changes to JPG', async () => {
})
test('SVG format hides scale selector', async () => {
- const formatTrigger = exportItems().first().locator('[data-test-id="app-select-trigger"]').last()
+ const formatTrigger = exportItems().first().getByTestId('app-select-trigger').last()
await formatTrigger.click()
await page.locator('[role="option"]').filter({ hasText: 'SVG' }).click()
await canvas.waitForRender()
- const selects = exportItems().first().locator('[data-test-id="app-select-trigger"]')
+ const selects = exportItems().first().getByTestId('app-select-trigger')
await expect(selects).toHaveCount(1)
canvas.assertNoErrors()
})
test('preview toggle shows image with blob src', async () => {
- const formatTrigger = exportItems().first().locator('[data-test-id="app-select-trigger"]').last()
+ const formatTrigger = exportItems().first().getByTestId('app-select-trigger').last()
await formatTrigger.click()
await page.locator('[role="option"]').filter({ hasText: 'PNG' }).click()
await canvas.waitForRender()
- await page.locator('[data-test-id="export-preview-toggle"]').click()
+ await page.getByTestId('export-preview-toggle').click()
const img = page.locator('[data-test-id="export-section"] img')
await expect(img).toBeVisible({ timeout: 10000 })
diff --git a/tests/e2e/fonts/settings.spec.ts b/tests/e2e/fonts/settings.spec.ts
index a144d33ef..1c00447a9 100644
--- a/tests/e2e/fonts/settings.spec.ts
+++ b/tests/e2e/fonts/settings.spec.ts
@@ -15,12 +15,12 @@ test('font settings popover is available from typography panel', async ({ page }
store.select([id])
})
- await expect(page.locator('[data-test-id="typography-section"]')).toBeVisible()
- await page.locator('[data-test-id="font-settings-trigger"]').click()
+ await expect(page.getByTestId('typography-section')).toBeVisible()
+ await page.getByTestId('font-settings-trigger').click()
await expect(page.getByText('Access system fonts')).toBeVisible()
- await expect(page.locator('[data-test-id="font-settings-request-access"]')).toBeVisible()
- await expect(page.locator('[data-test-id="font-settings-download-fallbacks"]')).toBeVisible()
- await expect(page.locator('[data-test-id="font-settings-refresh-cache"]')).toBeVisible()
- await expect(page.locator('[data-test-id="font-settings-clear-cache"]')).toBeVisible()
+ await expect(page.getByTestId('font-settings-request-access')).toBeVisible()
+ await expect(page.getByTestId('font-settings-download-fallbacks')).toBeVisible()
+ await expect(page.getByTestId('font-settings-refresh-cache')).toBeVisible()
+ await expect(page.getByTestId('font-settings-clear-cache')).toBeVisible()
})
diff --git a/tests/e2e/layers/panel.spec.ts b/tests/e2e/layers/panel.spec.ts
index b17a308f8..a51d4433f 100644
--- a/tests/e2e/layers/panel.spec.ts
+++ b/tests/e2e/layers/panel.spec.ts
@@ -173,7 +173,7 @@ test('double-click layer to rename', async () => {
const row = layerRows().filter({ hasText: 'Rectangle' }).first()
await row.dblclick()
- const input = page.locator('[data-test-id="layers-item-input"]')
+ const input = page.getByTestId('layers-item-input')
await expect(input).toBeVisible()
await input.fill('Renamed Layer')
await input.press('Enter')
@@ -189,7 +189,7 @@ test('clicking outside rename input commits', async () => {
const row = layerRows().filter({ hasText: 'Renamed Layer' }).first()
await row.dblclick()
- const input = page.locator('[data-test-id="layers-item-input"]')
+ const input = page.getByTestId('layers-item-input')
await expect(input).toBeVisible()
await input.fill('After Outside Click')
@@ -212,7 +212,7 @@ test('clearing a layer name falls back to the default node name', async () => {
await row.dblclick()
- const input = page.locator('[data-test-id="layers-item-input"]')
+ const input = page.getByTestId('layers-item-input')
await expect(input).toBeVisible()
await input.clear()
await input.press('Enter')
@@ -235,7 +235,7 @@ test('double-click does not toggle tree expand', async () => {
await containerRow.dblclick()
await canvas.waitForRender()
- const input = page.locator('[data-test-id="layers-item-input"]')
+ const input = page.getByTestId('layers-item-input')
await expect(input).toBeVisible()
await input.press('Escape')
diff --git a/tests/e2e/layers/scroll.spec.ts b/tests/e2e/layers/scroll.spec.ts
index 38406660d..8192750fc 100644
--- a/tests/e2e/layers/scroll.spec.ts
+++ b/tests/e2e/layers/scroll.spec.ts
@@ -26,8 +26,8 @@ test('pages and layers panels scroll inside splitter panes', async ({ page }) =>
})
await canvas.waitForRender()
- const pagesScroller = page.locator('[data-test-id="pages-scroll"]')
- const layersScroller = page.locator('[data-test-id="layers-scroll"]')
+ const pagesScroller = page.getByTestId('pages-scroll')
+ const layersScroller = page.getByTestId('layers-scroll')
await pagesScroller.evaluate((el) => {
el.scrollTop = el.scrollHeight
diff --git a/tests/e2e/pages/multi-page.spec.ts b/tests/e2e/pages/multi-page.spec.ts
index 70f872bd5..ca0b932ec 100644
--- a/tests/e2e/pages/multi-page.spec.ts
+++ b/tests/e2e/pages/multi-page.spec.ts
@@ -43,15 +43,15 @@ function getPageChildCount() {
}
function pagesPanel() {
- return page.locator('[data-test-id="pages-panel"]')
+ return page.getByTestId('pages-panel')
}
function pageItems() {
- return page.locator('[data-test-id="pages-item"]')
+ return page.getByTestId('pages-item')
}
function addPageButton() {
- return page.locator('[data-test-id="pages-add"]')
+ return page.getByTestId('pages-add')
}
test('initial state has one page', async () => {
@@ -164,7 +164,7 @@ test('double-click page to rename', async () => {
const item = pageItems().first()
await item.dblclick()
- const input = page.locator('[data-test-id="pages-item-input"]')
+ const input = page.getByTestId('pages-item-input')
await expect(input).toBeVisible()
await input.fill('My Page')
await input.press('Enter')
@@ -180,12 +180,12 @@ test('clicking outside page rename input commits', async () => {
const item = pageItems().first()
await item.dblclick()
- const input = page.locator('[data-test-id="pages-item-input"]')
+ const input = page.getByTestId('pages-item-input')
await expect(input).toBeVisible()
await input.fill('Outside Click Page')
// Click on the page header label to trigger blur (outside the input but still in the panel)
- await page.locator('[data-test-id="pages-header"]').click()
+ await page.getByTestId('pages-header').click()
await canvas.waitForRender()
await expect(input).not.toBeVisible()
diff --git a/tests/e2e/panels/basic.spec.ts b/tests/e2e/panels/basic.spec.ts
index f6deb7443..2b1b5cc9b 100644
--- a/tests/e2e/panels/basic.spec.ts
+++ b/tests/e2e/panels/basic.spec.ts
@@ -20,11 +20,11 @@ test.afterAll(async () => {
})
test('layers panel resize increases width', async () => {
- const panel = page.locator('[data-test-id="layers-panel"]')
+ const panel = page.getByTestId('layers-panel')
const before = await panel.boundingBox()
expect(before).not.toBeNull()
- const handle = page.locator('[data-test-id="left-splitter-handle"]')
+ const handle = page.getByTestId('left-splitter-handle')
const handleBox = await handle.boundingBox()
expect(handleBox).not.toBeNull()
@@ -48,7 +48,7 @@ test('panel width persists after page reload', async () => {
// Allow Reka's auto-save debounce to flush before recording the width
await page.waitForTimeout(300)
const recordedWidth = expectDefined(
- await page.locator('[data-test-id="layers-panel"]').boundingBox(),
+ await page.getByTestId('layers-panel').boundingBox(),
'persisted layers panel bounds'
).width
@@ -57,7 +57,7 @@ test('panel width persists after page reload', async () => {
await canvas.waitForInit()
const after = expectDefined(
- await page.locator('[data-test-id="layers-panel"]').boundingBox(),
+ await page.getByTestId('layers-panel').boundingBox(),
'reloaded layers panel bounds'
)
expect(Math.abs(after.width - recordedWidth)).toBeLessThanOrEqual(2)
@@ -68,7 +68,7 @@ test('Cmd+Backslash hides panels', async () => {
await page.keyboard.press('Meta+\\')
await canvas.waitForRender()
- await expect(page.locator('[data-test-id="layers-panel"]')).not.toBeVisible()
+ await expect(page.getByTestId('layers-panel')).not.toBeVisible()
canvas.assertNoErrors()
})
@@ -76,6 +76,6 @@ test('Cmd+Backslash shows panels again', async () => {
await page.keyboard.press('Meta+\\')
await canvas.waitForRender()
- await expect(page.locator('[data-test-id="layers-panel"]')).toBeVisible()
+ await expect(page.getByTestId('layers-panel')).toBeVisible()
canvas.assertNoErrors()
})
diff --git a/tests/e2e/properties/corner-stroke-toggles.spec.ts b/tests/e2e/properties/corner-stroke-toggles.spec.ts
index ad9f6186a..a6ac6ce2d 100644
--- a/tests/e2e/properties/corner-stroke-toggles.spec.ts
+++ b/tests/e2e/properties/corner-stroke-toggles.spec.ts
@@ -48,16 +48,16 @@ test('independent corners toggle shows per-corner inputs', async () => {
expect(flags?.type).toBe('FRAME')
expect(flags?.independentCorners).toBe(false)
- const toggle = page.locator('[data-test-id="independent-corners-toggle"]')
+ const toggle = page.getByTestId('independent-corners-toggle')
await expect(toggle).toBeVisible()
await toggle.click()
await canvas.waitForRender()
expect((await getSelectedNodeFlags())?.independentCorners).toBe(true)
- const grid = page.locator('[data-test-id="independent-corners-grid"]')
+ const grid = page.getByTestId('independent-corners-grid')
await expect(grid).toBeVisible()
- const cornerInputs = grid.locator('[data-test-id="scrub-input"]')
+ const cornerInputs = grid.getByTestId('scrub-input')
expect(await cornerInputs.count()).toBe(4)
await toggle.click()
@@ -69,12 +69,12 @@ test('stroke sides toggle shows per-side weight inputs', async () => {
await drawFrame(300, 50, 120, 80)
await canvas.waitForRender()
- const addStroke = page.locator('[data-test-id="stroke-section-add"]')
+ const addStroke = page.getByTestId('stroke-section-add')
await expect(addStroke).toBeVisible()
await addStroke.click()
await canvas.waitForRender()
- const toggle = page.locator('[data-test-id="stroke-sides-toggle"]')
+ const toggle = page.getByTestId('stroke-sides-toggle')
await expect(toggle).toBeVisible({ timeout: 5000 })
const sectionInputsBefore = await page
diff --git a/tests/e2e/properties/panel.spec.ts b/tests/e2e/properties/panel.spec.ts
index a357565d9..316e0d3a8 100644
--- a/tests/e2e/properties/panel.spec.ts
+++ b/tests/e2e/properties/panel.spec.ts
@@ -40,7 +40,7 @@ test('corner radius uniform sets cornerRadius', async () => {
await canvas.clearCanvas()
await canvas.drawRect(200, 200, 80, 80)
- const scrubContainer = page.locator('[data-test-id="corner-radius-input"]')
+ const scrubContainer = page.getByTestId('corner-radius-input')
await scrubContainer.click()
await canvas.waitForRender()
const input = page.locator(
@@ -56,13 +56,13 @@ test('corner radius uniform sets cornerRadius', async () => {
})
test('independent corners toggle shows four corner inputs', async () => {
- await page.locator('[data-test-id="independent-corners-toggle"]').click()
+ await page.getByTestId('independent-corners-toggle').click()
await canvas.waitForRender()
- await expect(page.locator('[data-test-id="corner-tl-input"]')).toBeVisible()
- await expect(page.locator('[data-test-id="corner-tr-input"]')).toBeVisible()
- await expect(page.locator('[data-test-id="corner-br-input"]')).toBeVisible()
- await expect(page.locator('[data-test-id="corner-bl-input"]')).toBeVisible()
+ await expect(page.getByTestId('corner-tl-input')).toBeVisible()
+ await expect(page.getByTestId('corner-tr-input')).toBeVisible()
+ await expect(page.getByTestId('corner-br-input')).toBeVisible()
+ await expect(page.getByTestId('corner-bl-input')).toBeVisible()
canvas.assertNoErrors()
})
@@ -74,16 +74,16 @@ test('fill gradient switch changes fill type', async () => {
await canvas.drawRect(300, 300, 80, 80)
await canvas.waitForRender()
- await expect(page.locator('[data-test-id="fill-section"]')).toBeVisible({ timeout: 5000 })
+ await expect(page.getByTestId('fill-section')).toBeVisible({ timeout: 5000 })
- const fillItem = page.locator('[data-test-id="fill-item"]').first()
+ const fillItem = page.getByTestId('fill-item').first()
await expect(fillItem).toBeVisible({ timeout: 5000 })
- const fillSwatch = fillItem.locator('[data-test-id="fill-picker-swatch"]')
+ const fillSwatch = fillItem.getByTestId('fill-picker-swatch')
await expect(fillSwatch).toBeVisible({ timeout: 5000 })
await fillSwatch.click()
await canvas.waitForRender()
- await page.locator('[data-test-id="fill-picker-tab-gradient"]').click()
+ await page.getByTestId('fill-picker-tab-gradient').click()
await canvas.waitForRender()
const node = expectDefined(await getSelectedNode(page), 'gradient-filled node')
@@ -107,7 +107,7 @@ test('variable bind badge appears on fill', async () => {
})
await canvas.waitForRender()
- await expect(page.locator('[data-test-id="fill-unbind-variable"]')).toBeVisible()
+ await expect(page.getByTestId('fill-unbind-variable')).toBeVisible()
canvas.assertNoErrors()
})
@@ -130,12 +130,12 @@ test('fill color can bind an existing variable', async () => {
})
await canvas.waitForRender()
- await page.locator('[data-test-id="fill-apply-variable-0"]').click()
+ await page.getByTestId('fill-apply-variable-0').click()
await page.getByText('test-brand-red', { exact: true }).click()
await canvas.waitForRender()
- await expect(page.locator('[data-test-id="fill-unbind-variable"]')).toBeVisible()
- const fillSwatch = page.locator('[data-test-id="fill-picker-swatch"]')
+ await expect(page.getByTestId('fill-unbind-variable')).toBeVisible()
+ const fillSwatch = page.getByTestId('fill-picker-swatch')
await expect(fillSwatch).toHaveCSS('background-color', 'rgb(255, 0, 0)')
await fillSwatch.click()
const colorInputs = page.locator('[role="dialog"] input[type="number"]:not(.hidden)')
@@ -143,7 +143,7 @@ test('fill color can bind an existing variable', async () => {
await colorInputs.first().fill('0')
await colorInputs.first().press('Enter')
await canvas.waitForRender()
- await expect(page.locator('[data-test-id="fill-unbind-variable"]')).toBeHidden()
+ await expect(page.getByTestId('fill-unbind-variable')).toBeHidden()
const boundVariableId = await page.evaluate(() => {
const store = window.openPencil?.getStore?.()
if (!store) throw new Error('OpenPencil store not initialized')
@@ -158,14 +158,14 @@ test('fill color can create and bind a variable', async () => {
await canvas.clearCanvas()
await canvas.drawRect(200, 200, 80, 80)
- await page.locator('[data-test-id="fill-apply-variable-0"]').click()
+ await page.getByTestId('fill-apply-variable-0').click()
await expect(page.getByText(/Create color variable from #?[0-9A-F]{6}/)).toBeVisible()
- await page.locator('[data-test-id="fill-apply-variable-0-create"]').click()
+ await page.getByTestId('fill-apply-variable-0-create').click()
await page.getByPlaceholder('Variable name').fill('Surface/default')
- await page.locator('[data-test-id="fill-apply-variable-0-create"]').click()
+ await page.getByTestId('fill-apply-variable-0-create').click()
await canvas.waitForRender()
- await expect(page.locator('[data-test-id="fill-unbind-variable"]')).toBeVisible()
+ await expect(page.getByTestId('fill-unbind-variable')).toBeVisible()
const boundVariable = await page.evaluate(() => {
const store = window.openPencil?.getStore?.()
if (!store) throw new Error('OpenPencil store not initialized')
@@ -182,16 +182,16 @@ test('fill color can create and bind a variable', async () => {
test('width can create, bind, and detach a number variable', async () => {
await canvas.clearCanvas()
await canvas.drawRect(200, 200, 80, 80)
- await page.locator('[data-test-id="layout-height-input"]').click()
+ await page.getByTestId('layout-height-input').click()
- await page.locator('[data-test-id="layout-width-apply-variable"]').click()
+ await page.getByTestId('layout-width-apply-variable').click()
await expect(page.getByText('Create number variable from 80')).toBeVisible()
- await page.locator('[data-test-id="layout-width-apply-variable-create"]').click()
+ await page.getByTestId('layout-width-apply-variable-create').click()
await page.getByPlaceholder('Variable name').fill('Card/width')
- await page.locator('[data-test-id="layout-width-apply-variable-create"]').click()
+ await page.getByTestId('layout-width-apply-variable-create').click()
await canvas.waitForRender()
- await expect(page.locator('[data-test-id="layout-width-unbind-variable"]')).toBeVisible()
+ await expect(page.getByTestId('layout-width-unbind-variable')).toBeVisible()
const boundVariable = await page.evaluate(() => {
const store = window.openPencil?.getStore?.()
if (!store) throw new Error('OpenPencil store not initialized')
@@ -203,14 +203,14 @@ test('width can create, bind, and detach a number variable', async () => {
})
expect(boundVariable).toBe('Card/width')
- const widthField = page.locator('[data-test-id="layout-width-input"]')
+ const widthField = page.getByTestId('layout-width-input')
await widthField.click()
- const widthInput = widthField.locator('[data-test-id="scrub-input-field"]')
+ const widthInput = widthField.getByTestId('scrub-input-field')
await widthInput.fill('120')
await widthInput.press('Enter')
await canvas.waitForRender()
- await expect(page.locator('[data-test-id="layout-width-unbind-variable"]')).toBeHidden()
+ await expect(page.getByTestId('layout-width-unbind-variable')).toBeHidden()
const directWidth = await page.evaluate(() => {
const store = window.openPencil?.getStore?.()
if (!store) throw new Error('OpenPencil store not initialized')
@@ -229,7 +229,7 @@ test('alignment buttons align nodes to same X', async () => {
await canvas.pressKey('Meta+a')
await canvas.waitForRender()
- await page.locator('[data-test-id="position-align-left"]').click()
+ await page.getByTestId('position-align-left').click()
await canvas.waitForRender()
const children = await getPageChildren(page)
@@ -242,7 +242,7 @@ test('flip horizontal sets flipX', async () => {
await canvas.clearCanvas()
await canvas.drawRect(200, 200, 80, 80)
- await page.locator('[data-test-id="position-flip-horizontal"]').click()
+ await page.getByTestId('position-flip-horizontal').click()
await canvas.waitForRender()
const node = await getSelectedNode(page)
@@ -263,7 +263,7 @@ test('clip content checkbox toggles clipsContent', async () => {
const before = expectDefined(await getSelectedNode(page), 'selected frame before clipping')
const initialValue = before.clipsContent
- await page.locator('[data-test-id="clip-content-checkbox"]').click()
+ await page.getByTestId('clip-content-checkbox').click()
await canvas.waitForRender()
const after = await getSelectedNode(page)
diff --git a/tests/e2e/properties/visibility.spec.ts b/tests/e2e/properties/visibility.spec.ts
index d5458f754..72f5d5966 100644
--- a/tests/e2e/properties/visibility.spec.ts
+++ b/tests/e2e/properties/visibility.spec.ts
@@ -39,7 +39,7 @@ test('fill visibility supports repeat click and undo redo', async () => {
await canvas.drawRect(120, 120, 120, 80)
await canvas.waitForRender()
- const fillButton = page.locator('[data-test-id="fill-visibility-0"]')
+ const fillButton = page.getByTestId('fill-visibility-0')
await expect(fillButton).toBeVisible()
expect(expectDefined(await getSelectedNode(), 'selected node').fills[0]?.visible).toBe(true)
@@ -59,10 +59,10 @@ test('fill visibility supports repeat click and undo redo', async () => {
})
test('stroke visibility supports repeat click and undo redo', async () => {
- await page.locator('[data-test-id="stroke-section-add"]').click()
+ await page.getByTestId('stroke-section-add').click()
await canvas.waitForRender()
- const strokeButton = page.locator('[data-test-id="stroke-visibility-0"]')
+ const strokeButton = page.getByTestId('stroke-visibility-0')
await expect(strokeButton).toBeVisible()
expect(expectDefined(await getSelectedNode(), 'selected node').strokes[0]?.visible).toBe(true)
@@ -82,7 +82,7 @@ test('stroke visibility supports repeat click and undo redo', async () => {
})
test('appearance visibility supports repeat click and undo redo in one step', async () => {
- const visibilityButton = page.locator('[data-test-id="appearance-visibility"]')
+ const visibilityButton = page.getByTestId('appearance-visibility')
await expect(visibilityButton).toBeVisible()
expect(expectDefined(await getSelectedNode(), 'selected node').visible).toBe(true)
diff --git a/tests/e2e/snap/guides.spec.ts b/tests/e2e/snap/guides.spec.ts
index ea32c211c..ef8ff8f22 100644
--- a/tests/e2e/snap/guides.spec.ts
+++ b/tests/e2e/snap/guides.spec.ts
@@ -40,7 +40,7 @@ test('edge snap guide: canvas differs at snap vs non-snap position', async () =>
await createRects()
- const box = await page.locator('[data-test-id="canvas-element"]').boundingBox()
+ const box = await page.getByTestId('canvas-element').boundingBox()
if (!box) throw new Error('No canvas')
// drag to a non-snap position first, capture screenshot
@@ -68,7 +68,7 @@ test('center snap guide: canvas differs at snap vs non-snap position', async ()
await createRects()
- const box = await page.locator('[data-test-id="canvas-element"]').boundingBox()
+ const box = await page.getByTestId('canvas-element').boundingBox()
if (!box) throw new Error('No canvas')
// drag to a non-snap position first
diff --git a/tests/e2e/stroke-picker/basic.spec.ts b/tests/e2e/stroke-picker/basic.spec.ts
index e598eb962..6f48321a4 100644
--- a/tests/e2e/stroke-picker/basic.spec.ts
+++ b/tests/e2e/stroke-picker/basic.spec.ts
@@ -22,11 +22,11 @@ async function openStrokePicker(page: Page) {
.waitFor({ state: 'detached' })
.catch(() => undefined)
await page.locator('[data-test-id="stroke-item"] button').first().click()
- await expect(page.locator('[data-test-id="color-picker-popover"]')).toBeVisible()
+ await expect(page.getByTestId('color-picker-popover')).toBeVisible()
}
async function chooseFormat(page: Page, label: 'RGB' | 'HSL' | 'HSB' | 'OkHCL') {
- await page.locator('[data-test-id="color-format-select"]').click()
+ await page.getByTestId('color-format-select').click()
await page.getByRole('option', { name: label, exact: true }).click()
}
@@ -46,7 +46,7 @@ test('stroke picker updates stroke color on a rectangle', async ({ page }) => {
await canvas.waitForInit()
await canvas.drawRect(120, 120, 180, 120)
- await page.locator('[data-test-id="stroke-section-add"]').click()
+ await page.getByTestId('stroke-section-add').click()
await canvas.waitForRender()
const before = await getSelectedStroke(page)
@@ -68,7 +68,7 @@ test('stroke picker alpha slider updates stroke opacity and alpha', async ({ pag
await canvas.waitForInit()
await canvas.drawRect(120, 120, 180, 120)
- await page.locator('[data-test-id="stroke-section-add"]').click()
+ await page.getByTestId('stroke-section-add').click()
await canvas.waitForRender()
await openStrokePicker(page)
@@ -107,7 +107,7 @@ test('stroke picker hsb saturation and brightness sliders update stroke color on
})
await canvas.waitForRender()
- await expect(page.locator('[data-test-id="stroke-item"]')).toBeVisible()
+ await expect(page.getByTestId('stroke-item')).toBeVisible()
await openStrokePicker(page)
await chooseFormat(page, 'HSB')
diff --git a/tests/e2e/text/editing.spec.ts b/tests/e2e/text/editing.spec.ts
index cea57408e..bb16cf9f5 100644
--- a/tests/e2e/text/editing.spec.ts
+++ b/tests/e2e/text/editing.spec.ts
@@ -90,7 +90,7 @@ test('typography section appears for text node', async () => {
await canvas.click(200, 200)
await canvas.waitForRender()
- const typoSection = page.locator('[data-test-id="typography-section"]')
+ const typoSection = page.getByTestId('typography-section')
await expect(typoSection).toBeVisible()
})
diff --git a/tests/e2e/text/formatting.spec.ts b/tests/e2e/text/formatting.spec.ts
index 0c3c3fe0a..75584f4e6 100644
--- a/tests/e2e/text/formatting.spec.ts
+++ b/tests/e2e/text/formatting.spec.ts
@@ -62,7 +62,7 @@ test('bold button toggles fontWeight to 700 then back to 400', async () => {
}, nodeId)
await canvas.waitForRender()
- const boldBtn = page.locator('[data-test-id="typography-bold-button"]')
+ const boldBtn = page.getByTestId('typography-bold-button')
await expect(boldBtn).toBeVisible({ timeout: 3000 })
await page.waitForTimeout(200)
await boldBtn.click()
@@ -72,7 +72,7 @@ test('bold button toggles fontWeight to 700 then back to 400', async () => {
const bold = await getNodeById(page, nodeId)
expect(bold?.fontWeight).toBe(700)
- await page.locator('[data-test-id="typography-bold-button"]').click()
+ await page.getByTestId('typography-bold-button').click()
await page.waitForTimeout(500)
await canvas.waitForRender()
diff --git a/tests/e2e/toolbar/basic.spec.ts b/tests/e2e/toolbar/basic.spec.ts
index 5b968b91a..38b7e7fab 100644
--- a/tests/e2e/toolbar/basic.spec.ts
+++ b/tests/e2e/toolbar/basic.spec.ts
@@ -20,13 +20,13 @@ test.afterAll(async () => {
})
test('shapes flyout opens', async () => {
- await page.locator('[data-test-id="toolbar-flyout-rectangle"]').click()
- await expect(page.locator('[data-test-id="toolbar-flyout-item-polygon"]')).toBeVisible()
+ await page.getByTestId('toolbar-flyout-rectangle').click()
+ await expect(page.getByTestId('toolbar-flyout-item-polygon')).toBeVisible()
canvas.assertNoErrors()
})
test('Polygon tool creates POLYGON node', async () => {
- await page.locator('[data-test-id="toolbar-flyout-item-polygon"]').click()
+ await page.getByTestId('toolbar-flyout-item-polygon').click()
await canvas.drag(300, 200, 400, 300)
await canvas.waitForRender()
@@ -36,8 +36,8 @@ test('Polygon tool creates POLYGON node', async () => {
})
test('Star tool creates STAR node', async () => {
- await page.locator('[data-test-id="toolbar-flyout-rectangle"]').click()
- await page.locator('[data-test-id="toolbar-flyout-item-star"]').click()
+ await page.getByTestId('toolbar-flyout-rectangle').click()
+ await page.getByTestId('toolbar-flyout-item-star').click()
await canvas.drag(150, 150, 250, 250)
await canvas.waitForRender()
@@ -105,8 +105,8 @@ test('Pen close path creates VECTOR with closed region', async () => {
})
test('Frame flyout shows Frame and Section items', async () => {
- await page.locator('[data-test-id="toolbar-flyout-frame"]').click()
- await expect(page.locator('[data-test-id="toolbar-flyout-item-frame"]')).toBeVisible()
- await expect(page.locator('[data-test-id="toolbar-flyout-item-section"]')).toBeVisible()
+ await page.getByTestId('toolbar-flyout-frame').click()
+ await expect(page.getByTestId('toolbar-flyout-item-frame')).toBeVisible()
+ await expect(page.getByTestId('toolbar-flyout-item-section')).toBeVisible()
canvas.assertNoErrors()
})
diff --git a/tests/e2e/tools/section.spec.ts b/tests/e2e/tools/section.spec.ts
index 55af977da..66a846cd3 100644
--- a/tests/e2e/tools/section.spec.ts
+++ b/tests/e2e/tools/section.spec.ts
@@ -25,7 +25,7 @@ test.beforeEach(async () => {
test('draw section in full editor without browser errors', async () => {
await canvas.drawSection(100, 100, 240, 160)
- await expect(page.locator('[data-test-id="design-node-header"]')).toContainText('SECTION')
+ await expect(page.getByTestId('design-node-header')).toContainText('SECTION')
await expect
.poll(async () => {
return page.evaluate(() => {
diff --git a/tests/e2e/variables/dialog.spec.ts b/tests/e2e/variables/dialog.spec.ts
index 003fd2b64..dab8271a1 100644
--- a/tests/e2e/variables/dialog.spec.ts
+++ b/tests/e2e/variables/dialog.spec.ts
@@ -31,14 +31,14 @@ async function createColorVariable(name: string) {
}
function variableRows() {
- return page.locator('[data-test-id="variable-row"]')
+ return page.getByTestId('variable-row')
}
test('variables dialog opens', async () => {
await createColorVariable('primary-color')
- await page.locator('[data-test-id="variables-section-open"]').click()
- await expect(page.locator('[data-test-id="variables-dialog"]')).toBeVisible()
+ await page.getByTestId('variables-section-open').click()
+ await expect(page.getByTestId('variables-dialog')).toBeVisible()
canvas.assertNoErrors()
})
@@ -52,7 +52,7 @@ test('search filters variable rows', async () => {
})
await canvas.waitForRender()
- const searchInput = page.locator('[data-test-id="variables-search-input"]')
+ const searchInput = page.getByTestId('variables-search-input')
await searchInput.fill('primary')
await expect(variableRows()).toHaveCount(1, { timeout: 3000 })
@@ -60,31 +60,31 @@ test('search filters variable rows', async () => {
})
test('add variable menu creates non-color variable types', async () => {
- await page.locator('[data-test-id="variables-search-input"]').fill('')
+ await page.getByTestId('variables-search-input').fill('')
await canvas.waitForRender()
- await page.locator('[data-test-id="variables-add-variable"]').click()
- await page.locator('[data-test-id="variables-add-float"]').click()
+ await page.getByTestId('variables-add-variable').click()
+ await page.getByTestId('variables-add-float').click()
await expect(
- page.locator('[data-test-id="variable-row"]').filter({ hasText: 'New number' })
+ page.getByTestId('variable-row').filter({ hasText: 'New number' })
).toHaveCount(1)
- await page.locator('[data-test-id="variables-add-variable"]').click()
- await page.locator('[data-test-id="variables-add-string"]').click()
+ await page.getByTestId('variables-add-variable').click()
+ await page.getByTestId('variables-add-string').click()
await expect(
- page.locator('[data-test-id="variable-row"]').filter({ hasText: 'New text' })
+ page.getByTestId('variable-row').filter({ hasText: 'New text' })
).toHaveCount(1)
- await page.locator('[data-test-id="variables-add-variable"]').click()
- await page.locator('[data-test-id="variables-add-boolean"]').click()
+ await page.getByTestId('variables-add-variable').click()
+ await page.getByTestId('variables-add-boolean').click()
await expect(
- page.locator('[data-test-id="variable-row"]').filter({ hasText: 'New boolean' })
+ page.getByTestId('variable-row').filter({ hasText: 'New boolean' })
).toHaveCount(1)
canvas.assertNoErrors()
})
test('click name cell activates editable input', async () => {
- await page.locator('[data-test-id="variables-search-input"]').fill('')
+ await page.getByTestId('variables-search-input').fill('')
await canvas.waitForRender()
const firstRow = variableRows().first()
@@ -102,15 +102,15 @@ test('color swatch opens color picker', async () => {
// close dialog if open from previous test
await page.keyboard.press('Escape')
await page.waitForTimeout(200)
- await page.locator('[data-test-id="variables-section-open"]').click()
- await expect(page.locator('[data-test-id="variables-dialog"]')).toBeVisible({ timeout: 3000 })
+ await page.getByTestId('variables-section-open').click()
+ await expect(page.getByTestId('variables-dialog')).toBeVisible({ timeout: 3000 })
const swatch = page
- .locator('[data-test-id="variable-row"]')
+ .getByTestId('variable-row')
.first()
- .locator('[data-test-id="color-picker-swatch"]')
+ .getByTestId('color-picker-swatch')
await expect(swatch).toBeVisible({ timeout: 3000 })
await swatch.click()
- await expect(page.locator('[data-test-id="color-picker-popover"]')).toBeVisible({ timeout: 5000 })
+ await expect(page.getByTestId('color-picker-popover')).toBeVisible({ timeout: 5000 })
canvas.assertNoErrors()
})
diff --git a/tests/helpers/canvas.ts b/tests/helpers/canvas.ts
index e1cdaa2ef..1f2cfdb18 100644
--- a/tests/helpers/canvas.ts
+++ b/tests/helpers/canvas.ts
@@ -7,7 +7,7 @@ export class CanvasHelper {
constructor(page: Page) {
this.page = page
- this.canvas = page.locator('[data-test-id="canvas-area"]')
+ this.canvas = page.getByTestId('canvas-area')
page.on('pageerror', (err) => this.errors.push(err.message))
page.on('console', (msg) => {
if (msg.type() === 'error') this.errors.push(msg.text())
@@ -27,12 +27,8 @@ export class CanvasHelper {
}
async waitForInit() {
- await this.page
- .locator('[data-test-id="canvas-element"][data-ready="1"]')
- .waitFor({ timeout: 30000 })
- await this.page
- .locator('[data-test-id="canvas-loading"]')
- .waitFor({ state: 'hidden', timeout: 30000 })
+ await this.page.getByTestId('canvas-element').and(this.page.locator('[data-ready="1"]')).waitFor({ timeout: 30000 })
+ await this.page.getByTestId('canvas-loading').waitFor({ state: 'hidden', timeout: 30000 })
await this.page.locator('#loader').waitFor({ state: 'detached', timeout: 30000 })
}