Repository navigation
feat(sdk-go): add role and text locator builders - #3193
Open
supremeboxlogos wants to merge 6 commits into
Open
supremeboxlogos wants to merge 6 commits into
supremeboxlogos wants to merge 6 commits into
Conversation
🦋 Changeset detectedLatest commit: cc48c11 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
There was a problem hiding this comment.
1 issue found across 6 files
Confidence score: 4/5
GetByRoleinpackages/sdk-go/semantic_locator.goaccepts unsupported roles andLevel: 0, so invalid input fails only on the first browser operation. Validate the role and options before returning the locator.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/sdk-go/semantic_locator.go">
<violation number="1" location="packages/sdk-go/semantic_locator.go:16">
P2: `GetByRole` returns a locator without error for unsupported roles or `Level: 0`, so the invalid input fails only on the first browser operation. Validate the role and options before returning the locator, matching the TypeScript and Python builders.</violation>
</file>
Architecture diagram
sequenceDiagram
participant GoSDK as Go SDK (User Code)
participant PL as PageLocator
participant Page as Page
participant RPC as RPC Client
participant Ext as Extension Runtime (Chrome)
participant DOM as DOM/Accessibility Tree
Note over GoSDK,Page: NEW: Semantic Locator Builder API
GoSDK->>Page: GetByRole(role, options)
Page->>Page: newSemanticLocator(role step)
Page-->>GoSDK: PageLocator (lazy, no RPC)
GoSDK->>Page: GetByText(text, options)
Page->>Page: newSemanticLocator(text step)
Page-->>GoSDK: PageLocator (lazy, no RPC)
GoSDK->>PL: GetByRole(role, options)
PL->>PL: extendSemanticLocator()
alt Existing semantic query
PL->>PL: Decode existing step array
else Plain CSS selector
PL->>PL: Encode selector as first step
end
opt Locator has Nth/First selection
PL->>PL: Append nth step to array
end
PL->>PL: Append role step
PL-->>GoSDK: PageLocator (lazy, no RPC)
GoSDK->>PL: GetByText(text, options)
PL->>PL: extendSemanticLocator()
PL-->>GoSDK: PageLocator (lazy, no RPC)
GoSDK->>PL: Locator(selector)
alt Selector contains reserved semantic prefix
PL-->>GoSDK: Error (reject nested query)
else Valid selector
PL->>PL: extendSemanticLocator()
PL-->>GoSDK: PageLocator (lazy, no RPC)
end
Note over GoSDK,Ext: Lazy Evaluation - First Action Trigger
GoSDK->>PL: Count() / Click() / InnerText()
PL->>RPC: locator.count / locator.click / locator.inner_text
RPC->>Ext: JSON-RPC with encoded query steps
Ext->>DOM: Resolve semantic steps (ARIA role, accessible name/regex)
DOM-->>Ext: Matching elements
Ext-->>RPC: Result
RPC-->>PL: Locator action result
PL-->>GoSDK: Result / error
Note over GoSDK,Ext: Option Snapshot Behavior
GoSDK->>PL: Build locator with options
PL->>PL: Snapshot options at build time
GoSDK->>GoSDK: Mutate original options after build
Note over PL,GoSDK: Existing locator unaffected (snapshot preserved)
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
| // visible text. Hidden elements are excluded unless IncludeHidden is true. | ||
| // Pass nil options for defaults. | ||
| func (p *Page) GetByRole(role AriaRole, options *GetByRoleOptions) (*PageLocator, error) { | ||
| return newSemanticLocator(p.rpc, p.PageID(), nil, RoleQueryStep{Kind: "role", Role: role, Options: options}) |
Contributor
There was a problem hiding this comment.
P2: GetByRole returns a locator without error for unsupported roles or Level: 0, so the invalid input fails only on the first browser operation. Validate the role and options before returning the locator, matching the TypeScript and Python builders.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At packages/sdk-go/semantic_locator.go, line 16:
<comment>`GetByRole` returns a locator without error for unsupported roles or `Level: 0`, so the invalid input fails only on the first browser operation. Validate the role and options before returning the locator, matching the TypeScript and Python builders.</comment>
<file context>
@@ -0,0 +1,100 @@
+// visible text. Hidden elements are excluded unless IncludeHidden is true.
+// Pass nil options for defaults.
+func (p *Page) GetByRole(role AriaRole, options *GetByRoleOptions) (*PageLocator, error) {
+ return newSemanticLocator(p.rpc, p.PageID(), nil, RoleQueryStep{Kind: "role", Role: role, Options: options})
+}
+
</file context>
2 tasks done
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
why
Complete the stack with a focused Go API review. Stacked on #3192; approximately 560 changed lines including documentation and tests.
what changed
test plan