Beispiel #1
0
def restore_firefox_focus():
    """Restore Firefox focus by clicking the panel near HOME or REFRESH button."""

    try:
        if exists(NavBar.HOME_BUTTON, Settings.DEFAULT_UI_DELAY):
            target_pattern = NavBar.HOME_BUTTON
        else:
            target_pattern = NavBar.RELOAD_BUTTON
        w, h = target_pattern.get_size()
        horizontal_offset = w * 1.7
        click_area = target_pattern.target_offset(horizontal_offset, 0)
        click(click_area)
    except FindError:
        raise APIHelperError('Could not restore firefox focus.')
Beispiel #2
0
def minimize_window_control(window_type):
    """Click on minimize window control.

    :param window_type: Type of window that need to be minimized.
    :return: None.
    """
    find_window_controls(window_type)

    if window_type == 'auxiliary':
        if OSHelper.is_mac():
            width, height = AuxiliaryWindow.AUXILIARY_WINDOW_CONTROLS.get_size(
            )
            click(AuxiliaryWindow.AUXILIARY_WINDOW_CONTROLS.target_offset(
                width / 2, height / 2),
                  align=Alignment.TOP_LEFT)
        else:
            click(AuxiliaryWindow.MINIMIZE_BUTTON)
    else:
        if OSHelper.is_mac():
            width, height = MainWindow.MAIN_WINDOW_CONTROLS.get_size()
            click(MainWindow.MAIN_WINDOW_CONTROLS.target_offset(
                width / 2, height / 2),
                  align=Alignment.TOP_LEFT)
        else:
            click(MainWindow.MINIMIZE_BUTTON)
Beispiel #3
0
def restore_window_control(window_type):
    """Click on restore window control.

    :param window_type: Type of window that need to be restored.
    :return: None.
    """
    find_window_controls(window_type)

    if window_type == 'auxiliary':
        if OSHelper.is_mac():
            key_down(Key.ALT)
            width, height = AuxiliaryWindow.AUXILIARY_WINDOW_CONTROLS.get_size(
            )
            click(AuxiliaryWindow.AUXILIARY_WINDOW_CONTROLS.target_offset(
                width - 10, height / 2),
                  align=Alignment.TOP_LEFT)
            key_up(Key.ALT)
        else:
            if OSHelper.is_linux():
                reset_mouse()
            click(AuxiliaryWindow.ZOOM_RESTORE_BUTTON)
    else:
        if OSHelper.is_mac():
            key_down(Key.ALT)
            width, height = MainWindow.MAIN_WINDOW_CONTROLS.get_size()
            click(MainWindow.MAIN_WINDOW_CONTROLS.target_offset(
                width - 10, height / 2),
                  align=Alignment.TOP_LEFT)
            key_up(Key.ALT)
        else:
            if OSHelper.is_linux():
                reset_mouse()
            click(MainWindow.RESIZE_BUTTON)
Beispiel #4
0
def open_zoom_menu():
    """Open the 'Zoom' menu from the 'View' menu."""

    if OSHelper.is_mac():
        view_menu_pattern = Pattern('view_menu.png')

        click(view_menu_pattern)

        repeat_key_down(3)
        type(text=Key.ENTER)
    else:
        type(text='v', modifier=KeyModifier.ALT)

        repeat_key_down(2)
        type(text=Key.ENTER)
def select_throttling(option):
    open_web_console()

    try:
        wait(Pattern('network.png'), 10)
        click(Pattern('network.png'))
    except FindError:
        raise APIHelperError('Can\'t find the network menu in the page, aborting test.')

    try:
        wait(Pattern('no_throttling.png'), 10)
        click(Pattern('no_throttling.png'))
    except FindError:
        raise APIHelperError('Can\'t find the throttling menu in the page, aborting test.')

    for i in range(option + 1):
        type(Key.DOWN)
    type(Key.ENTER)
Beispiel #6
0
    def click(self, ps=None, duration=None, align=None):
        """Mouse left click.

        :param ps: Pattern or String.
        :param duration: Speed of hovering from current location to target.
        :param align: Click location alignment could be top_left, center, top_right, bottom_left, bottom_right.
        :return: None.
        """
        return click(ps, duration, self._area, align)
