I'm working on converting an app to SwiftUI, and I have a menu that used to be several table cells in a storyboard, but I moved it to an embedded SwiftUI view instead.
Here's the old way (from override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
):
cellReuseID = "BillingToolsCell"
let cell = tableView.dequeueReusableCell(withIdentifier: cellReuseID, for: indexPath)
if let billingToolsCell = cell as? BillingToolsCell {
billingToolsCell.billingToolsOptions.text = billingTools[indexPath.row].title
// Accessibility
billingToolsCell.isAccessibilityElement = true
billingToolsCell.accessibilityIdentifier = "Billing_\(billingTools[indexPath.row].title.replacingOccurrences(of: " ", with: ""))"
}
return cell
And here's the new way I'm creating the cell:
cellReuseID = "BillingToolsSwiftUI"
if let cell = tableView.dequeueReusableCell(withIdentifier: cellReuseID, for: indexPath) as? SwiftUIHostTableViewCell<BillingToolsView> {
let view = BillingToolsView(billingToolVM: BillingToolViewModel()) { segueID in
self.performSegue(segueID: segueID)
}
cell.host(view, parent: self)
return cell
}
Here's the swiftUI view:
struct BillingToolsView: View {
@StateObject var billingToolVM: BillingToolViewModel
var navigationCallback: (String) -> Void
var body: some View {
VStack {
VStack{
ForEach(self.billingToolVM.billingToolList, id: \.self) { tool in
Button {
navigationCallback(tool.segueID)
} label: {
BillingToolsRowView(toolName: tool.title)
Divider().foregroundColor(AFINeutral800_SwiftUI)
}
.accessibilityIdentifier("Billing_\(tool.title.replacingOccurrences(of: " ", with: ""))")
}
}
.padding(.vertical)
.padding(.leading)
.background(AFINeutral0_SwiftUI)
}
}
}
If I check the accessibility inspector, I can see the identifier - here it is showing Billing_PaymentHistory:
But when the testers try to run their tests in Appium, they don't see any identifier at all:
Did I mess up setting up the accessibility identifier somehow? Or do the testers need to update their script?