fix(mobile): read an iOS tab bar button inside an Other wrapper as a tab (#2498)

roleOf read a button as a tab only when its direct parent was a tab bar
or segmented control. After a document picker closes, XCTest reports the
app with an Other wrapper between the tab bar and its buttons, so the tabs
read as buttons and getByRole('tab') found none. The container check now
skips Other wrappers.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: DongYun Kang <kdy.1997.dev@gmail.com>
This commit is contained in:
gagarinyury
2026-11-30 03:45:15 +00:00
committed by GitHub
co-authored by Claude Opus 5.5 DongYun Kang
parent ddebc946c3
commit d46f2ade8e
4 changed files with 45 additions and 2 deletions
+5
View File
@@ -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`.
+1 -1
View File
@@ -1276,7 +1276,7 @@ to `combobox`.
| `listitem` | `Cell`, `ListItem`, `TableCell`, `CollectionCell` | |
| `row` | `TableRow` | |
| `tablist` | `TabBar`, `TabGroup`, `SegmentedControl` | `TabLayout`, `TabWidget`, `BottomNavigationView` |
| `tab` | `Tab`, `TabBarItem`, `TabBarButton`, and a `Button` inside a `TabBar` or `SegmentedControl` | `TabLayout$TabView`, `BottomNavigationItemView` |
| `tab` | `Tab`, `TabBarItem`, `TabBarButton`, and a `Button` inside a `TabBar` or `SegmentedControl`, through any `Other` wrappers between them | `TabLayout$TabView`, `BottomNavigationItemView` |
| `menu` | `Menu` | |
| `menubar` | `MenuBar` | |
| `menuitem` | `MenuItem`, `MenuBarItem`, `MenuButton` | |
+12 -1
View File
@@ -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;
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);
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
+27
View File
@@ -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' },
{ 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' },