Beispiel #7
0
def open_bookmarks_toolbar():
    """ Open the Bookmarks Toolbar using the context menu from the navigation bar """

    home_button = NavBar.HOME_BUTTON
    w, h = home_button.get_size()
    horizontal_offset = w * 1.7
    navbar_context_menu = home_button.target_offset(horizontal_offset, 0)

    try:
        right_click(navbar_context_menu)
        click(NavBar.ContextMenu.BOOKMARKS_TOOLBAR)
        logger.debug(
            'Click is performed successfully on Bookmarks Toolbar option from navigation bar context menu.'
        )
    except FindError:
        raise APIHelperError(
            'Could not open the Bookmarks Toolbar using context menu from the navigation bar.'
        )

    restore_firefox_focus()
Beispiel #8
0
def get_support_info():
    """Returns support information as a JSON object from 'about:support' page."""
    copy_raw_data_to_clipboard = Pattern(
        'about_support_copy_raw_data_button.png')

    new_tab()
    select_location_bar()
    paste('about:support')
    type(Key.ENTER)
    time.sleep(Settings.DEFAULT_UI_DELAY)

    try:
        click(copy_raw_data_to_clipboard)
        time.sleep(Settings.DEFAULT_UI_DELAY_LONG)
        json_text = get_clipboard()
        return json.loads(json_text)
    except Exception as e:
        raise APIHelperError(
            'Failed to retrieve support information value.\n{}'.format(e))
    finally:
        close_tab()
Beispiel #9
0
def full_screen_control(window_type):
    """Click on full screen window mode (Applicable only for MAC system).

    :param window_type: Type of window that need to be maximized in full screen mode.
    :reurn: None.
    """
    if OSHelper.is_mac():
        find_window_controls(window_type)

        if window_type == 'auxiliary':
            width, height = AuxiliaryWindow.AUXILIARY_WINDOW_CONTROLS.get_size(
            )
            click(AuxiliaryWindow.AUXILIARY_WINDOW_CONTROLS.target_offset(
                width - 10, height / 2),
                  align=Alignment.TOP_LEFT)
        else:
            width, height = MainWindow.MAIN_WINDOW_CONTROLS.get_size()
            click(MainWindow.MAIN_WINDOW_CONTROLS.target_offset(
                width - 10, height / 2),
                  align=Alignment.TOP_LEFT)
    else:
        raise APIHelperError('Full screen mode applicable only for MAC')
Beispiel #10
0
def access_bookmarking_tools(option):
    """Access option from 'Bookmarking Tools'.

    :param option: Option from 'Bookmarking Tools'.
    :return: None.
    """

    bookmarking_tools_pattern = LibraryMenu.BookmarksOption.BOOKMARKING_TOOLS
    open_library_menu(LibraryMenu.BOOKMARKS_OPTION)

    try:
        wait(bookmarking_tools_pattern, 10)
        logger.debug('Bookmarking Tools option has been found.')
        click(bookmarking_tools_pattern)
    except FindError:
        raise APIHelperError(
            'Can\'t find the Bookmarking Tools option, aborting.')
    try:
        wait(option, 15)
        logger.debug('%s option has been found.' % option)
        click(option)
    except FindError:
        raise APIHelperError('Can\'t find the %s option, aborting.' % option)
Beispiel #11
0
def click_hamburger_menu_option(option):
    """Click on a specific option from the hamburger menu.

    :param option: Hamburger menu option to be clicked.
    :return: The region created starting from the hamburger menu pattern.
    """
    hamburger_menu_pattern = NavBar.HAMBURGER_MENU
    try:
        wait(hamburger_menu_pattern, 10)
        logger.debug('Hamburger menu found.')
    except FindError:
        raise APIHelperError(
            'Can\'t find the "hamburger menu" in the page, aborting test.')
    else:
        click(hamburger_menu_pattern)
        time.sleep(Settings.DEFAULT_UI_DELAY)
        try:
            region = create_region_from_image(hamburger_menu_pattern)
            region.click(option)
            return region
        except FindError:
            raise APIHelperError(
                'Can\'t find the option in the page, aborting test.')
