Пример #1
0
def open_library_menu(option):
    """Open the Library menu with an option as argument.

    :param option: Library menu option.
    :return: Custom region created for a more efficient and accurate image
    pattern search.
    """

    library_menu_pattern = NavBar.LIBRARY_MENU

    try:
        wait(library_menu_pattern, 10)
        region = Region(
            image_find(library_menu_pattern).x - Screen().width / 4,
            image_find(library_menu_pattern).y,
            Screen().width / 4,
            Screen().height / 4 - 100)
        logger.debug('Library menu found.')
    except FindError:
        raise APIHelperError(
            'Can\'t find the library menu in the page, aborting test.')
    else:
        time.sleep(Settings.DEFAULT_UI_DELAY_LONG)
        click(library_menu_pattern)
        time.sleep(Settings.DEFAULT_UI_DELAY_SHORT)
        try:
            time.sleep(Settings.DEFAULT_UI_DELAY_SHORT)
            region.wait(option, 10)
            logger.debug('Option found.')
            region.click(option)
            return region
        except FindError:
            raise APIHelperError(
                'Can\'t find the option in the page, aborting test.')
Пример #2
0
def access_and_check_pattern(access_pattern, msg, check_pattern=None, access_type=None):
    """Access and check(if it exists) the patterns received.

    :param access_pattern: pattern to find and access if access_type is not None.
    :param msg: Message to display on test result
    :param check_pattern: pattern to assert after accessing 'find_pattern'.
    :param access_type: action to be performed on the access_pattern image. TODO Add more actions when needed
    :return: None.
    """

    try:
        exists = wait(access_pattern, 10)
        logger.debug('%s pattern is displayed properly.' % access_pattern)
        if access_type and access_type == 'click':
            click(access_pattern)
    except FindError:
        raise APIHelperError(
            'Can\'t find the %s pattern, aborting.' % access_pattern.get_filename())

    if check_pattern:
        try:
            exists = wait(check_pattern, 15)
            logger.debug('%s pattern has been found.' % check_pattern.get_filename())
        except FindError:
            raise APIHelperError('Can\'t find the %s option, aborting.' % check_pattern.get_filename())

    return Step(exists, '%s was accessed and displayed properly.' % msg)
def download_file(file_to_download, accept_download):
    """
    :param file_to_download: File to be downloaded.
    :param accept_download: Accept download pattern.
    :return: None.
    """
    file_found = exists(file_to_download, 2)
    if file_found:
        click(file_to_download)
    else:
        while not file_found:
            type(Key.PAGE_DOWN)
            try:
                click(file_to_download)
                file_found = True
            except FindError:
                file_found = False
            if exists(DownloadFiles.ABOUT, 2):
                raise APIHelperError('File to be downloaded not found.')

    try:
        wait(DownloadFiles.SAVE_FILE, 90)
        logger.debug('The \'Save file\' option is present in the page.')
        click(DownloadFiles.SAVE_FILE)
    except FindError:
        raise APIHelperError('The \'Save file\' option is not present in the page, aborting.')

    try:
        ok_button = exists(accept_download, 5)
        if ok_button:
            logger.debug('The OK button found in the page.')
            click(accept_download)
    except FindError:
        raise APIHelperError('The OK button is not found in the page.')
Пример #4
0
def create_region_for_hamburger_menu():
    """Create region for hamburger menu pop up."""

    hamburger_menu_pattern = NavBar.HAMBURGER_MENU
    try:
        wait(hamburger_menu_pattern, 10)
        click(hamburger_menu_pattern)
        time.sleep(0.5)
        sign_in_to_sync = Pattern('sign_in_to_sync.png')
        if OSHelper.is_linux():
            quit_menu_pattern = Pattern('quit.png')
            return RegionUtils.create_region_from_patterns(None,
                                                           sign_in_to_sync,
                                                           quit_menu_pattern,
                                                           None,
                                                           padding_right=20)
        elif OSHelper.is_mac():
            help_menu_pattern = Pattern('help.png')
            return RegionUtils.create_region_from_patterns(None,
                                                           sign_in_to_sync,
                                                           help_menu_pattern,
                                                           None,
                                                           padding_right=20)
        else:
            exit_menu_pattern = Pattern('exit.png')
            return RegionUtils.create_region_from_patterns(None,
                                                           sign_in_to_sync,
                                                           exit_menu_pattern,
                                                           None,
                                                           padding_right=20)
    except (FindError, ValueError):
        raise APIHelperError(
            'Can\'t find the hamburger menu in the page, aborting test.')
