skip to Main Content

I’m using Appium for UI test my iOS application.

I want to know current image file name (asset name) loaded to UIImageView, because the image file changes dynamically by cases.

<XCUIElementTypeImage type="XCUIElementTypeImage" name="Accessbility id I set in Xcode" enabled="true" visible="false" accessible="false" x="668" y="498" width="17" height="17" index="1"/>

This is some portion of xml created by Appium.

I expected that a property like ‘value’ or ‘image’ or ‘src’ would appear in the xml code, but it didn’t.

Is there any way to know image resource name?

2

Answers


  1. UI elements in Apple’s XCTest don’t contain original file meta-data. (See, for example, discussion here.)

    Some people recommend to write unit tests if you need to check whether an image with specific name was assigned to a view object.

    Other people store all images in the test bundle, automatically make partial screenshots of image views and compare their representations with stored images. (I personally am not sure how flaky it would be, but, IMO, the option is anyway too complicated.)

    Another option might be to collect app screenshots in all states you want to check, and compare them with expected screenshots. I assume there are tools which can help automate this.

    Login or Signup to reply.
  2. While it would be a very dirty way to write your view, you could theoretically pass the image’s filename as the accessibility ID. As you need to still identify the element you would still use the accessibility label to describe the element.

    Why is this "dirty"? Your UIImageView contains an instance UIImage, not a file. The UIImage also does not store the filename, only the file’s data. For this reason you’d have to get really messy about passing that filename around. This breaks a lot of view controller pattern rules.

    This is not a good candidate for a UI test. Or if it is, not with Appium. Or if it is, with some sort of screenshot comparison tool (I’ve been out of Appium for a few years, but I’m sure you could make even an external tool work with enough effort).

    Again, this seems like a lot of effort and that’s always a red flag to me.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search