Example #1
0
def select_file_in_dialog(context, name, path):
    # click search button
    context.app.dialog.findChildren(lambda x: x.roleName == 'toggle button' and x.showing)[0].click()

    full_path = os.path.join(path, name)
    typeText(full_path)
    keyCombo('<enter>')
def show_attendee_field(context, field):
    context.app.event_editor.menu('View').click()
    menuItem = context.app.event_editor.menu('View').menuItem('%s Field' % field.capitalize())
    if not menuItem.checked:
        menuItem.click()
    else:
        keyCombo('<Esc>')
Example #3
0
    def kill(self):
        """
        Kill the app via 'killall'
        """
        try:
            # first try to quit graciously
            GnomeShell().clickApplicationMenuItem(
                self.getName(self.parseDesktopFile()), "Quit")
            assert wait_until(lambda x: not x.isRunning(), self, timeout=30)
        except (AssertionError, SearchError):
            try:
                # okay, didn't work. Kill by pid
                self.process.kill()
                assert wait_until(lambda x: not x.isRunning(),
                                  self, timeout=30)
            except:  # pylint: disable=bare-except
                # send SIGKILL if sigterm didn't work
                Popen("killall -9 " + self.appCommand + " > /dev/null",
                      shell=True).wait()
        self.pid = None

        if self.recordVideo:
            keyCombo('<Control><Alt><Shift>R')
            if self.recordVideoName is not None:
                # Rename the last screencast according to the template in
                # self.recordVideoName
                scrcast_list = sorted(glob.glob(
                    os.path.join(os.path.expanduser('~/Videos'),
                                 'Screencast*')))
                last_scrcast = scrcast_list[-1]
                curtime = datetime.datetime.now().strftime('%Y-%m-%dT%H-%M-%S')
                os.rename(last_scrcast,
                          os.path.expanduser('~/Videos/%s_%s.webm' %
                                             (self.recordVideoName, curtime)))
Example #4
0
    def __init__(self,
                 appName,
                 shortcut='<Control><Q>',
                 a11yAppName=None,
                 forceKill=True,
                 parameters='',
                 recordVideo=False):
        """
        Initialize object App
        appName     command to run the app
        shortcut    default quit shortcut
        a11yAppName app's a11y name is different than binary
        forceKill   is the app supposed to be kill before/after test?
        parameters  has the app any params needed to start? (only for startViaCommand)
        recordVideo start gnome-shell recording while running the app
        """
        self.appCommand = appName
        self.shortcut = shortcut
        self.forceKill = forceKill
        self.parameters = parameters
        self.internCommand = self.appCommand.lower()
        self.a11yAppName = a11yAppName
        self.recordVideo = recordVideo
        self.pid = None

        # a way of overcoming overview autospawn when mouse in 1,1 from start
        pressKey('Esc')
        absoluteMotion(100, 100, 2)

        # attempt to make a recording of the test
        if self.recordVideo:
            keyCombo('<Control><Alt><Shift>R')
def add_new_reminder_with_following_options(context):
    context.app.reminders.button('Add').click()
    dialog = context.app.instance.dialog('Add Reminder')

    for row in context.table:
        if row['Field'] in ['Action', 'Period', 'Before/After', 'Start/End']:
            value = row['Value']
            combo = dialog.child(value, roleName='menu item').parent.parent
            if combo.combovalue != value:
                combo.combovalue = value
        elif row['Field'] == 'Num':
            spin_button = dialog.child(roleName='spin button')
            spin_button.text = row['Value']
            spin_button.grab_focus()
            keyCombo('<Enter>')
        elif row['Field'] == 'Message':
            dialog.child('Custom message').click()
            # dialog.childLabelled('Message:').text = row['Value']
            dialog.child(roleName='text').text = row['Value']
        else:
            dialog.childLabelled(row['Field']).text = row['Value']

    dialog.button('OK').click()

    assert wait_until(lambda x: x.dead, dialog), "Add Reminder dialog was not closed"
Example #6
0
def open_file_via_menu(context, filename):
    keyCombo("<Ctrl>O")
    context.execute_steps(u"""
        * file select dialog with name "Open Image" is displayed
        * In file select dialog select "%s"
    """ % filename)
    sleep(0.5)
Example #7
0
    def closeViaShortcut(self):
        """
        Close the app via shortcut
        """
        internCritical = (self.critical == 'quit')

        if not self.isRunning():
            if internCritical:
                self.updateResult(False)
            #print "!!! The app does not seem to be running"
            return False

        keyCombo(self.shortcut)
        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
