One of the best things about mobile apps is how much access they have to all the wonderful functionality of mobile devices. Apps can pull in photos taken from the device for their own purposes. But when running automated tests of these applications, the device is always starting from a clean slate, with no photo fixtures on it (or it should be!).
One challenge for the Appium tester is to figure out how to seed the device under test with photos, and not just any photos, but the exact ones whose behavior within the app will have known results, to make verification of that behavior possible.
The trick is to use Appium's pushFile command. This is a little-known command that enables pushing of files to the iOS app container. In a special mode, it can also leverage simctl's addmedia command under the hood to drop whatever images you want on the device. The pushFile command works like this:
In other words, you give the image a name (this is important because iOS uses it to make it the correct image type on the sim), and then you give the driver a path to the actual file on your local system. That's it! Check out the full example below (or view it on GitHub):
Note that it's important not to put any slashes in front of the image name, otherwise Appium might think you want to copy it into the app container rather than add it to the media library on the device.
Interested in how to perform the same trick with Android? Check out the Appium Pro article on photos in Android!