Search code examples
iosxcodeappiumappium-iosxcuitest

Appium get image file name of XCUIElementTypeImage


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?


Solution

  • 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.