Exemple #1
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)
Exemple #2
0
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:
            scroll_down()
            try:
                click(file_to_download)
                file_found = True
            except FindError:
                file_found = False
            if exists(DownloadFiles.ABOUT, 1):
                raise APIHelperError('File to be downloaded not found.')

    try:
        wait(DownloadFiles.SAVE_FILE, 5)
        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:
        wait(accept_download, 5)
        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.')
Exemple #3
0
def auto_hide_download_button():
    click_hamburger_menu_option('Customize...')

    try:
        wait(NavBar.DOWNLOADS_BUTTON, 10)
        logger.debug('Downloads button found in the \'Customize\' page.')
    except FindError:
        raise APIHelperError(
            'Downloads button not found in the \'Customize\' page.')

    click(NavBar.DOWNLOADS_BUTTON)
    try:
        wait(CustomizePage.AUTO_HIDE, 5)
        logger.debug('The auto-hide button found in the page.')
    except FindError:
        raise APIHelperError('The auto-hide button not found in the page.')

    click(CustomizePage.AUTO_HIDE)
    close_customize_page()
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,
                        find_hamburger_menu.x - find_back_button.x,
                        SCREEN_HEIGHT)
    else:
        steps = open_show_all_downloads_window_from_library_menu()
        logger.debug('Creating a region for Non-private Library window.')
        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.DownloadLibrary.CLEAR_DOWNLOADS)
        except FindError:
            raise FindError(
                'Could not get the x-coordinate of the clear_downloads button.'
            )

        clear_downloads_width, clear_downloads_height = Library.DownloadLibrary.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(
        Library.DownloadLibrary.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 Library.DownloadLibrary.DOWNLOAD_CANCEL_HIGHLIGHTED

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

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

    return steps