def fill_in_credentials(context, cfg): user = cfg['id'] pswd = cfg['password'] acc_name = cfg['name'] if acc_name == 'Google': add_google_account(context, user, pswd) if acc_name == 'Owncloud': dialog = get_showing_node_name('ownCloud account', context.app.instance, 'dialog') dialog.childLabelled('Server').text = cfg['server'] dialog.childLabelled('Username').text = user dialog.childLabelled('Password').text = pswd dialog.button('Connect').click() assert wait_until(lambda x: x.dead, dialog), \ "Dialog was not closed" if 'Exchange' in acc_name: dialog = get_showing_node_name('Microsoft Exchange account', context.app.instance, 'dialog') dialog.childLabelled("E-mail").text = '%s' % cfg['email'] dialog.childLabelled("Password").text = 'RedHat1!' get_showing_node_name('Custom', dialog).click() dialog.childLabelled("Server").text = cfg['server'] get_showing_node_name('Connect', dialog).click() get_showing_node_name('Error connecting to Microsoft Exchange server:\nThe signing certificate authority is not known.', dialog) sleep(0.5) get_showing_node_name('Ignore', dialog).click() assert wait_until(lambda x: x.dead, dialog), \ "Dialog was not closed" if acc_name == 'Facebook': add_facebook_account(context, user, pswd) if acc_name == 'Windows Live': add_windows_live_account(context, user, pswd)
def startViaMenu(self, throughCategories=False): # pylint: disable=W0613 """ Start the app via Gnome Shell menu """ desktopConfig = self.parseDesktopFile() if self.forceKill and self.isRunning(): self.kill() assert wait_until(lambda x: not x.isRunning(), self, timeout=30),\ "Application cannot be stopped" # panel button Activities gnomeShell = root.application('gnome-shell') os.system("dbus-send --session --type=method_call " + "--dest='org.gnome.Shell' " + "'/org/gnome/Shell' " + "org.gnome.Shell.FocusSearch") textEntry = gnomeShell.textentry('') assert wait_until(lambda x: x.showing, textEntry), \ "Can't find gnome shell search textbar" typeText(self.desktopFileName) keyCombo('<Enter>') assert wait_until(lambda x: x.isRunning(), self, timeout=30),\ "Application failed to start"
def open_section_by_name(context, section_name): wait_until(lambda x: x.showing, context.app.menu("View")) sleep(0.2) context.app.menu("View").click() context.app.menu("View").menu("Window").point() context.app.menu("View").menu("Window").menuItem(section_name).click() # Find a search bar context.app.search_bar = get_visible_searchbar(context) # Check that service required for this sections is running required_services = { "Mail": "org.gnome.evolution.dataserver.Sources", "Calendar": "org.gnome.evolution.dataserver.Calendar", "Tasks": "org.gnome.evolution.dataserver.Calendar", "Memos": "org.gnome.evolution.dataserver.Calendar", "Contacts": "org.gnome.evolution.dataserver.AddressBook", } required_service = required_services[section_name] bus = Gio.bus_get_sync(Gio.BusType.SESSION, None) dbus_proxy = Gio.DBusProxy.new_sync( bus, Gio.DBusProxyFlags.NONE, None, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", None, ) for attempt in xrange(0, 10): result = dbus_proxy.call_sync("ListNames", None, Gio.DBusCallFlags.NO_AUTO_START, 500, None) sleep(1) if True in [required_service in x for x in result[0]]: return raise RuntimeError("%s service was not found" % required_service)
def save_contact(context): context.app.contact_editor.button('Save').click() assert wait_until(lambda x: not x.showing, context.app.contact_editor),\ "Contact Editor was not hidden" assert wait_until(lambda x: x.dead, context.app.contact_editor),\ "Contact Editor was not closed" context.app.contact_editor = None
def open_section_by_name(context, section_name): wait_until(lambda x: x.showing, context.app.menu('View')) sleep(0.2) context.app.menu('View').click() context.app.menu('View').menu('Window').point() context.app.menu('View').menu('Window').menuItem(section_name).click() # Find a search bar context.app.search_bar = get_visible_searchbar(context) # Check that service required for this sections is running required_services = { 'Mail': 'org.gnome.evolution.dataserver.Sources', 'Calendar': 'org.gnome.evolution.dataserver.Calendar', 'Tasks': 'org.gnome.evolution.dataserver.Calendar', 'Memos': 'org.gnome.evolution.dataserver.Calendar', 'Contacts': 'org.gnome.evolution.dataserver.AddressBook', } required_service = required_services[section_name] bus = Gio.bus_get_sync(Gio.BusType.SESSION, None) dbus_proxy = Gio.DBusProxy.new_sync(bus, Gio.DBusProxyFlags.NONE, None, 'org.freedesktop.DBus', '/org/freedesktop/DBus', 'org.freedesktop.DBus', None) for attempt in xrange(0, 10): result = dbus_proxy.call_sync( 'ListNames', None, Gio.DBusCallFlags.NO_AUTO_START, 500, None) sleep(1) if True in [required_service in x for x in result[0]]: return raise RuntimeError("%s service was not found" % required_service)
def help_is_displayed(context, name): try: context.yelp = root.application('yelp') frame = context.yelp.child(roleName='frame') wait_until(lambda x: x.showing, frame) sleep(1) context.assertion.assertEquals(name, frame.name) finally: system("killall yelp")
def help_is_displayed(context, name): try: context.yelp = root.application("yelp") frame = context.yelp.child(roleName="frame") wait_until(lambda x: x.showing, frame) sleep(1) context.assertion.assertEquals(name, frame.name) finally: system("killall yelp")
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 select_contact_with_name(context, contact_name): # heading shows the name of currently selected contact # We have to keep on pressing Tab to select the next contact # Until we meet the first contact # WARNING - what if we will have two identical contacts? fail = False selected_contact = None # HACK # To make the contact table appear # we need to focus on search window # and send Tabs to have the first contact focused context.app.search_bar.grab_focus() sleep(0.1) # Switch to 'Any field contains' (not reachable in 3.6) icons = context.app.search_bar.findChildren(GenericPredicate(roleName='icon')) if icons != []: icons[0].click() wait_until(lambda x: x.findChildren( GenericPredicate(roleName='check menu item', name='Any field contains')) != [], context.app) context.app.menuItem('Any field contains').click() for attempts in range(0, 10): try: context.app.search_bar.text = contact_name break except (GLib.GError, AttributeError): sleep(0.1) continue keyCombo("<Enter>") context.app.search_bar.grab_focus() keyCombo("<Tab>") first_contact_name = context.app.child(roleName='heading').text while True: selected_contact = context.app.child(roleName='heading') if selected_contact.text == contact_name: fail = False break keyCombo("<Tab>") # Wait until contact data is being rendered sleep(1) if first_contact_name == selected_contact.text: fail = True break context.assertion.assertFalse( fail, "Can't find contact named '%s'" % contact_name) context.selected_contact_text = selected_contact.text
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 add_facebook_account(context, user, password): dialog = context.app.instance.dialog('Facebook account') # Input credentials assert wait_until(lambda x: x.findChildren( GenericPredicate(roleName='entry')) != [], dialog, timeout=90), \ "Facebook auth window didn't appear" entry = dialog.child(roleName='entry') if entry.text != user: entry.text = user dialog.child(roleName='password text').text = password doDelay(1) dialog.child(roleName='password text').grabFocus() pressKey('Enter') assert wait_until(lambda x: x.dead, dialog), \ "Dialog was not closed"
def get_visible_searchbar(context): """Wait for searchbar to become visible""" def get_searchbars(): return context.app.findChildren(lambda x: x.labeller.name == "Search:" and x.showing) assert wait_until(lambda x: len(x()) > 0, get_searchbars), "No visible searchbars found" return get_searchbars()[0]
def add_windows_live_account(context, user, password): dialog = context.app.instance.dialog('Windows Live account') # Input credentials # assert wait_until( # lambda x: x.findChildren( # GenericPredicate(roleName='entry')) != [], dialog, # timeout=90), "Windows Live auth window didn't appear" entry = dialog.child(roleName='entry', description="Email or phone") if entry.text != user: entry.click() typeText(user) pressKey('Tab') typeText(password) doDelay(2) dialog.button('Sign in').click() doDelay(5) # Wait for GNOME icon to appear third_party_icon_pred = GenericPredicate(roleName='document web', name='Let this app access your info?') for attempts in range(0, 10): # pylint: disable=W0612 if dialog.findChild(third_party_icon_pred, retry=False, requireResult=False) is not None: break else: doDelay(2) doDelay(1) allow_button = dialog.child("Yes", roleName='push button') if not allow_button.showing: # Scroll to confirmation button scrolls = dialog.findChildren( GenericPredicate(roleName='scroll bar')) scrolls[-1].value = scrolls[-1].maxValue pressKey('space') pressKey('space') # Wait for button to become enabled for attempts in range(0, 10): if pyatspi.STATE_SENSITIVE in \ allow_button.getState().getStates(): break else: doDelay(1) allow_button.click() assert wait_until(lambda x: x.dead, dialog), \ "Dialog was not closed"
def add_windows_live_account(context, user, password): dialog = context.app.instance.dialog('Windows Live account') # Input credentials # assert wait_until( # lambda x: x.findChildren( # GenericPredicate(roleName='entry')) != [], dialog, # timeout=90), "Windows Live auth window didn't appear" entry = dialog.child(roleName='entry', description="Email or phone") if entry.text != user: entry.click() typeText(user) pressKey('Tab') typeText(password) doDelay(2) dialog.button('Sign in').click() doDelay(5) # Wait for GNOME icon to appear third_party_icon_pred = GenericPredicate( roleName='document web', name='Let this app access your info?') for attempts in range(0, 10): # pylint: disable=W0612 if dialog.findChild(third_party_icon_pred, retry=False, requireResult=False) is not None: break else: doDelay(2) doDelay(1) allow_button = dialog.child("Yes", roleName='push button') if not allow_button.showing: # Scroll to confirmation button scrolls = dialog.findChildren(GenericPredicate(roleName='scroll bar')) scrolls[-1].value = scrolls[-1].maxValue pressKey('space') pressKey('space') # Wait for button to become enabled for attempts in range(0, 10): if pyatspi.STATE_SENSITIVE in \ allow_button.getState().getStates(): break else: doDelay(1) allow_button.click() assert wait_until(lambda x: x.dead, dialog), \ "Dialog was not closed"
def add_google_account(context, user, password): dialog = get_showing_node_name('Google account', context.app.instance) #idialog = context.app.instance.dialog('Google account') # Input credentials entry = get_showing_node_name('Enter your email', dialog) if entry.text != user: entry.click() typeText(user) if dialog.findChildren(lambda x: x.roleName == 'password text') == []: dialog.child('Next').click() get_showing_node_name('Password', dialog).click() typeText(password) keyCombo('<Enter>') #get_showing_node_name('Sign in', dialog).click() # Wait for Allow to appear third_party_icon_pred = GenericPredicate(roleName='push button', name='Allow') for attempts in range(0, 40): # pylint: disable=W0612 if dialog.findChild(third_party_icon_pred, retry=False, requireResult=False) is not None: break else: doDelay(0.5) allow_button = dialog.child("Allow", roleName='push button') if not allow_button.showing: # Scroll to confirmation button scrolls = dialog.findChildren( GenericPredicate(roleName='scroll bar')) scrolls[-1].value = scrolls[-1].maxValue pressKey('space') pressKey('space') # Wait for button to become enabled for attempts in range(0, 10): if pyatspi.STATE_SENSITIVE in \ allow_button.getState().getStates(): break else: doDelay(0.5) sleep(1) allow_button.click() assert wait_until(lambda x: x.dead, dialog), \ "Dialog was not closed"
def fill_in_credentials(context, cfg): user = cfg['id'] pswd = cfg['password'] acc_name = cfg['name'] if acc_name == 'Google': add_google_account(context, user, pswd) if acc_name == 'Owncloud': dialog = get_showing_node_name('ownCloud account', context.app.instance, 'dialog') dialog.childLabelled('Server').text = cfg['server'] dialog.childLabelled('Username').text = user dialog.childLabelled('Password').text = pswd dialog.button('Connect').click() assert wait_until(lambda x: x.dead, dialog), \ "Dialog was not closed" if 'Exchange' in acc_name: dialog = get_showing_node_name('Microsoft Exchange account', context.app.instance, 'dialog') dialog.childLabelled("E-mail").text = '%s' % cfg['email'] dialog.childLabelled("Password").text = 'RedHat1!' get_showing_node_name('Custom', dialog).click() dialog.childLabelled("Server").text = cfg['server'] get_showing_node_name('Connect', dialog).click() get_showing_node_name( 'Error connecting to Microsoft Exchange server:\nThe signing certificate authority is not known.', dialog) sleep(0.5) get_showing_node_name('Ignore', dialog).click() assert wait_until(lambda x: x.dead, dialog), \ "Dialog was not closed" if acc_name == 'Facebook': add_facebook_account(context, user, pswd) if acc_name == 'Windows Live': add_windows_live_account(context, user, pswd)
def add_google_account(context, user, password): dialog = get_showing_node_name('Google account', context.app.instance) #idialog = context.app.instance.dialog('Google account') # Input credentials entry = get_showing_node_name('Enter your email', dialog) if entry.text != user: entry.click() typeText(user) if dialog.findChildren(lambda x: x.roleName == 'password text') == []: dialog.child('Next').click() get_showing_node_name('Password', dialog).click() typeText(password) keyCombo('<Enter>') #get_showing_node_name('Sign in', dialog).click() # Wait for Allow to appear third_party_icon_pred = GenericPredicate(roleName='push button', name='Allow') for attempts in range(0, 40): # pylint: disable=W0612 if dialog.findChild(third_party_icon_pred, retry=False, requireResult=False) is not None: break else: doDelay(0.5) allow_button = dialog.child("Allow", roleName='push button') if not allow_button.showing: # Scroll to confirmation button scrolls = dialog.findChildren(GenericPredicate(roleName='scroll bar')) scrolls[-1].value = scrolls[-1].maxValue pressKey('space') pressKey('space') # Wait for button to become enabled for attempts in range(0, 10): if pyatspi.STATE_SENSITIVE in \ allow_button.getState().getStates(): break else: doDelay(0.5) sleep(1) allow_button.click() assert wait_until(lambda x: x.dead, dialog), \ "Dialog was not closed"
def kill(self): """ Kill the app via 'killall' """ if self.recordVideo: keyCombo('<Control><Alt><Shift>R') try: # Kill by pid kill(self.pid, SIGTERM) assert wait_until(lambda x: not x.isRunning(), self, timeout=10) except: # send SIGKILL if sigterm didn't work Popen("killall -9 " + self.processName + " > /dev/null", shell=True).wait() self.pid = None
def help_is_displayed(context, name): context.yelp = root.application('yelp') frame = context.yelp.child(roleName='frame') wait_until(lambda x: x.showing, frame) sleep(1) context.assertion.assertEquals(name, frame.name)
def evolution_is_closed(context): assert wait_until(lambda x: x.dead, context.app), "Evolution window is opened" context.assertion.assertFalse(context.app_class.isRunning(), "Evolution is in the process list")
def initial_page_loaded(context): wait_until(lambda x: x.name != 'New', context.app)
def evolution_is_closed(context): assert wait_until(lambda x: x.dead, context.app),\ "Evolution window is opened" context.assertion.assertFalse(context.app_class.isRunning(), "Evolution is in the process list")
def get_visible_searchbar(context): """Wait for searchbar to become visible""" def get_searchbars(): return context.app.findChildren(lambda x: x.labeller.name == 'Search:' and x.showing) assert wait_until(lambda x: len(x()) > 0, get_searchbars), "No visible searchbars found" return get_searchbars()[0]