def shortcut(self, key, shift=False): """Keyboard press of the correct shortcut key for os x = cmd + key for win and linux = ctrl + key """ if shift == False: if config.get_os_name() == "osx": type(key, KEY_CMD) elif config.get_os_name() == "win": type(key, KEY_CTRL) elif config.get_os_name() == "lin": type(key, KEY_CTRL) else: print config.get_os_name() type(key, KEY_CTRL) else: if config.get_os_name() == "osx": type(key, KEY_CMD + KEY_SHIFT) elif config.get_os_name() == "win": type(key, KEY_CTRL + KEY_SHIFT) elif config.get_os_name() == "lin": type(key, KEY_CTRL + KEY_SHIFT) else: print config.get_os_name() type(key, KEY_CTRL + KEY_SHIFT)
def multi_select(self, region, item_list): """Use the CTRL or CMD key as os appropriate to select items in a region. Return a list of the items that we successfully selected. """ selected_items = [] #press the ctrl / cmd key if config.get_os_name() == "osx": keyDown(Key.CMD) else: keyDown(Key.CTRL) #select each item in the list if it is found time.sleep(2) for x in item_list: print x if region.exists(x): region.click(x) time.sleep(2) selected_items.append(x) #release the ctrl /cmd key if config.get_os_name() == "osx": keyUp(Key.CMD) else: keyUp(Key.CTRL) return selected_items
def multi_select(self, region, item_list): """Use the CTRL or CMD key as os appropriate to select items in a region. Return a list of the items that we successfully selected. """ selected_items = [] # press the ctrl / cmd key if config.get_os_name() == "osx": keyDown(Key.CMD) else: keyDown(Key.CTRL) # select each item in the list if it is found time.sleep(2) for x in item_list: print x if region.exists(x): region.click(x) time.sleep(2) selected_items.append(x) # release the ctrl /cmd key if config.get_os_name() == "osx": keyUp(Key.CMD) else: keyUp(Key.CTRL) return selected_items
def cmd_ctrl(): """Based on the operating systems, returns the correct key modifier for shortcuts. """ if config.get_os_name() == "osx": return "CMD" elif config.get_os_name() == "win": return "CTRL" else: print config.get_os_name() return "CTRL"
def open_ff(): """Returns the launch path for the application. launch is an os specific command """ if config.get_os_name() == "osx": return "/Applications/Firefox.app" elif config.get_os_name() == "win": return os.path.join(os.getenv("PROGRAMFILES"),"Mozilla Firefox","firefox.exe") elif config.get_os_name() == "lin": config.start_ff_on_linux() return "Firefox" else: print "no clue"
def launch_cmd(): """Returns the launch path for the application. launch is an os specific command """ if config.get_os_name() == "osx": return "/Applications/Miro.app" elif config.get_os_name() == "win": return os.path.join(os.getenv("PROGRAMFILES"),"Participatory Culture Foundation","Miro","Miro.exe") elif config.get_os_name() == "lin": print "trying to run on linux - make sure MIRONIGHTLYDIR is set" return "linux" else: print config.get_os_name()
def __init__(self): config.set_image_dirs() self.os_name = config.get_os_name() PREF_HEADING = Pattern("pref_heading.png") def preference_panel_regions(): if not exists(PREF_HEADING): self.open_prefs() exists(PREF_HEADING, 10) heading = Region(getLastMatch()) gtw = heading.getW()/10 heading.setX(heading.getX() - gtw) heading.setW(heading.getW() + gtw*2) heading.setH(heading.getH() + 30) heading.setAutoWaitTimeout(10) settings = Region(heading.below()) settings.setAutoWaitTimeout(10) return (heading, settings) def screen_region(): myscreen = Screen() screen = Region(myscreen.getBounds()) return screen self.hr, self.sr = preference_panel_regions() self.screen = screen_region()
def test_4(self): """http://litmus.pculture.org/show_test.cgi?id=4 1st time install, specify a dir to search. Litmus Test Title:: 4 - 1st time install, specify a dir to search Description: 1. Clean up Miro support and vidoes directories 2. Launch - walk through 1st tieme install dialog and search everywhere """ if exists("Miro",3) or \ exists("Music",3): click(getLastMatch()) mirolib.quit_miro(self) if config.get_os_name() == "osx": time.sleep(20) config.delete_database_and_prefs() config.delete_miro_video_storage_dir() setAutoWaitTimeout(testvars.timeout) #set the search regions mirolib.restart_miro(confirm=False) search_path = os.path.join(os.getenv("PCF_TEST_HOME"),"Miro","TestData") mirolib.first_time_startup_dialog(self,lang="Default",run_on_start="No",search="Yes",search_path=search_path,itunes="No") reg = mirolib.AppRegions() time.sleep(10) mirolib.click_sidebar_tab(self,reg,"Videos") mirolib.tab_search(self,reg,title="Deerhunter",confirm_present=True) mirolib.click_sidebar_tab(self,reg,"Music") mirolib.tab_search(self,reg,title="Pancakes",confirm_present=True)
def test_173(self): """http://litmus.pculture.org/show_test.cgi?id=173 1st time install, search everywhere Litmus Test Title:: 173 - 1st time install, search everywhere Description: 1. Clean up Miro support and vidoes directories 2. Launch - walk through 1st tieme install dialog and search everywhere """ if exists("Miro",3) or \ exists("Music",3): click(getLastMatch()) mirolib.quit_miro(self) if config.get_os_name() == "osx": time.sleep(20) config.delete_database_and_prefs() config.delete_miro_video_storage_dir() setAutoWaitTimeout(testvars.timeout) #set the search regions mirolib.restart_miro(confirm=False) search_path = os.path.join(os.getenv("PCF_TEST_HOME"),"Miro","TestData") mirolib.first_time_startup_dialog(self,lang="Default",run_on_start="No",search="Yes",search_path="Everywhere",itunes="No") reg = mirolib.AppRegions() time.sleep(10) mirolib.click_sidebar_tab(self,reg,"Videos") find(Pattern("sort_name_normal.png").exact()) doubleClick(getLastMatch().below(100)) mirolib.verify_video_playback(self,reg)
def type_a_path(self, dirname): if config.get_os_name() == "win": if not exists("Location", 5): click(self.SYS_TEXT_ENTRY_BUTTON) time.sleep(2) type(dirname + "\n") type(Key.ENTER)
def type_a_path(self, dirname): if config.get_os_name() == "win": if not exists("Location",5): click(self.SYS_TEXT_ENTRY_BUTTON) time.sleep(2) type(dirname +"\n") type(Key.ENTER)
def launch_cmd(): """Returns the launch path for the application. launch is an os specific command """ if config.get_os_name() == "osx": return "/Applications/Miro.app" elif config.get_os_name() == "win": return os.path.join(os.getenv("PROGRAMFILES"), "Participatory Culture Foundation", "Miro", "Miro.exe") elif config.get_os_name() == "lin": print "trying to run on linux - make sure MIRONIGHTLYDIR is set" return "linux" else: print config.get_os_name()
def __init__(self): ''' Constructor ''' self.os_name = config.get_os_name() self.SYS_TEXT_ENTRY_BUTTON = Pattern('type_a_filename.png') self.OPTION_EXPAND = Pattern("prefs_expand_option.png")
def _add_a_file(self, filename): input_file_path = os.path.join(os.path.join(os.getenv("PCF_TEST_HOME"),"MVC", "TestData")) testfile = os.path.join(input_file_path, filename) self.reg.click(self.CHOOSE_FILE) time.sleep(2) type(testfile +"\n") if config.get_os_name() == "osx": time.sleep(2) type(Key.ENTER)
def type_a_path(self,file_path): if config.get_os_name() == "osx": type(file_path +"\n") else: if not exists("Location",5): click(Pattern("type_a_filename.png")) time.sleep(2) else: #clear any text in the type box for x in range(0,15): type(Key.DELETE) type(file_path +"\n")
def type_a_path(self, file_path): if config.get_os_name() == "osx": type(file_path + "\n") else: if not exists("Location", 5): click(self.SYS_TEXT_ENTRY_BUTTON) time.sleep(2) else: #clear any text in the type box for x in range(0, 15): type(Key.DELETE) type(file_path + "\n")
def __init__(self): ''' Constructor ''' config.set_image_dirs() self.os_name = config.get_os_name() # CMD or CTRL Key if self.os_name == 'osx': self.CMDCTRL = Key.CMD else: self.CMDCTRL = Key.CTRL
def save_prefs(self,reg,p,allset): if allset == True or \ config.get_os_name() == "osx": type(Key.ESC) else: if p.exists(Pattern("button_close.png"),5) or \ p.exists("Close",5): click(p.getLastMatch()) if reg.t.exists("Miro",2): click(reg.t.getLastMatch()) time.sleep(2)
def type_a_path(self, file_path): if config.get_os_name() == "osx": type(file_path + "\n") else: if not exists("Location", 5): click(self.SYS_TEXT_ENTRY_BUTTON) time.sleep(2) else: # clear any text in the type box for x in range(0, 15): type(Key.DELETE) type(file_path + "\n")
def __init__(self): ''' Constructor ''' self.os_name = config.get_os_name() self.SYS_TEXT_ENTRY_BUTTON = Pattern('type_a_filename.png') self.OPTION_EXPAND = Pattern("prefs_expand_option.png") AppRegion = MiroRegions() self.s = AppRegion.s self.sidebar_width = self.s.getW() self.m = AppRegion.m self.mtb = AppRegion.mtb self.t = AppRegion.t self.mr = AppRegion.mr
def restart_miro(confirm=True): if config.get_os_name() == "lin": config.start_miro_on_linux() else: App.open(open_miro()) if confirm == True: time.sleep(5) if exists(Pattern("icon-guide_active.png"),10) or \ exists(Pattern("icon-guide.png"),10) or \ exists("Miro",45): print "miro started" else: print("can't confirm miro restarted") else: time.sleep(5) #give it 5 secs - probably waiting for 1st time dialog or other
def convert_file(self,reg,out_format): if config.get_os_name() == "osx": reg.t.click("Convert") else: type('c',KEY_ALT) find("Conversion Folder") tmpr = Region(getLastMatch().above()) tmpr.setX(tmpr.getX()-50) tmpr.setW(tmpr.getW()+100) if out_format == "MP3": tmpr.find("Theora") click(tmpr.getLastMatch().above(80)) else: tmpr.find(out_format) click(tmpr.getLastMatch())
def __init__(self): """ Constructor """ self.os_name = config.get_os_name() self.SYS_TEXT_ENTRY_BUTTON = Pattern("type_a_filename.png") self.OPTION_EXPAND = Pattern("prefs_expand_option.png") AppRegion = MiroRegions() self.s = AppRegion.s self.sidebar_width = self.s.getW() self.m = AppRegion.m self.mtb = AppRegion.mtb self.t = AppRegion.t self.mr = AppRegion.mr
def __init__(self): self.os_name = config.get_os_name() self.mvcapp = App(config.launch_cmd()) self.testfiles = input_files() self.DEVICE_MENU = Pattern("device_menu.png") self.CONVERT = Pattern("convert.png") self.DROP_ZONE = Pattern("drop_zone.png") self.CHOOSE_FILE = Pattern("choose_a_file.png") self.STARTING = Pattern('starting.png') self.FINISHED = Pattern('finished.png') self.OPEN = Pattern('Open.png') self.mvcapp.focus() time.sleep(3) self.reg = set_regions() setAutoWaitTimeout(10)
def browser_to_miro(self,reg,url): """Opens the browser and copies in a url. Waits then closes the browser. This has the expectation that the browser is configured to open the url with miro, .torrent or feed item. """ myFF = App.open(open_ff()) if reg.t.exists("Firefox",45): click(reg.t.getLastMatch()) if config.get_os_name() == "osx": time.sleep(20) #because on my osx ff is way slow to launch. shortcut("l") time.sleep(2) type(url + "\n") time.sleep(30) myFF.close() waitVanish("Firefox",10) close_ff()
def edit_item_metadata(self, reg, meta_field, meta_value): """Given the field and new metadata value, edit a selected item, or multiple items metadata. """ metalist = ["name","artist","album","genre","track_num", "track_of","year","about","rating","type", "art","path","cancel","ok"] time.sleep(2) if self.os_name=='osx': type(Key.TAB) #os x make sure focus on item so shortcut works time.sleep(2) self.shortcut('i') time.sleep(2) for i in (i for i,x in enumerate(metalist) if x == meta_field.lower()): rep = i if meta_field == "rating": self.edit_item_rating(rating=meta_value) elif config.get_os_name() == "osx" and rep > 6: #stupid but the tab gets stuck on the about field if meta_field == "art": click("Click to") type(meta_value) type(Key.ENTER) else: click(meta_field) click(getLastMatch().right(50)) type(meta_value) click(Pattern("button_ok.png")) else: for x in range(0,rep): #tab to the correct field type(Key.TAB) time.sleep(.5) if meta_field == "art": #need a space bar to open the text entry field type(" ") type(meta_value) type(Key.ENTER) time.sleep(2) click("button_ok.png") else: type(meta_value) #enter the new value ok_but = len(metalist) for x in range(rep+1,ok_but): type(Key.TAB) time.sleep(.5) type(Key.ENTER) #Save the changes
def test_682(self): """http://litmus.pculture.org/show_test.cgi?id=54 Test Crash Reporter with DB. 1. Perform a search of crash inducing text 2. Submit crash dialog 3. Quit Miro """ print self.id() reg = mirolib.AppRegions() if config.get_os_name() == "osx": reg.tl.click("Dev") else: type("f", KEY_ALT) time.sleep(1) type(Key.LEFT) reg.t.click("Test Soft") mirolib.handle_crash_dialog(self, db=True, test=True)
def test_460(self): """http://litmus.pculture.org/show_test.cgi?id=460 upgrade corrupt db submit crash with db Litmus Test Title:: 460 - upgrade with corrupted db submit crash report with db Description: 1. Replace Miro db with a corrupt database. 2. Launch miro and submit crash report with db """ if exists("Miro",3) or \ exists("Music",3): click(getLastMatch()) mirolib.quit_miro(self) if config.get_os_name() == "osx": time.sleep(20) db = os.path.join(os.getenv("PCF_TEST_HOME"),"Miro","TestData","databases","corrupt_db") config.replace_database(db) setAutoWaitTimeout(testvars.timeout) #set the search regions mirolib.restart_miro(confirm=False) mirolib.corrupt_db_dialog(action="submit_crash",db=True)
def _choose_format(self, out_format): if self.reg.exists(out_format): return self.reg.click(self.DEVICE_MENU) if config.get_os_name() == "win": if out_format == "iPad": type("i") type(Key.ENTER) elif out_format == "Nano": type("i") for x in range(0,3): type(Key.DOWN) type(Key.ENTER) elif out_format == "MP3": type("m") type(Key.DOWN) type(Key.ENTER) elif out_format == "MP4": type("m") type(Key.ENTER) elif out_format == "PSP": type("p") type(Key.ENTER) elif out_format == "Hero": type("h") type(Key.ENTER) elif out_format == "Cliq": type("c") type(Key.ENTER) elif out_format == "G1": type("g") type(Key.ENTER) elif out_format == "WebM": type("w") type(Key.ENTER) elif self.reg.exists(out_format): click(self.reg.getLastMatch()) else: raise Exception("Output format not found") else: self.reg.click(out_format)
def open_tab(self,p,tab): """Open the specified tab by searching with-in the preferences region (p) for the icon. """ if exists("Preferences") and config.get_os_name() == "osx": pr = Region(getLastMatch().below(150)) pr.setX(pr.getX()-250) pr.setW(pr.getW()+500) else: pr = Region(p) pr.highlight(5) for x in testvars.PREF_PANEL.keys(): if tab.lower() in x: pref_icon = testvars.PREF_PANEL[x] print "going to tab: "+str(tab) if pr.exists(Pattern(pref_icon),5) or pr.exists(tab.capitalize(),5): tab_loc = Region(pr.getLastMatch()) click(tab_loc) return tab_loc else: self.fail(tab+" tab not found")
def open_prefs(self, reg, menu=None, option=None): """OS specific handling for Preferences menu, since it differs on osx and windows. """ if reg.s.exists("icon-search.png", 3) or reg.s.exists("icon-video.png", 3): click(reg.s.getLastMatch()) time.sleep(3) if menu == None: option = "Preferences" sc = "f" else: sc = menu[0].lower() # Open the Preferences Menu based on the os with keyboard navigation if config.get_os_name() == "osx": self.shortcut(",") else: myscreen = Screen() pr = Region(myscreen.getBounds()) type(sc, KEY_ALT) reg.s.click(option) time.sleep(2)
def open_prefs(self, reg, menu=None, option=None): """OS specific handling for Preferences menu, since it differs on osx and windows. """ if reg.s.exists("icon-search.png",3) or \ reg.s.exists("icon-video.png",3): click(reg.s.getLastMatch()) time.sleep(3) if menu == None: option = 'Preferences' sc = 'f' else: sc = menu[0].lower() #Open the Preferences Menu based on the os with keyboard navigation if config.get_os_name() == "osx": self.shortcut(',') else: myscreen = Screen() pr = Region(myscreen.getBounds()) type(sc, KEY_ALT) reg.s.click(option) time.sleep(2)
def remove_confirm(self, reg, action="remove"): """If the remove confirmation is displayed, remove or cancel. action = (remove_feed, remove_item or cancel) m = Mainview region from testcase need to add remove_library option """ time.sleep(3) dialog_texts = ["Remove", "Are you", "One of", "dialog_are_you_sure.png", "dialog_one_of_these.png", "Cancel"] for txt in dialog_texts: if reg.mr.exists(txt, 2): print "got confirmation dialog" break else: print "no confirmation dialog" return dialog = Screen(0).capture(Region(reg.mr.getLastMatch())) if action == "remove": print "clicking remove button" type(Key.ENTER) elif action == "delete_item": print "clicking delete button" if config.get_os_name() == "osx": reg.t.click("button_delete_file.png") else: reg.m.click("Delete File") elif action == "cancel": print "clicking cancel" type(Key.ESC) elif action == "keep": print "keeping" reg.m.click("Keep") type(Key.ENTER) else: print "not sure what to do in this dialog" if dialog: waitVanish(dialog)
def __init__(self): self.os_name = config.get_os_name() PREF_HEADING = Pattern("pref_heading.png") def preference_panel_regions(): find(PREF_HEADING) heading = Region(getLastMatch()) gtw = heading.getW() / 10 heading.setX(heading.getX() - gtw) heading.setW(heading.getW() + gtw * 2) heading.setH(heading.getH() + 30) heading.setAutoWaitTimeout(10) settings = Region(heading.below()) settings.setAutoWaitTimeout(10) return (heading, settings) def screen_region(): myscreen = Screen() screen = Region(myscreen.getBounds()) return screen self.hr, self.sr = preference_panel_regions() self.screen = screen_region()
def open_prefs(self,reg,lang='en',menu=None,option=None): """OS specific handling for Preferences menu, since it differs on osx and windows. """ if reg.s.exists("icon-search.png",3) or \ reg.s.exists("icon-video.png",3): click(reg.s.getLastMatch()) time.sleep(3) if lang == 'en': option = 'Preferences' sc = 'f' else: sc = menu[0].lower() #Open the Preferences Menu based on the os with keyboard navigation if config.get_os_name() == "osx": mirolib.shortcut(',') pr = Region(reg.m) else: myscreen = Screen() pr = Region(myscreen.getBounds()) type(sc,KEY_ALT) reg.t.click(option) time.sleep(2) return pr
def remove_confirm(self,reg,action="remove"): """If the remove confirmation is displayed, remove or cancel. action = (remove_feed, remove_item or cancel) m = Mainview region from testcase need to add remove_library option """ time.sleep(3) if reg.m.exists("Remove",3) or \ reg.t.exists("Are you",3) or \ reg.t.exists("One of",3) or \ reg.m.exists(Pattern("dialog_are_you_sure.png"),3) or \ reg.m.exists(Pattern("dialog_one_of_these.png"),3) or \ reg.t.exists("Cancel",3)or \ reg.t.exists(Pattern("dialog_are_you_sure.png"),3) or \ reg.t.exists(Pattern("dialog_one_of_these.png"),3): print "got confirmation dialog" if action == "remove": print "clicking remove button" type(Key.ENTER) elif action == "delete_item": print "clicking delete button" if config.get_os_name() == "osx": reg.t.click("button_delete_file.png") else: reg.m.click("Delete File") elif action == "cancel": print "clicking cancel" type(Key.ESC) elif action == "keep": print "keeping" reg.m.click("Keep") type(Key.ENTER) else: print "not sure what to do in this dialog"
def close_window(self): if config.get_os_name() == "win": self.shortcut('w') else: self.shortcut('q')
def first_time_startup_dialog(self, lang="Default", run_on_start="No", search="No", search_path="Everywhere", itunes="No"): """Walk throught the first time startup dialog, specifying defaults. """ if exists(Pattern("button_System_default.png").similar(.90),45) or \ exists("System default",45) or \ exists("Language",5): print "In first time dialog" dR = Region(getLastMatch()) dR.setX(dR.getX() - 200) dR.setY(dR.getY() - 20) dR.setH(dR.getH() + 600) dR.setW(dR.getW() + 600) dR.highlight(2) dR.setAutoWaitTimeout(15) #Language Setting print "setting lang:", lang if not lang == "Default": click(getLastMatch()) for x in range(0, 3): if not exists(lang, 3): type(Key.PAGE_DOWN) for x in range(0, 4): if not exists(lang, 3): type(Key.PAGE_UP) click(lang) time.sleep(2) self.click_next(dR) #Run on Startup print "run at startup? ", run_on_start time.sleep(3) if run_on_start == "Yes": dR.click("Yes") elif run_on_start == "No": dR.click("No") else: print "pref not set" self.click_next(dR) #Add itunes library time.sleep(3) if config.get_os_name() == "osx" or \ (config.get_os_name() == "win" and dR.exists("iTunes",3)): print "itunes? ", itunes if itunes == "Yes": dR.click("Yes") else: dR.click("No") self.click_next(dR) #Search for music and video files print "search for files? ", search time.sleep(3) if search == "Yes": dR.click("Yes") print "specifying search" if search_path == "Everywhere": print "searching everywhere" self.click_next(dR) time.sleep(5) waitVanish( "parsed", 900) #this can take a long time, giving 15 mins for search else: print "searching specific dir: ", search_path dR.click("Just") dR.click(Pattern("button_choose.png")) self.type_a_path(search_path) self.click_next(dR) waitVanish("parsed", 300) time.sleep(2) self.click_finish(dR)
def first_time_startup_dialog( self, lang="Default", run_on_start="No", search="No", search_path="Everywhere", itunes="No" ): """Walk throught the first time startup dialog, specifying defaults. """ if ( exists(Pattern("button_System_default.png").similar(0.90), 45) or exists("System default", 45) or exists("Language", 5) ): print "In first time dialog" dR = Region(getLastMatch()) dR.setX(dR.getX() - 200) dR.setY(dR.getY() - 20) dR.setH(dR.getH() + 600) dR.setW(dR.getW() + 600) dR.highlight(2) dR.setAutoWaitTimeout(15) # Language Setting print "setting lang:", lang if not lang == "Default": click(getLastMatch()) for x in range(0, 3): if not exists(lang, 3): type(Key.PAGE_DOWN) for x in range(0, 4): if not exists(lang, 3): type(Key.PAGE_UP) click(lang) time.sleep(2) self.click_next(dR) # Run on Startup print "run at startup? ", run_on_start time.sleep(3) if run_on_start == "Yes": dR.click("Yes") elif run_on_start == "No": dR.click("No") else: print "pref not set" self.click_next(dR) # Add itunes library time.sleep(3) if config.get_os_name() == "osx" or (config.get_os_name() == "win" and dR.exists("iTunes", 3)): print "itunes? ", itunes if itunes == "Yes": dR.click("Yes") else: dR.click("No") self.click_next(dR) # Search for music and video files print "search for files? ", search time.sleep(3) if search == "Yes": dR.click("Yes") print "specifying search" if search_path == "Everywhere": print "searching everywhere" self.click_next(dR) time.sleep(5) waitVanish("parsed", 900) # this can take a long time, giving 15 mins for search else: print "searching specific dir: ", search_path dR.click("Just") dR.click(Pattern("button_choose.png")) self.type_a_path(search_path) self.click_next(dR) waitVanish("parsed", 300) time.sleep(2) self.click_finish(dR)