Beispiel #12
0
def close_window_control(window_type):
    """Click on close window control.

    :param window_type: Type of window that need to be closed.
    :return: None.
    """
    find_window_controls(window_type)

    if window_type == 'auxiliary':
        if OSHelper.is_mac():
            hover(AuxiliaryWindow.RED_BUTTON_PATTERN)
            click(AuxiliaryWindow.HOVERED_RED_BUTTON)
        else:
            click(AuxiliaryWindow.CLOSE_BUTTON)
    else:
        if OSHelper.is_mac():
            hover(MainWindow.UNHOVERED_MAIN_RED_CONTROL)
            click(MainWindow.HOVERED_MAIN_RED_CONTROL)
        else:
            click(MainWindow.CLOSE_BUTTON)
Beispiel #13
0
def get_telemetry_info():
    """Returns telemetry information as a JSON object from 'about:telemetry'
    page.
    """

    copy_raw_data_to_clipboard_pattern = Pattern(
        'copy_raw_data_to_clipboard.png')
    raw_json_pattern = Pattern('raw_json.png')
    raw_data_pattern = Pattern('raw_data.png')

    new_tab()

    paste('about:telemetry')
    type(Key.ENTER)

    try:
        wait(raw_json_pattern, 10)
        logger.debug('\'RAW JSON\' button is present on the page.')
        click(raw_json_pattern)
    except (FindError, ValueError):
        raise APIHelperError('\'RAW JSON\' button not present in the page.')

    try:
        wait(raw_data_pattern, 10)
        logger.debug('\'Raw Data\' button is present on the page.')
        click(raw_data_pattern)
    except (FindError, ValueError):
        close_tab()
        raise APIHelperError('\'Raw Data\' button not present in the page.')

    try:
        click(copy_raw_data_to_clipboard_pattern)
        time.sleep(Settings.DEFAULT_UI_DELAY)
        json_text = get_clipboard()
        return json.loads(json_text)
    except Exception:
        raise APIHelperError(
            'Failed to retrieve raw message information value.')
    finally:
        close_tab()
def cancel_in_progress_downloads_from_the_library(private_window=False):
    # Open the 'Show Downloads' window and cancel all 'in progress' downloads.
    global cancel_downloads
    if private_window:
        steps = show_all_downloads_from_library_menu_private_window()
        logger.debug('Creating a region for Private Library window.')
        try:
            find_back_button = find(NavBar.BACK_BUTTON)
        except FindError:
            raise FindError('Could not get the coordinates of the nav bar back button.')

        try:
            find_hamburger_menu = find(NavBar.HAMBURGER_MENU)
        except FindError:
            raise FindError('Could not get the coordinates of the hamburger menu.')

        region = Region(find_back_button.x - 10, find_back_button.y,
                        Screen.SCREEN_WIDTH, Screen.SCREEN_HEIGHT)
    else:
        steps = open_show_all_downloads_window_from_library_menu()
        logger.debug('Creating a region for Non-private Library window.')
        expected = exists(Library.TITLE, 10)
        assert expected is True, 'Library successfully opened.'

        try:
            find_library = find(Library.TITLE)
        except FindError:
            raise FindError('Could not get the x-coordinate of the library window title.')

        try:
            find_clear_downloads = find(Library.CLEAR_DOWNLOADS)
        except FindError:
            raise FindError('Could not get the x-coordinate of the clear_downloads button.')

        clear_downloads_width, clear_downloads_height = Library.CLEAR_DOWNLOADS.get_size()
        region = Region(find_library.x - 10, find_library.y,
                        (find_clear_downloads.x + clear_downloads_width + 20) - find_library.x, 500)

    # Cancel all 'in progress' downloads.
    expected = region.exists(DownloadManager.DownloadsPanel.DOWNLOAD_CANCEL, 5)
    expected_highlighted = region.exists(DownloadManager.DownloadsPanel.DOWNLOAD_CANCEL_HIGHLIGHTED)
    if expected or expected_highlighted:
        steps.append(Step(expected, 'The Cancel Download button is displayed properly.'))
        cancel_downloads = True
        expected_cancel = True
    else:
        steps.append(Step(True, 'There are no downloads to be cancelled.'))
        cancel_downloads = False

    cancel_pattern = DownloadManager.DownloadsPanel.DOWNLOAD_CANCEL if expected \
        else DownloadManager.DownloadsPanel.DOWNLOAD_CANCEL_HIGHLIGHTED

    if cancel_downloads:
        while expected_cancel:
            expected_cancel = region.exists(cancel_pattern, 10)
            if expected_cancel:
                click(cancel_pattern)
                if not private_window:
                    hover(Library.TITLE)
        steps.append(Step(True, 'All downloads were cancelled.'))

    if private_window:
        close_tab()
    else:
        click_window_control('close')

    return steps
