Exemple #1
0
def get_pref_value(pref_name):
    """Returns the value of a provided preference from 'about:config' page.

    :param pref_name: Preference's name.
    :return: Preference's value.
    """

    new_tab()
    select_location_bar()
    paste("about:config")
    type(Key.ENTER)
    time.sleep(Settings.DEFAULT_UI_DELAY)

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

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

    try:
        value = copy_to_clipboard().split("\t")[1]
    except Exception as e:
        raise APIHelperError(
            "Failed to retrieve preference value.\n{}".format(e))

    close_tab()
    return value
Exemple #2
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))
Exemple #3
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.
    """
    if not isinstance(value, str):
        value = str(value).lower()
    try:
        new_tab()
        navigate("about:config")
        time.sleep(Settings.DEFAULT_UI_DELAY_LONG)

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

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

        try:
            retrieved_value = copy_to_clipboard().split("\t")[1]
        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)
            if not (value == "true" or value == "false"):
                try:
                    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))
Exemple #4
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()
Exemple #5
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