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 [
'com.android.camera2:id/done_button', # Nexus 7 with Android M
'com.motorola.camera:id/review_approve', # Droid Turbo
'com.amazon.camera:id/btn_done', # Amazon Fire Tablet
'com.sec.android.app.camera:id/save', # Samsung S4
]
end
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
break
end
end
end
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!