Example #8
0
def type_text_to_paragraph(context, replaced_text, replacement):
    """
    In this method we use shortcut CTRL+h to fire replace dialog window,
    then submit changes.
    """
    # fire dialog with ctrl+h
    keyCombo('<Control>h')
    dialog = context.app.get_current_window()
    # Search Field
    dialog.findChildren(lambda x: x.name == 'Search For' and x.roleName=='panel')[0].\
        child(roleName='text').typeText(replaced_text)
    dialog.findChildren(lambda x: x.roleName == 'push button' and x.name == 'Find All' and x.showing)[0].click()
    # Replace Field
    dialog.findChildren(lambda x: x.name == 'Replace With' and x.roleName=='panel')[0].\
        child(roleName='text').typeText(replacement)
    dialog.findChildren(lambda x: x.roleName == 'push button' and x.name == 'Replace All' and x.showing)[0].click()

    # this is used for wait of alert - it takes some time to render and not in all situation its gets showed instantly
    sleep(1)
    alert_dialog = context.app.get_current_window()
    click_button_in_dialog_window(context, "OK")

    assert not alert_dialog.showing, "Alert Dialog is still showing and probably also have focus"
    assert context.paragraph.text == replacement, "Incorrect text in paragraph, expected '%s' but was '%s'" % (
        replacement, context.paragraph.text)

    dialog.findChildren(lambda x: x.roleName == 'push button' and x.name == 'Close' and x.showing)[0].click()
Example #9
0
def insert_table(context):
    keyCombo('<Control><F12>')
    context.app.get_current_window().findChildren(
        lambda x: x.roleName == 'push button' and x.name == 'Insert' and x.showing)[0].click()

    assert len(context.app.get_current_window().findChildren(
        lambda x: x.showing and x.roleName == 'table')) != 0, "In paragraph should be at least one table"
def select_first_suggestion_as_field_typing_name(context, field, name):
    context.app.composer.child(field).grab_focus()
    typeText(name)
    sleep(1)
    keyCombo("<Down>")
    keyCombo("<Enter>")
    sleep(0.5)
def search_for_message(context, name):
    # Clear existing search
    for attempts in range(0, 10):
        try:
            context.search_bar.text = ''
            break
        except (GLib.GError, AttributeError):
            sleep(0.1)
            continue
    context.search_bar.grab_focus()
    context.search_bar.keyCombo('<Enter>')
    sleep(1)

    # Perform the search
    for attempts in range(0, 10):
        try:
            context.search_bar.text = name
            break
        except (GLib.GError, AttributeError):
            sleep(0.1)
            continue
    context.search_bar.grab_focus()
    sleep(0.5)
    context.search_bar.keyCombo('<Enter>')
    context.app.instance.child(name='Messages', roleName='panel').click()
    keyCombo('<Home>')
Example #12
0
    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"
Example #13
0
def quit_boxes(context):
    keyCombo('<Ctrl><Q>')
    counter = 0
    while call('pidof gnome-boxes > /dev/null', shell=True) != 1:
        sleep(0.5)
        counter += 1
        if counter == 100:
            raise Exception("Failed to turn off Boxes in 50 seconds")
Example #14
0
def select_menu_action(context, action):
    keyCombo("<Super_L><F10>")
    if action == 'About':
        pressKey('Down')
    if action == 'Quit':
        pressKey('Down')
        pressKey('Down')
    pressKey('Enter')
 def kill(self):
     """
     Kill the app via 'killall'
     """
     if self.recordVideo:
         keyCombo('<Control><Alt><Shift>R')
     print("*** Killing all '%s' instances" % self.appCommand)
     return Popen("pkill " + self.appCommand, shell=True).wait()
Example #16
0
def file_open_on_path(context, path, name):

    full_path = os.path.join(path, name)
    context.app.dialog = context.app.get_current_window()
    context.app.dialog.childLabelled('Location:').set_text_contents(full_path)
    context.app.dialog.childLabelled('Location:').grab_focus()
    keyCombo('<Enter>')
    sleep(1)
Example #17
0
def hit_keycombo(context, keycombo):
    sleep(0.2)
    if keycombo == "Enter":
        pressKey("Enter")
    else:
        keyCombo('%s'%keycombo)

    sleep(0.2)
Example #18
0
def file_save_to_path(context, path, name):

    full_path = os.path.join(path, name)
    context.app.dialog = context.app.get_current_window()
    context.app.dialog.findChildren(lambda x: x.roleName == 'text')[0].set_text_contents(full_path)
    context.app.dialog.findChildren(lambda x: x.roleName == 'text')[0].grab_focus()
    keyCombo('<Enter>')
    sleep(1)
Example #19
0
def undo_replace_text_with_shortcut(context):
    # this take context.paragraph.text which is stored on first place in type_text_to_paragraph
    # and compare if its the same with text after undo changes
    keyCombo('<Control>z')

    assert context.paragraph.text == context.original_paragraph_text, \
        "Incorrect text in paragraph, expected '%s' but was '%s'" % (
            context.original_paragraph_text, context.paragraph.text)
