I'll try to simplify my problem. I'm writing a test program using py.test and appium. Now:
In the application I have 4 media formats: Video, Audio, Image and Document. I have a control interface with previous, next, play , stop buttons. Each media formats has a unique ID like
video_playbutton, audio_playbutton, document_playbutton, image_playbutton, video_stopbutton audio_stopbutton ...etc etc.
But the operation I have to do is the same for all of them e.g press on playbutton.
I can address playbutton of each when i give them explicitly like this
find_element_by_id("video_playbutton")
And when i want to press on other playbuttons I've to repeat above line each time. Like this:
find_element_by_id("video_playbutton")
find_element_by_id("audio_playbutton")
find_element_by_id("image_playbutton")
find_element_by_id("document_playbutton")
And because I'm calling this function from another script I would have to distinguish first what string I got e.g:
def play(mediatype):
if mediatype == "video"
el = find_element_by_id("video_playbutton")
el.click()
if mediatype == "audio"
el = find_element_by_id("audio_playbutton")
el.click()
if .....
What is the best way to solve this situation? I want to avoid hundreds of if-statements because there is also stop, next , previous etc buttons.
I'm rather searching for something like this
def play(mediatype)
find_element_by_id(mediatype.playbutton)
el = find_element_by_id(mediatype+"_playbutton"); ... ; el.click()? In..., you'd want to check whether you actually found something, of course.ids = dict(); ids['video'] = 'video_playbutton'; ids['audio'] = 'audio_playbutton'; ... ;and then later doel = find_element_by_id[ids[mediatype]]; ...; el.click(). Then you the lookup code is simple, and the only tedious part is generating that mapping. That mapping has to exist somewhere, and it's probably much more flexible to keep it as a mapping than as a bunch of if/elif/else statements.