Пример #5
0
def remove_zoom_indicator_from_toolbar():
    """Remove the zoom indicator from toolbar by clicking on the 'Remove from
    Toolbar' button.
    """

    zoom_control_toolbar_decrease_pattern = NavBar.ZOOM_OUT
    remove_from_toolbar_pattern = Pattern('remove_from_toolbar.png')

    try:
        wait(zoom_control_toolbar_decrease_pattern,
             Settings.DEFAULT_FIREFOX_TIMEOUT)
        logger.debug('\'Decrease\' zoom control found.')
        right_click(zoom_control_toolbar_decrease_pattern)
    except FindError:
        raise APIHelperError(
            'Can\'t find the \'Decrease\' zoom control button in the page, \
            aborting.')

    try:
        wait(remove_from_toolbar_pattern, Settings.DEFAULT_FIREFOX_TIMEOUT)
        logger.debug('\'Remove from Toolbar\' option found.')
        click(remove_from_toolbar_pattern)
    except FindError:
        raise APIHelperError(
            'Can\'t find the \'Remove from Toolbar\' option in the page, \
            aborting.')

    try:
        wait_vanish(zoom_control_toolbar_decrease_pattern,
                    Settings.DEFAULT_FIREFOX_TIMEOUT)
    except FindError:
        raise APIHelperError(
            'Zoom indicator not removed from toolbar, aborting.')
Пример #6
0
def click_cancel_button():
    """Click cancel button."""
    cancel_button_pattern = Pattern('cancel_button.png')
    try:
        wait(cancel_button_pattern, 10)
        logger.debug('Cancel button found.')
        click(cancel_button_pattern)
    except FindError:
        raise APIHelperError('Can\'t find the cancel button, aborting.')
Пример #7
0
def close_customize_page():
    """Close the 'Customize...' page by pressing the 'Done' button."""
    customize_done_button_pattern = Pattern('customize_done_button.png')
    try:
        wait(customize_done_button_pattern, 10)
        logger.debug('Done button found.')
        click(customize_done_button_pattern)
    except FindError:
        raise APIHelperError(
            'Can\'t find the Done button in the page, aborting.')
Пример #8
0
def confirm_firefox_launch(image=None):
    """Waits for firefox to exist by waiting for the iris logo to be present.
    :param image: Pattern to confirm Firefox launch
    :return: None.
    """
    if image is None:
        image = Pattern('iris_logo.png')

    try:
        wait(image, 60)
    except Exception:
        raise APIHelperError('Can\'t launch Firefox - aborting test run.')
Пример #9
0
def confirm_close_multiple_tabs():
    """Click confirm 'Close all tabs' for warning popup when multiple tabs are
    opened.
    """
    close_all_tabs_button_pattern = Pattern('close_all_tabs_button.png')

    try:
        wait(close_all_tabs_button_pattern, 5)
        logger.debug('"Close all tabs" warning popup found.')
        type(Key.ENTER)
    except FindError:
        logger.debug('Couldn\'t find the "Close all tabs" warning popup.')
        pass