Beispiel #15
0
def restore_window_from_taskbar(option=None):
    """Restore firefox from task bar."""
    if OSHelper.is_mac():
        try:
            click(Pattern('main_menu_window.png'))
            if option == "browser_console":
                click(Pattern('window_browser_console.png'))
            else:
                click(Pattern('window_firefox.png'))
        except FindError:
            raise APIHelperError('Restore window from taskbar unsuccessful.')
    elif OSHelper.get_os_version() == 'win7':
        try:
            click(Pattern('firefox_start_bar.png'))
            if option == "library_menu":
                click(Pattern('firefox_start_bar_library.png'))
            if option == "browser_console":
                click(Pattern('firefox_start_bar_browser_console.png'))
        except FindError:
            raise APIHelperError('Restore window from taskbar unsuccessful.')

    else:
        type(text=Key.TAB, modifier=KeyModifier.ALT)
        if OSHelper.is_linux():
            Mouse().move(Location(0, 50))
    time.sleep(Settings.DEFAULT_UI_DELAY)
Beispiel #16
0
def select_file_in_folder(directory,
                          filename_pattern,
                          file_option,
                          max_num_of_attempts=3):
    """
    Opens directory, selects file in opened directory, and provides action with it (e.g. copy, cut, delete),
    and closes opened directory.

    :param directory: Folder on hard drive to open.
    :param filename_pattern: File Pattern to select.
    :param file_option: File processing function. Appropriate methods are: edit_copy, edit_cut, edit_delete.
    :param max_num_of_attempts: Attempts to find pattern of file name. Default: 3
    """

    finder_list_view = '2'
    type_delay = 0.5

    if not isinstance(directory, str):
        raise ValueError(INVALID_GENERIC_INPUT)

    if not isinstance(filename_pattern, Pattern):
        raise ValueError(INVALID_GENERIC_INPUT)

    if not callable(file_option):
        raise ValueError(INVALID_GENERIC_INPUT)

    open_directory(directory)

    try:
        for attempt in range(1, max_num_of_attempts + 1):
            file_located = exists(filename_pattern)

            if file_located:
                logger.debug('File {} in directory {} is available.'.format(
                    filename_pattern, directory))
                break
            else:
                if attempt == max_num_of_attempts:
                    logger.debug(
                        'File {} is not available after {} attempt(s).'.format(
                            filename_pattern, attempt))
                    raise Exception

                time.sleep(Settings.DEFAULT_UI_DELAY_LONG)
                if OSHelper.is_mac():
                    type(text=finder_list_view,
                         modifier=KeyModifier.CMD,
                         interval=type_delay)

        click(filename_pattern)

        file_option()

    except Exception:
        raise APIHelperError('Could not find file {} in folder {}.'.format(
            filename_pattern, directory))
    finally:
        if OSHelper.is_windows():
            type(text='w', modifier=KeyModifier.CTRL)
        elif OSHelper.is_linux():
            type(text='q', modifier=KeyModifier.CTRL)
        elif OSHelper.is_mac():
            type(text='w', modifier=KeyModifier.CMD + KeyModifier.ALT)