Example #20
0
    def closeViaShortcut(self):
        """
        Close the app via shortcut
        """
        if not self.isRunning():
            raise Exception("App is not running")

        keyCombo(self.shortcut)
        assert not self.isRunning(), "Application cannot be stopped"
Example #21
0
def insert_table(context):
    keyCombo("<Control><F12>")
    context.app.get_current_window().findChildren(
        lambda x: x.roleName == "push button" and x.name == "Insert" and x.showing
    )[0].click()

    assert (
        len(context.app.get_current_window().findChildren(lambda x: x.showing and x.roleName == "table")) != 0
    ), "In paragraph should be at least one table"
Example #22
0
def select_menu_action(context, action):
    keyCombo("<Super_L><F10>")
    gs = GnomeShell()
    buttons = gs.getApplicationMenuList()
    sleep(0.5)
    for button in buttons:
        if button.name == action:
            button.click()
            break
Example #23
0
    def closeViaShortcut(self):
        """
        Close the app via shortcut
        """
        if not self.isRunning():
            raise Exception("App is not running")

        keyCombo(self.shortcut)
        assert wait_until(lambda x: not x.isRunning(), self, timeout=30),\
            "Application cannot be stopped"
def delete_all_emails_with_in_folder(context, subject, name):
    context.execute_steps(u'* Open "%s" folder' % name)
    search_for_message(context, subject)
    keyCombo('<Ctrl>A')
    context.app.instance.menu('Edit').click()
    mnu = context.app.instance.menu('Edit').menuItem('Delete Message')
    if pyatspi.STATE_ENABLED in mnu.getState().getStates():
        mnu.click()
    else:
        context.app.instance.menu('Edit').click()
Example #25
0
def select_file_in_dialog(context, name):
    location_button = context.app.dialog.child('Enter Location')
    if pyatspi.STATE_ARMED not in location_button.getState().getStates():
        location_button.click()

    location_text = context.app.dialog.child(roleName='text')
    location_text.set_text_contents(name)
    doDelay(0.2)
    location_text.grab_focus()
    keyCombo('<Enter>')
Example #26
0
def rename_vm(context, machine, name, way):
    if way == 'button':
        context.app.child(machine, roleName='push button').click()
        sleep(0.5)
    if way == 'label':
        context.app.child('General').child('Name').parent.child(roleName='text').click()
        keyCombo('<Ctrl><a>')
    typeText(name)
    pressKey('Enter')
    sleep(0.5)
def select_first_suggestion_as_attendee(context, name):
    context.app.event_editor.button('Add').click()
    typeText(name)
    sleep(1)

    # Again, cell renderer is not avaiable here
    keyCombo("<Down>")
    keyCombo("<Enter>")

    sleep(0.5)
Example #28
0
def rename_vm(context, machine, name, way):
    if way == 'button':
        context.app.child(machine, roleName='push button').click()
    if way == 'label':
        context.app.child('General').child('Name').parent.child(roleName='text').click()
        keyCombo('<Ctrl><a>')
    context.execute_steps(u"""
        * Type text "%s" and return
        """ % name )
    sleep(0.5)
Example #29
0
    def startViaCommand(self):
        """
        Start the app via command
        """
        internCritical = (self.critical == 'start')
        if self.forceKill and self.isRunning():
            self.kill()
            sleep(2)
            if self.isRunning():
                if internCritical:
                    self.updateResult(False)
                #print "!!! The app is running but it shouldn't be"
                return False
            else:
                pass
                #print "*** The app has been killed succesfully"

        returnValue = 0
        command = "%s %s &" % (self.appCommand, self.parameters)
        import os
        os.system(command)
        returnValue = 1
        #returnValue = utilsRun(command, timeout = 1, dumb = True)

        #if there is a polkit
        if self.polkit:
            sleep(3)
            typeText(self.polkitPass)
            keyCombo('<Enter>')

        start_time = 0
        while start_time < self.timeout:
            if self.isRunning():
                break
            sleep(0.5)
            start_time += 0.5

        #check the returned values
        if returnValue is None:
            if internCritical:
                self.updateResult(False)
            #print "!!! The app command could not be found"
            return False
        else:
            if self.isRunning():
                if internCritical:
                    self.updateResult(True)
                #print "*** The app started successfully"
                return True
            else:
                if internCritical:
                    self.updateResult(False)
                    #print "!!! The app did not started despite " \
                    #        + "the fact that the command was found"
                return False
def mail_viewer_has_attachment_named(context, name, filename):
    keyCombo('<Alt>a')

    context.execute_steps(u"""
        * file select dialog with name "Save Attachment" is displayed
        * in file save dialog save file to "%s" clicking "Save"
    """ % filename)
        # Handle replace dialog
    alert = context.app.instance.findChild(GenericPredicate(roleName='alert', name='Question'), retry=False, requireResult=False)
    if alert:
        alert.button("Replace").click()