Search code examples
swiftassetsxcode-ui-testingswift4

Swift: Assets not visible to UI tests when ran from the command line


I have a set of UI tests that are testing the state of a checkbox. There is no in-built checkbox element in swift, therefore I am using two images (checked and unchecked). When I am running the tests with the simulator open, everything works fine. When I am running the tests in the command line (needed for continuous integration) all the tests fail at the parts where images(assets) are included. Therefore the assets are not visible to UI tests (even though I gave them visibility in the image settings)

This is how I am testing the images:

tablesQuery.cells.containing(.staticText, identifier: item).images["checked"].tap()

Should I call the images in a different way? Is there any other option to make images visible besides checking the option to make images visible to the UI tests?


Solution

  • UI tests are opening the application itself and testing the presence of elements on it. Therefore, file paths are not visible to them (just like objects). A good trick is to set an accesibility identifier of the image every time the image changes state. Set the identifier with the same name as the image that is present and it should work.

    accessibilityIdentifier = "checked"