Skip to content

How to test button with image #19

Discussion options

You must be logged in to vote

Hi @ckunchur,

As @vishnuravi pointed out, the accessibility modifier is the right way to go, you are on a good path!
Your code example that you have shared only as a syntax error and you have to attach the accessibility modifier to the complete button:

Button(
    action: {
        // ... your action
    },
    label: {
        Bundle.module.image(fromFileNamed: "Instagram")
            .resizable()
            .padding(.horizontal, 5)
            .frame(width: 65, height: 40)
    }
)
    .accessibilityIdentifier("Instagram")

You can then tap the button in your UI test using the following call:

app.buttons["Instagram"].tap()

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@ckunchur
Comment options

ckunchur Jan 24, 2023
Collaborator Author

Comment options

You must be logged in to vote
1 reply
@PSchmiedmayer
Comment options

Answer selected by ckunchur
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants