def isRunning(self): """ Is the app running? """ if self.a11yAppName is None: self.a11yAppName = self.internCommand try: if self.a11yAppName in [x.name for x in root.applications()]: return True except: sleep(10) if self.a11yAppName in [x.name for x in root.applications()]: return True return False
def close_appointments_window(context): if filter(lambda x: x.name == 'evolution-alarm-notify', root.applications()): alarm_notify = root.application('evolution-alarm-notify') dialog = alarm_notify.findChild( GenericPredicate(name='Appointments'), retry=False, requireResult=False) if dialog: dialog.button('Dismiss All').click() assert wait_until(lambda x: x.dead and not x.showing, dialog),\ "Appointments window didn't disappear"
def generate_steps(self, scenario, test): self.steps = [] # Starting with an empty list for every test # parent condition exlude the root node automatically] self.app.cleanup() self.app.start() # only one runtime controller for now test_nodes = [x for x in test if x.roleName not in WINDOW_ROLENAMES] for node in test_nodes: apps_before = root.applications() app_before = self.get_app_nodes() if node == test_nodes[-1]: self.handle_last_node(node) self.execute_action(node) # after action state check # app is running but windows have changed if not self.app.is_running(): self.add_step('ASSERT_QUIT') break window = self.app.get_current_window() # acessibility bug in libreoffice if window and 'Calc' in window.name \ and not self.app.instance.isChild( self.app.main_window_name, recursive=False): self.add_step('ASSERT_WINDOW_SHOWN', window) self.generate_ocr_check(window) elif not self.app.instance.isChild(self.app.main_window_name): # app is running but windows have changed self.add_step('ASSERT_WINDOW_SHOWN', window) self.generate_ocr_check(window) else: apps = list( set(apps_before).symmetric_difference(root.applications())) if apps: self.handle_new_apps(apps) else: try: self.handle_new_nodes(app_before, test) except Exception as e: print(f'Failed to handle new nodes {e}') self.check_errors()
def evo_account_assistant_receiving_email_dialog_from_table( context, sending_or_receiving): window = context.app.child(roleName='frame') for row in context.table: label = str(row['Field']) value = str(row['Value']) filler = window.child(roleName='filler', name='%s Email' % sending_or_receiving) widgets = filler.findChildren(lambda x: x.showing) visible_widgets = [ x for x in widgets if x.labeller and x.labeller.name == label ] if len(visible_widgets) == 0: raise RuntimeError("Cannot find visible widget labelled '%s'" % label) widget = visible_widgets[0] if widget.roleName == 'combo box': if label != 'Port:': widget.click() widget.menuItem(value).click() else: # Port is a combobox, but you can type your port there widget.textentry('').text = value widget.textentry('').grab_focus() widget.textentry('').keyCombo("<Enter>") if widget.roleName == 'text': widget.text = value # Check for password here and accept self-generated certificate (if appears) btns = window.findChildren(lambda x: x.name == 'Check for Supported Types') visible_btns = [w for w in btns if w.showing] if visible_btns == []: click_next(window) return visible_btns[0].click() # Confirm all certificates by clicking 'Accept Permanently' until dialog is visible apps = [x.name for x in root.applications()] if 'evolution-user-prompter' in apps: prompter = root.application('evolution-user-prompter') dialog = prompter.child(roleName='dialog') while dialog.showing: if prompter.findChild(lambda x: x.name == 'Accept Permanently', retry=False, requireResult=False): prompter.button('Accept Permanently').click() else: sleep(0.1) # Wait until Cancel button disappears cancel = filler.findChildren(lambda x: x.name == 'Cancel')[0] while cancel.showing: sleep(0.1) check_for_errors(context) click_next(window)
def handle_authentication_window(context, password='******'): # Get a list of applications app_names = [] for attempt in range(0, 15): try: app_names = map(lambda x: x.name, root.applications()) break except GLib.GError: sleep(1) continue if 'gcr-prompter' in app_names: # Non gnome shell stuf passprompt = root.application('gcr-prompter') continue_button = passprompt.findChild( GenericPredicate(name='Continue'), retry=False, requireResult=False) if continue_button: passprompt.findChildren( GenericPredicate(roleName='password text'))[-1].grab_focus() sleep(0.5) typeText(password) # Don't save passwords to keyring keyCombo('<Tab>') # Click Continue keyCombo('<Tab>') keyCombo('<Tab>') keyCombo('<Enter>') elif 'gnome-shell' in app_names: shell = root.application('gnome-shell') # if wait_until(lambda x: x.findChildren( # lambda x: x.roleName == 'password text' and x.showing) != [], shell): # pswrd = shell.child(roleName='password text') # pswrd.text = password # st = shell.child('Add this password to your keyring') # if not st.parent.parent.checked: # st.click() # continue_button = shell.button('Continue') # shell.button('Continue').click() # sleep(3) if wait_until( lambda x: x.findChildren(lambda x: x.roleName == 'password text' and x.showing) != [], shell): st = shell.child('Add this password to your keyring') if not st.parent.parent.checked: st.click() pswrd = shell.child(roleName='password text') pswrd.click() typeText(password) keyCombo('<Enter>') wait_until(st.dead) sleep(1)
def evo_account_assistant_receiving_email_dialog_from_table(context, sending_or_receiving): window = context.app.instance.child('Evolution Account Assistant') for row in context.table: label = str(row['Field']) value = str(row['Value']) filler = window.child(roleName='filler', name='%s Email' % sending_or_receiving) widgets = filler.findChildren(GenericPredicate(label=label)) visible_widgets = [w for w in widgets if w.showing] if len(visible_widgets) == 0: raise RuntimeError("Cannot find visible widget labelled '%s'" % label) widget = visible_widgets[0] if widget.roleName == 'combo box': if label != 'Port:': widget.click() widget.menuItem(value).click() else: # Port is a combobox, but you can type your port there widget.textentry('').text = value widget.textentry('').grab_focus() widget.textentry('').keyCombo("<Enter>") if widget.roleName == 'text': widget.text = value # Check for password here and accept self-generated certificate (if appears) btns = window.findChildren(GenericPredicate(name='Check for Supported Types')) visible_btns = [w for w in btns if w.showing] if visible_btns == []: click_continue(window) return visible_btns[0].click() # Confirm all certificates by clicking 'Accept Permanently' until dialog is visible apps = [x.name for x in root.applications()] if 'evolution-user-prompter' in apps: prompter = root.application('evolution-user-prompter') dialog = prompter.findChild(GenericPredicate(roleName='dialog')) while dialog.showing: if prompter.findChild( GenericPredicate(name='Accept Permanently'), retry=False, requireResult=False): prompter.button('Accept Permanently').click() else: sleep(0.1) # Wait until Cancel button disappears cancel = filler.findChildren(GenericPredicate(name='Cancel'))[0] while cancel.showing: sleep(0.1) check_for_errors(context) click_continue(window)
def isRunning(self): """ Is the app running? """ if self.a11yAppName is None: self.a11yAppName = self.internCommand # Trap weird bus errors for attempt in xrange(0, 10): try: return self.a11yAppName in [x.name for x in root.applications()] except GLib.GError: continue raise Exception("10 at-spi errors, seems that bus is blocked")
def handle_authentication_window(context, password='******'): # Get a list of applications app_names = [] for attempt in range(0, 15): try: app_names = map(lambda x: x.name, root.applications()) break except GLib.GError: sleep(1) continue if 'gcr-prompter' in app_names: # Non gnome shell stuf passprompt = root.application('gcr-prompter') continue_button = passprompt.findChild( GenericPredicate(name='Continue'), retry=False, requireResult=False) if continue_button: passprompt.findChildren(GenericPredicate(roleName='password text'))[-1].grab_focus() sleep(0.5) typeText(password) # Don't save passwords to keyring keyCombo('<Tab>') # Click Continue keyCombo('<Tab>') keyCombo('<Tab>') keyCombo('<Enter>') elif 'gnome-shell' in app_names: shell = root.application('gnome-shell') # if wait_until(lambda x: x.findChildren( # lambda x: x.roleName == 'password text' and x.showing) != [], shell): # pswrd = shell.child(roleName='password text') # pswrd.text = password # st = shell.child('Add this password to your keyring') # if not st.parent.parent.checked: # st.click() # continue_button = shell.button('Continue') # shell.button('Continue').click() # sleep(3) if wait_until(lambda x: x.findChildren( lambda x: x.roleName == 'password text' and x.showing) != [], shell): st = shell.child('Add this password to your keyring') if not st.parent.parent.checked: st.click() pswrd = shell.child(roleName='password text') pswrd.click() typeText(password) keyCombo('<Enter>') wait_until(st.dead) sleep(1)
def isRunning(self): """ Is the app running? """ if self.a11yAppName is None: self.a11yAppName = self.internCommand # Trap weird bus errors for i in xrange(0, 10): try: return self.a11yAppName in \ [x.name for x in root.applications()] except Exception as e: print("isRunning: got exception %s" % str(e)) sleep(1) continue raise Exception("10 at-spi errors, seems that bus is blocked")
def getMenuNth(self, nth): """ Return nth submenu """ #bind to the right app app = root apps = root.applications() for i in apps: if i.name.lower() == self.internCommand: app = i break #try to bind the menu and the button try: appMenu = app.child(roleName='menu bar') return appMenu.children[nth] except: return None
def getMenuNamed(self, menuName): """ Return submenu with name specified with 'menuName' """ #bind to the right app app = root apps = root.applications() for i in apps: if i.name.lower() == self.internCommand: app = i break #try to bind the menu and the button try: appMenu = app.child(roleName='menu bar') return appMenu.child(name=menuName) except: return None
def getApp(): try: #from dogtail.tree import root apps = root.applications() except: traceback.print_exc(file=sys.stdout) time.sleep(4) #from dogtail.tree import root try: app = root.application(self.a11yAppName) return app except SearchError: return None for i in apps: if i.name.lower() == self.a11yAppName: return i return None
def isRunning(self): """ Is the app running? """ #print "*** Checking if '%s' is running" % self.internCommand app = root apps = root.applications() for i in apps: if i.name.lower() == self.internCommand: app = i break if app.isChild(roleName='frame', recursive=False): #print "*** The app '%s' is running" % self.internCommand return True else: #print "*** The app '%s' is not running" % self.internCommand return False
def closeViaMenu(self): """ Close app via menu button """ internCritical = (self.critical == 'quit') if not self.isRunning(): if internCritical: self.updateResult(False) #print "!!! The app does not seem to be running" return False #bind to the right app app = root apps = root.applications() for i in apps: if i.name.lower() == self.internCommand: app = i break app = app # variable app is not used FIXME #try to bind the menu and the button try: firstSubmenu = self.getMenuNth(0) firstSubmenu.click() length = len(firstSubmenu.children) closeButton = firstSubmenu.children[length - 1] if self.quitButton is None: while re.search('(Close|Quit|Exit)', closeButton.name) is None: length = length - 1 closeButton = firstSubmenu.children[length] if length < 0: if internCritical: self.update(False) #print "!!! The app quit button coldn't be found" return False else: closeButton = firstSubmenu.child(self.quitButton) except SearchError: if internCritical: self.updateResult(False) #print "!!! The app menu bar or the quit button could'n be found" if self.forceKill: self.kill() return False sleep(2) # timeout until menu appear #print "*** Trying to click to '%s'" % closeButton closeButton.click() sleep(self.timeout) if self.isRunning(): if self.forceKill: self.kill() if internCritical: self.updateResult(False) #print "!!! The app is running but it shouldn't be" return False else: if self.existsCoreDump() != 0: if internCritical: self.updateResult(False) # print "!! The app closed with core dump created. Signal %d" \ # % self.existsCoreDump() return False if internCritical: self.updateResult(True) #print "*** The app was successfully closed" return True
def app_is_not_present_in_process_list(context, app): try: app_names = map(lambda x: x.name, root.applications()) assert app not in app_names finally: os.system("killall %s" % app)