-
Notifications
You must be signed in to change notification settings - Fork 806
fix: allow first/last as modifiers after role/text locators in find command #389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -887,7 +887,10 @@ async function handleGetByRole( | |
| browser: BrowserManager | ||
| ): Promise<Response> { | ||
| const page = browser.getPage(); | ||
| const locator = page.getByRole(command.role as any, { name: command.name }); | ||
| let locator = page.getByRole(command.role as any, { name: command.name }); | ||
| if (command.index !== undefined) { | ||
| locator = command.index === -1 ? locator.last() : locator.nth(command.index); | ||
| } | ||
|
|
||
| switch (command.subaction) { | ||
| case 'click': | ||
|
|
@@ -910,12 +913,18 @@ async function handleGetByText( | |
| browser: BrowserManager | ||
| ): Promise<Response> { | ||
| const page = browser.getPage(); | ||
| const locator = page.getByText(command.text, { exact: command.exact }); | ||
| let locator = page.getByText(command.text, { exact: command.exact }); | ||
| if (command.index !== undefined) { | ||
| locator = command.index === -1 ? locator.last() : locator.nth(command.index); | ||
| } | ||
|
|
||
| switch (command.subaction) { | ||
| case 'click': | ||
| await locator.click(); | ||
| return successResponse(command.id, { clicked: true }); | ||
| case 'fill': | ||
| await locator.fill(command.value ?? ''); | ||
| return successResponse(command.id, { filled: true }); | ||
|
Comment on lines
+925
to
+927
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
A Useful? React with 👍 / 👎. |
||
| case 'hover': | ||
| await locator.hover(); | ||
| return successResponse(command.id, { hovered: true }); | ||
|
|
@@ -927,7 +936,10 @@ async function handleGetByLabel( | |
| browser: BrowserManager | ||
| ): Promise<Response> { | ||
| const page = browser.getPage(); | ||
| const locator = page.getByLabel(command.label); | ||
| let locator = page.getByLabel(command.label); | ||
| if (command.index !== undefined) { | ||
| locator = command.index === -1 ? locator.last() : locator.nth(command.index); | ||
| } | ||
|
|
||
| switch (command.subaction) { | ||
| case 'click': | ||
|
|
@@ -947,7 +959,10 @@ async function handleGetByPlaceholder( | |
| browser: BrowserManager | ||
| ): Promise<Response> { | ||
| const page = browser.getPage(); | ||
| const locator = page.getByPlaceholder(command.placeholder); | ||
| let locator = page.getByPlaceholder(command.placeholder); | ||
| if (command.index !== undefined) { | ||
| locator = command.index === -1 ? locator.last() : locator.nth(command.index); | ||
| } | ||
|
|
||
| switch (command.subaction) { | ||
| case 'click': | ||
|
|
@@ -1660,7 +1675,10 @@ async function handleGetByAltText( | |
| browser: BrowserManager | ||
| ): Promise<Response> { | ||
| const page = browser.getPage(); | ||
| const locator = page.getByAltText(command.text, { exact: command.exact }); | ||
| let locator = page.getByAltText(command.text, { exact: command.exact }); | ||
| if (command.index !== undefined) { | ||
| locator = command.index === -1 ? locator.last() : locator.nth(command.index); | ||
| } | ||
|
|
||
| switch (command.subaction) { | ||
| case 'click': | ||
|
|
@@ -1677,7 +1695,10 @@ async function handleGetByTitle( | |
| browser: BrowserManager | ||
| ): Promise<Response> { | ||
| const page = browser.getPage(); | ||
| const locator = page.getByTitle(command.text, { exact: command.exact }); | ||
| let locator = page.getByTitle(command.text, { exact: command.exact }); | ||
| if (command.index !== undefined) { | ||
| locator = command.index === -1 ? locator.last() : locator.nth(command.index); | ||
| } | ||
|
|
||
| switch (command.subaction) { | ||
| case 'click': | ||
|
|
@@ -1694,7 +1715,10 @@ async function handleGetByTestId( | |
| browser: BrowserManager | ||
| ): Promise<Response> { | ||
| const page = browser.getPage(); | ||
| const locator = page.getByTestId(command.testId); | ||
| let locator = page.getByTestId(command.testId); | ||
| if (command.index !== undefined) { | ||
| locator = command.index === -1 ? locator.last() : locator.nth(command.index); | ||
| } | ||
|
|
||
| switch (command.subaction) { | ||
| case 'click': | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These handlers now rely on
command.indexto apply.last()/.nth(), but the command validator insrc/protocol.tsstill does not define anindexfield for anygetby*schema and dispatchesresult.datafromsafeParse. That means the newindexemitted by the CLI is dropped before execution, so commands likefind role spinbutton first clickstill target the unscoped locator and can fail when multiple matches exist.Useful? React with 👍 / 👎.