ElaWorkshop / TagListView

Simple and highly customizable iOS tag list view, in Swift.
MIT License
2.64k stars 492 forks source link

Hard to test tag removal in UI tests #238

Closed traviskaufman closed 4 years ago

traviskaufman commented 5 years ago

I'm currently in the process of writing UI tests for an app that makes liberal use of TagListView; it is a fantastic library! As part of these tests, I need to remove a tag. Clicking the remove button on a tag has proven difficult.

I tried querying for the remove button via XCUIApplication().buttons["tagText"].children(matching: .button).firstMatch but that does not return anything.

I tried adding an accessibility label to the remove button, but because it's internal the only way I could do this was by subclassing TagView, which seems like overkill since it would require more work to make sure my TagListViews always add the subclass with the accessible remove button.

What I would up doing was tapping on a specific portion of the tag view that I knew contained the remove button:

let REMOVE_BTN_OFFSET = CGVector(dx: 0.7, dy: 0.5)
let removeButtonCoord = app.buttons["B"].coordinate(
    withNormalizedOffset: REMOVE_BTN_OFFSET)
removeButtonCoord.tap()

This only works because I know exactly what the content in the tag I'm trying to remove is. I'm wondering if the maintainers would be open to making clicking this a bit easier? Some possible solutions:

Happy to contribute as well. Thanks again for building such a great library!

anti-transmission commented 4 years ago

I think both ideas make sense. Feel free to contribute.