How to automate capturing picture in mobile app using Ruby language?

Hi All,

How to automate capturing picture in mobile web using Ruby language?

After taking Picture, how to select Ok or Cancel button?
Platform - Android


Assuming you have accessed the native camera screen, you will need to switch context to the native_app view and can click the camera using: driver.key_event(27).

You may then have to tap an okay button using either a locator or coordinates depending on your flavor of android.

Thanks Cauthon. Will try it with locator after switching.

I’ve found that while this works quite well with Nexus devices, it fails on other manufacturers’ devices such as the Droid Turbo or Samsung S4. On those devices we use device-specific ids.

As for tapping on “Ok” and “Cancel” after taking a photo, using specific ids also seem to be the only reliable way. For example see below:

def done_button_ids
  return [
    '', # Nexus 7 with Android M 
    '', # Droid Turbo
    '', # Amazon Fire Tablet
    '', # Samsung S4

def click_done_button
  # To confirm the camera image that was taken
  done_button_ids.each do |id|
    done = click_on_element_if_exists(id)
    if done

This does require a list of ids for every device you use for appium testing, but with a small enough set of test devices it is manageable.

If anyone have a better method do tell!

What really does the OK and Cancel buttons? You could also go and tap them by text, isn’t it?

After taking a photo, you have to confirm whether the photo is one you want to use or discard and take again (it could be blurry, poor exposure, etc).

Text doesn’t work globally because sometimes it can be Ok/Cancel, or Save/Discard, or in different languages, but more importantly they’re icons with no text on Nexus and other devices.

In rhose cases I use buttons command.
It returns an array with all the buttons in the screen.

@zai: driver.key_event(27) works on my Samsung S4, but I agree, using resource id’s whenever possible, is the best way to go.

When I have to store device specific id’s for a button, I usually create a hash map or data-dictionary with the device name as the key and the locator as a value. As my tests know my device on initialization, it allows me to easily maintain and update their values in one place.