TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

UITesting Lists: How to set accessibilityIdentifier for onDelete swipe button?

Forums > SwiftUI

I'm trying to test my internationalized app in all locales. Testing the delete function from a List like

app.cells.firstMatch.swipeLeft()
app.buttons["Delete"].tap()

obviously only works when in English / Default language.

The List is defined as follows

List {
    ForEach(items) { item in
        ...
    }
    .onDelete(perform: deleteItems)
}

With that, there's no delete-button explicitly defined (same as with the navigation bar's back-button). I couldn't figure out how to add an accessibilityIdentifer so my tests are language agnostic. (I'm usually adding a .accessibilityIdentifier("AddButton") in order to reference it properly in the tests)

So how to set this identifier? Or if it's not possible, what's a feasible way to test it properly?

BTW: I'm using

let navigationBar = app.navigationBars.element(boundBy: 0)
let backButton = navigationBars.buttons.element(boundBy: 0)

already to mitigate the same problem with the back-button and the fact that I can't set an identifier solely to a navigationBar (without setting this accessibilityIdentifier to all elements inside). However using app.buttons.element(boundBy: app.buttons.count - 1) doesn't only look ugly, it may also be wrong (delete button doesn't necessarily have to be the last button).

PS: Why do I see 1 Reply in the list when there's actually no reply visible?

   

Hacking with Swift is sponsored by String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.