Hi,
I'm attempting to do an UI tests on my iOS app.
I'm using swiftui for one part of the app and, for the love of god, I can't figure out how to attach an accessibility identifier on the individual items in the Menu Section.
It appears these are just ignores (as well as eg. multiple Text() items within one Button()). Any idea how can i find my items? (those items with top-popup-section- identifier) - Other than the text they show as that's not really a possibility for me.
This is roughly the code i have:
.toolbar {
ToolbarItem(placement: .principal) {
Menu {
Section(content: {
ForEach(pages as? [FormFillPageViewControllerSU<FormFillComponentSU>] ?? [], id: \.id) { page in
Button {
if let index = pages.firstIndex(where: { view in
if let localPage = view as? FormFillPageViewControllerSU<FormFillComponentSU>,
page.id == localPage.id {
return true
}
return false
}) {
withAnimation {
currentPage = index
}
}
} label: {
Text(page.title)
.lineLimit(nil)
.multilineTextAlignment(.leading)
}
// ID for this element doesn't propagate correctly in iOS < 15, so tests cannot work
.accessibilityIdentifier("top-popup-section-s\(page.id)")
}
}, header: {
Text("Switch to Page")
})
} label: {
VStack(alignment: .center, spacing: 2, content: {
let text = viewModel?.response.displayName() ?? "N/A"
let maxLength = UIDevice.current.userInterfaceIdiom == .pad ? 85 : 35
Text(text.with(maxLength: maxLength)).font(.headline)
.frame(minWidth: 100, minHeight: 24, alignment: .center)
.fixedSize(horizontal: true, vertical: true)
.accessibilityLabel(NFLocalizedString("Switch to page", comment: "Fill Page"))
.nestformsAccessibilityIdentifier("response-title-label")
Text(
(pages[currentPage] as? FormFillPageViewControllerSU<FormFillComponentSU>)?
.title ?? "N/A"
).font(.subheadline)
.frame(minWidth: 100, minHeight: 15, alignment: .center)
.fixedSize(horizontal: true, vertical: true)
}).foregroundColor(Color(
viewModel?.response.brand?.color?.appHeadingColor
?? viewModel?.appBranding?.color?.appHeadingColor
?? BrandColor.available[.initial]?.appHeadingColor
?? .label))
}
}
}