Repository navigation
fix(mobile): read an iOS tab bar button inside an Other wrapper as a tab #2498
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
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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@e2e-dev/mobile': patch | ||
| --- | ||
|
|
||
| On iOS, a tab bar or segmented control button that XCTest nests in an `Other` wrapper reads as a `tab`, as it does without the wrapper. XCTest reports the app that way once a document picker has closed, so `getByRole('tab', 'Search')` stopped finding a tab bar item for the rest of the session and the tree showed it as a `button`. |
| Original file line number | Diff line number | Diff line change | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -399,6 +399,17 @@ function roleOf(kind: string, android: boolean, parentKind: string | undefined): | ||||||||||
| return ROLE_MAP[kind] ?? kind; | |||||||||||
| } | |||||||||||
|
|
|||||||||||
| /** | |||||||||||
| * The kind of the nearest ancestor that is not an `Other` wrapper. XCTest can | |||||||||||
| * nest a tab bar's buttons in one, as it does for the whole app after a | |||||||||||
| * document picker closes, and the tab bar still says what they are. | |||||||||||
| */ | |||||||||||
| function containerKind(parent: ProjectedNode | undefined): string | undefined { | |||||||||||
| let node = parent; | |||||||||||
| while (node?.kind === 'other') node = node.parent; | |||||||||||
|
Collaborator
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. P3 · Non-blocking · The walk also skips an Optional. This does not block the merge. The loop skips every ancestor whose kind is Projection at base
A button in such a container stops matching |
|||||||||||
| return node?.kind; | |||||||||||
| } | |||||||||||
|
|
|||||||||||
| /** | |||||||||||
| * The role an app declared beside the platform's class: Android's heading | |||||||||||
| * flag (React Native's `accessibilityRole="header"`), else the localized role | |||||||||||
|
|
@@ -701,7 +712,7 @@ export function projectSnapshot( | ||||||||||
| // `Other`: it is the role the app declared, and iOS had no trait for it. | |||||||||||
| // Only an `Other` carries that encoding; a native control's value is its own. | |||||||||||
| const spelled = android || kind !== 'other' ? undefined : reactNativeValue(source.value); | |||||||||||
| const role = editableRole(spelled?.role ?? describedRole(source, echoedTexts.has(position)) ?? roleOf(kind, android, parent?.kind), source.editable); | |||||||||||
| const role = editableRole(spelled?.role ?? describedRole(source, echoedTexts.has(position)) ?? roleOf(kind, android, containerKind(parent)), source.editable); | |||||||||||
|
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. Preserve semantically identified containers. For
|
|||||||||||
| const editable = source.editable === true || (role !== undefined && TEXT_INPUT_ROLES.has(role)); | |||||||||||
| const value = showsHint(source, android, editable) ? '' : spelled === undefined ? source.value : spelled.value; | |||||||||||
| // iOS names a secure field by class; UIAutomator flags a password | |||||||||||
|
|
|||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -226,6 +226,33 @@ describe('snapshot projection', () => { | |
| expect(project(webDriver).viewport).toEqual({ width: 390, height: 844 }); | ||
| }); | ||
|
|
||
| it('reads a tab bar or segmented control button nested in an Other wrapper as a tab', () => { | ||
| const projected = project([ | ||
| { ref: 'e1', index: 0, depth: 0, type: 'Application', label: 'Rechka' }, | ||
| { ref: 'e2', index: 1, parentIndex: 0, depth: 1, type: 'TabBar', label: 'Tab Bar' }, | ||
| { ref: 'e3', index: 2, parentIndex: 1, depth: 2, type: 'Other', label: 'Recordings' }, | ||
| { ref: 'e4', index: 3, parentIndex: 2, depth: 3, type: 'Button', label: 'Recordings', selected: true }, | ||
| { ref: 'e5', index: 4, parentIndex: 2, depth: 3, type: 'Button', label: 'Search' }, | ||
| { ref: 'e6', index: 5, parentIndex: 0, depth: 1, type: 'SegmentedControl' }, | ||
| { ref: 'e7', index: 6, parentIndex: 5, depth: 2, type: 'Other' }, | ||
| { ref: 'e8', index: 7, parentIndex: 6, depth: 3, type: 'Button', label: 'Weekly' }, | ||
| { ref: 'e9', index: 8, parentIndex: 0, depth: 1, type: 'Other' }, | ||
|
Collaborator
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. P3 · Non-blocking · The negative case does not show which ancestor kinds the walk skips Optional. This does not block the merge. The only negative case is
Collaborator
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. P3 · Non-blocking · The negative case does not show which ancestor kinds the walk skips Optional. This does not block the merge. The only negative case is |
||
| { ref: 'e10', index: 9, parentIndex: 8, depth: 2, type: 'Button', label: 'Save' }, | ||
| ]); | ||
| expect(projected.index.map((entry) => entry.node.role)).toEqual([ | ||
| 'application', | ||
| 'tablist', | ||
| 'other', | ||
| 'tab', | ||
| 'tab', | ||
| 'tablist', | ||
| 'other', | ||
| 'tab', | ||
| 'other', | ||
| 'button', | ||
| ]); | ||
| }); | ||
|
|
||
| it('maps iOS composite widgets onto the vocabulary roles a browser reports for them', () => { | ||
| const projected = project([ | ||
| { ref: 'e1', index: 0, depth: 0, type: 'Application', label: 'Shop' }, | ||
|
|
||
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.
P3 · Non-blocking · The walk also skips an
Otherthat has a declared roleOptional. This does not block the merge.
The loop skips every ancestor whose kind is
other. It also skips anOtherthat has a role from React Native (the role thatreactNativeValuereads from the value, or the role thatdescribedRolereads from the role description). The roles table atdocs/reference/mobile.mdx:1289says that such a role replaces the type.Trigger:
TabBar > Other(value: "tool bar") > Button. At7c1b2b2the projection istablist / toolbar / button. At2dc19d6it istablist / toolbar / tab.TabBar > Other(roleDescription: "Tab List") > Buttonchanges frombuttontotabin the same way. Thus a toolbar button inside a tab bar matchesgetByRole('tab')and no longer matchesgetByRole('button').This tree is not common: a native tab bar seldom contains a React Native view with a declared role, and no captured golden tree has this shape.