Skip to content
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

fix: update xpath selector selection logic yet again #1135

Merged
merged 1 commit into from Oct 19, 2023

Conversation

jlipps
Copy link
Member

@jlipps jlipps commented Oct 19, 2023

this PR primarily removes class/type from xpath uniqueness attributes. instead adds logic to look for unique node names and refer to those if necessary (since class/type are always the same as node names)

@jlipps jlipps requested a review from eglitise October 19, 2023 06:11
Copy link
Collaborator

@eglitise eglitise left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the edge case in my other comment, looks good!

Comment on lines 147 to 151
// even if this node name is unique, if it's the root node, we don't want to refer to it using
// '//' but rather '/'
if (!domNode?.parentNode?.tagName) {
xpath = `/${domNode.tagName}`;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how useful this condition is. From the apps I checked, Android always has two android.widget.FrameLayout as the roots, so isUnique will be false anyway; and iOS has XCUIElementTypeApplication with filled out name and label fields, so the xpath generator will rely on those, and not even reach this base case. So currently I haven't found a usecase for this.

Also, CI is failing here because we can't use optional chaining (Parcel v1 limitation). It probably needs to be something like if (!(domNode.parentNode && domNode.parentNode.tagName)).

Finally, if we really must keep the condition, it should probably be moved inside the isUnique block on the next line.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It really matters for our tests, so I don't have to change a million lines of test code, and I think it might matter for some other hierarchies that come from other platforms. But I'll fix the optional chaining issue.

@jlipps jlipps merged commit 2e70347 into main Oct 19, 2023
5 checks passed
@jlipps jlipps deleted the jlipps/xpath-suggestions branch October 19, 2023 18:50
@eglitise eglitise added the fix This resolves a user-facing problem label Oct 25, 2023
shiva-guntoju pushed a commit to shiva-guntoju/appium-inspector that referenced this pull request Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix This resolves a user-facing problem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants