Ejemplo n.º 1
0
def open_library_menu(option):
    """Open a specific option from 'Library' menu with an option as an argument.

    :param option: Library menu option to be selected.
    :return: None
    """

    library_menu_pattern = NavBar.LIBRARY_MENU

    library_option_list = {
        'Bookmarks': 1,
        'View Pocket List': 2,
        'History': 3,
        'Downloads': 4,
        'Synced Tabs': 5
    }

    if OSHelper.is_windows():
        value = 5
    else:
        value = 4

    try:
        wait(library_menu_pattern, 10)
        region = Region(
            image_find(library_menu_pattern).x - Screen().width / value,
            image_find(library_menu_pattern).y,
            Screen().width / value,
            Screen().height / value,
        )
        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(LibraryMenu.BOOKMARKS_OPTION, 10)
            option_number_in_library_list = library_option_list[option]
            for _ in range(option_number_in_library_list):
                time.sleep(0.5)
                type(Key.TAB)
            time.sleep(1)
            type(Key.ENTER)

        except FindError:
            raise APIHelperError(
                "Can't find the option in the page, aborting test.")
Ejemplo n.º 2
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

    if OSHelper.is_windows():
        value = 5
    else:
        value = 4

    try:
        wait(library_menu_pattern, 10)
        region = Region(
            image_find(library_menu_pattern).x - Screen().width / value,
            image_find(library_menu_pattern).y,
            Screen().width / value,
            Screen().height / value,
        )
        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.")