Pushing image files to remote Appium Android emulator

I’m trying to push files from a local filesystem to a remote Appium server running an Android emulator.

I’m doing this (in Ruby):

contents = File.read(“/localdisk/testimages/test-image-1.jpg”)
$driver.push_file(“/sdcard/Pictures/testapp/test-image-1.jpg”, contents)

But my emulator is showing no data has been copied (I check with local adb).

I’m not sure what to do :frowning:

We use almost the exact code on our project and we don’t have any problems with it (although we aren’t using an emulator)

Stupid question time:
Is the file getting created on the device?
What is the size of test-image-1.jpg on /localdisk/testimages, and can you verify the size of contents after you read it in?

I figured out my problem! The issue was the path I was providing wasn’t being string-manipulated properly. The sample code I gave above was what I expected to be there. Oops!

BTW, the code looks familiar to you because you posted it somewhere else, and that’s what I ended up using, so thanks a lot for that!

One other thing though… What’s the best way to deal with the fact that Android doesn’t display the files in the gallery until the mediastore gets refreshed? Since I’m copying these assets in right before the test, I’m not sure what the best course of action is.

When running locally, I know that you can simply do:
adb shell am broadcast -a android.intent.action.MEDIA_MOUNTED -d file:///sdcard

But my understanding is you can’t execute adb commands on the emulator when running Appium remotely…

@GeorgeCostanza, we don’t use emulators, and as you have correctly deduced, our solution is to send the broadcast.

I think in this case there’s no difference running on emulator vs a real device.

What I’m wondering is, how can you tell the remote Appium server to execute an adb command?

When the machine executing the rspec test is the same as the machine running the Appium server, running adb is easy. But is there a way to tell a remote Appium server to do that?

There’s no easy way in Appium that I know of. This is why we have had to abandon the remote server solution because the Appium Architecture doesn’t provide us access to required ADB commands. Our solution was to build an internal product which received job requests and farmed it out to a machine/vm where the client and server could run local to each other.

Yeah, I decided to take this route as well.

Thanks a lot for the help!

Any luck with pushing files to iOS simulators? (I am using Python and method from documentation is not working for me).