From 68601c255ae1ed41744414522b6caf7a75805487 Mon Sep 17 00:00:00 2001 From: openhands Date: Mon, 2 Mar 2026 23:13:05 +0000 Subject: [PATCH] fix: getByRole('button', { name: 'Buy' }).last() fragility is duplicated across e2e/01 and this scenario (#398) Co-Authored-By: Claude Sonnet 4.6 --- scripts/harb-evaluator/helpers/swap.ts | 6 +++--- tests/e2e/01-acquire-and-stake.spec.ts | 6 +++--- tests/e2e/02-max-stake-all-tax-rates.spec.ts | 6 +++--- web-app/src/components/LocalSwapWidget.vue | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/scripts/harb-evaluator/helpers/swap.ts b/scripts/harb-evaluator/helpers/swap.ts index 7670daa..83b93e1 100644 --- a/scripts/harb-evaluator/helpers/swap.ts +++ b/scripts/harb-evaluator/helpers/swap.ts @@ -80,13 +80,13 @@ export async function buyKrk(page: Page, ethAmount: string): Promise { await navigateSPA(page, '/app/get-krk'); await expect(page.getByRole('heading', { name: 'Get $KRK Tokens' })).toBeVisible({ timeout: 10_000 }); - const swapInput = page.getByLabel('ETH to spend'); + const swapInput = page.getByTestId('swap-amount-input'); await expect(swapInput).toBeVisible({ timeout: 15_000 }); await swapInput.fill(ethAmount); await page.waitForTimeout(500); - const buyButton = page.getByRole('button', { name: 'Buy KRK' }); + const buyButton = page.getByTestId('swap-buy-button'); await expect(buyButton).toBeVisible({ timeout: 5_000 }); await page.screenshot({ path: 'test-results/holdout-before-buy.png' }); @@ -97,7 +97,7 @@ export async function buyKrk(page: Page, ethAmount: string): Promise { try { await page.getByRole('button', { name: /Submitting/i }).waitFor({ state: 'visible', timeout: 5_000 }); console.log('[swap] Swap in progress...'); - await page.getByRole('button', { name: 'Buy KRK' }).waitFor({ state: 'visible', timeout: 60_000 }); + await page.getByTestId('swap-buy-button').waitFor({ state: 'visible', timeout: 60_000 }); console.log('[swap] Swap completed'); } catch { // Swap completed before the Submitting state could be observed diff --git a/tests/e2e/01-acquire-and-stake.spec.ts b/tests/e2e/01-acquire-and-stake.spec.ts index e8d8239..7e5d10c 100644 --- a/tests/e2e/01-acquire-and-stake.spec.ts +++ b/tests/e2e/01-acquire-and-stake.spec.ts @@ -170,11 +170,11 @@ test.describe('Acquire & Stake', () => { await page.screenshot({ path: 'test-results/before-swap.png' }); - const ethToSpendInput = page.getByLabel('ETH to spend'); + const ethToSpendInput = page.getByTestId('swap-amount-input'); await expect(ethToSpendInput).toBeVisible({ timeout: 15_000 }); await ethToSpendInput.fill('0.05'); - const buyButton = page.getByRole('button', { name: 'Buy KRK' }); + const buyButton = page.getByTestId('swap-buy-button'); await expect(buyButton).toBeVisible(); console.log('[TEST] Clicking Buy KRK button...'); await buyButton.click(); @@ -184,7 +184,7 @@ test.describe('Acquire & Stake', () => { try { await page.getByRole('button', { name: /Submitting/i }).waitFor({ state: 'visible', timeout: 5_000 }); console.log('[TEST] Swap initiated, waiting for completion...'); - await page.getByRole('button', { name: 'Buy KRK' }).waitFor({ state: 'visible', timeout: 60_000 }); + await page.getByTestId('swap-buy-button').waitFor({ state: 'visible', timeout: 60_000 }); console.log('[TEST] Swap completed!'); } catch (e) { console.log('[TEST] No "Submitting" state detected, swap may have completed instantly'); diff --git a/tests/e2e/02-max-stake-all-tax-rates.spec.ts b/tests/e2e/02-max-stake-all-tax-rates.spec.ts index 427de6f..6c58d3c 100644 --- a/tests/e2e/02-max-stake-all-tax-rates.spec.ts +++ b/tests/e2e/02-max-stake-all-tax-rates.spec.ts @@ -181,11 +181,11 @@ test.describe('Max Stake All Tax Rates', () => { await expect(page.getByRole('heading', { name: 'Get $KRK Tokens' })).toBeVisible({ timeout: 10_000 }); console.log('[TEST] Buying KRK tokens (swapping 5 ETH)...'); - const ethToSpendInput = page.getByLabel('ETH to spend'); + const ethToSpendInput = page.getByTestId('swap-amount-input'); await expect(ethToSpendInput).toBeVisible({ timeout: 15_000 }); await ethToSpendInput.fill('5'); - const buyButton = page.getByRole('button', { name: 'Buy KRK' }); + const buyButton = page.getByTestId('swap-buy-button'); await expect(buyButton).toBeVisible(); await buyButton.click(); @@ -193,7 +193,7 @@ test.describe('Max Stake All Tax Rates', () => { console.log('[TEST] Waiting for swap to process...'); try { await page.getByRole('button', { name: /Submitting/i }).waitFor({ state: 'visible', timeout: 5_000 }); - await page.getByRole('button', { name: 'Buy KRK' }).waitFor({ state: 'visible', timeout: 60_000 }); + await page.getByTestId('swap-buy-button').waitFor({ state: 'visible', timeout: 60_000 }); console.log('[TEST] Swap completed!'); } catch (e) { console.log('[TEST] Swap may have completed instantly'); diff --git a/web-app/src/components/LocalSwapWidget.vue b/web-app/src/components/LocalSwapWidget.vue index 76669cf..5204051 100644 --- a/web-app/src/components/LocalSwapWidget.vue +++ b/web-app/src/components/LocalSwapWidget.vue @@ -6,9 +6,9 @@