fix: allow first/last as modifiers after role/text locators in find command #389
+252
−28
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #364
Currently,
firstandlastare only recognized as standalone locator types in thefindcommand (e.g.,find first <selector>). This means chaining them as modifiers after semantic locators likerole,text,label, etc. fails with an error.For example, this command fails:
Because
firstat position 3 is interpreted as the subaction (likeclick/fill), not as a modifier.Changes
CLI Parser (
cli/src/commands.rs)role,text,label,placeholder,alt,title,testid) and its value, the parser now checks if the next token isfirst,last, ornthindexfield to the JSON command (0 for first, -1 for last, or the specified index for nth) and shifts the remaining arguments accordinglyfind first <selector>andfind last <selector>continue to work as before (backward compatible)Server-side Handlers (
src/actions.ts,src/types.ts)indexfield toGetByRoleCommand,GetByTextCommand,GetByLabelCommand,GetByPlaceholderCommand,GetByAltTextCommand,GetByTitleCommand, andGetByTestIdCommandinterfaceshandleGetBy*functions to apply.first(),.last(), or.nth()on the locator when anindexfield is presentHelp Text (
cli/src/output.rs)findcommand help to document the new modifier syntax with examplesTests
find role <role> first/last/nth <n> <action> [value]find text <text> first <action>find label <label> last <action> <value>find placeholder <text> first <action> <value>find testid <id> last <action>find first/last <selector>still worksfind role <role> <action>without modifier has no index fieldExamples