Пример #10
0
def change_preference(pref_name, value):
    """Change the value for a specific preference.

    :param pref_name: Preference to be changed.
    :param value: Preference's value after the change.
    :return: None.
    """
    try:
        new_tab()
        navigate('about:config')
        time.sleep(Settings.DEFAULT_UI_DELAY)

        type(Key.SPACE)
        time.sleep(Settings.DEFAULT_UI_DELAY)

        type(Key.ENTER)
        time.sleep(Settings.DEFAULT_UI_DELAY)

        paste(pref_name)
        time.sleep(Settings.DEFAULT_UI_DELAY)
        type(Key.TAB)
        time.sleep(Settings.DEFAULT_UI_DELAY)
        type(Key.TAB)
        time.sleep(Settings.DEFAULT_UI_DELAY)

        try:
            retrieved_value = copy_to_clipboard()
        except Exception:
            raise APIHelperError('Failed to retrieve preference value.')

        if retrieved_value == value:
            logger.debug('Flag is already set to value:' + value)
            return None
        else:
            type(Key.ENTER)
            dialog_box_pattern = Pattern('preference_dialog_icon.png')
            try:
                wait(dialog_box_pattern, 3)
                paste(value)
                type(Key.ENTER)
            except FindError:
                pass

        close_tab()
    except Exception:
        raise APIHelperError('Could not set value: %s to preference: %s' %
                             (value, pref_name))
Пример #11
0
    def wait(self, ps=None, timeout=None) -> bool or FindError:
        """Wait for a Pattern or image to appear.

        :param ps: Pattern or String.
        :param timeout: Number as maximum waiting time in seconds.
        :return: True or FineError Exception.
        """
        return wait(ps, timeout, self._area)
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)
Пример #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()
Пример #14
0
    def generate_region_by_markers(top_left_marker_img=None,
                                   bottom_right_marker_img=None):
        """Generate a region starting from 2 markers.

        :param top_left_marker_img: Top left pattern used to generate the region.
        :param bottom_right_marker_img: Bottom right pattern used to generate the region.
        :return: Screen region generated.
        """
        try:
            wait(top_left_marker_img, 10)
            exists(bottom_right_marker_img, 10)
        except FindError:
            raise FindError('Unable to find page markers.')

        top_left_pos = find(top_left_marker_img)
        bottom_right_pos = find(bottom_right_marker_img)

        marker_width, marker_height = bottom_right_marker_img.get_size()

        return Region(top_left_pos.x, top_left_pos.y,
                      (bottom_right_pos.x + marker_width),
                      bottom_right_pos.y - top_left_pos.y + marker_height)
Пример #15
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.')
Пример #16
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)
Пример #17
0
def find_window_controls(window_type):
    """Find window controls for main and auxiliary windows.

    :param window_type: Controls for a specific window type.
    :return: None.
    """
    if window_type == 'auxiliary':
        Mouse().move(Location(1, 300))
        if OSHelper.is_mac():
            try:
                wait(AuxiliaryWindow.RED_BUTTON_PATTERN.similar(0.9), 5)
                logger.debug('Auxiliary window control found.')
            except FindError:
                raise APIHelperError(
                    'Can\'t find the auxiliary window controls, aborting.')
        else:
            if OSHelper.is_linux():
                Mouse().move(Location(80, 0))
            try:
                wait(AuxiliaryWindow.CLOSE_BUTTON, 5)
                logger.debug('Auxiliary window control found.')
            except FindError:
                raise APIHelperError(
                    'Can\'t find the auxiliary window controls, aborting.')

    elif window_type == 'main':
        if OSHelper.is_mac():
            try:
                wait(MainWindow.MAIN_WINDOW_CONTROLS.similar(0.9), 5)
                logger.debug('Main window controls found.')
            except FindError:
                raise APIHelperError(
                    'Can\'t find the Main window controls, aborting.')
        else:
            try:
                if OSHelper.is_linux():
                    reset_mouse()
                wait(MainWindow.CLOSE_BUTTON, 5)
                logger.debug('Main window control found.')
            except FindError:
                raise APIHelperError(
                    'Can\'t find the Main window controls, aborting.')
    else:
        raise APIHelperError('Window Type not supported.')