예제 #1
0
파일: test_utils.py 프로젝트: yyayegor/iris
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)
예제 #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.')
예제 #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()
예제 #4
0
def bookmark_page():
    """Bookmark the current page."""
    if Settings.get_os() == Platform.MAC:
        type(text='d', modifier=KeyModifier.CMD)
    else:
        type(text='d', modifier=KeyModifier.CTRL)
    try:
        wait(LocationBar.BOOKMARK_SELECTED_BUTTON, 10)
        logger.debug('Page was successfully bookmarked')
    except FindError:
        raise APIHelperError('Page can not be bookmarked')
예제 #5
0
def get_os():
    """Get the type of the operating system your script is running on."""
    current_system = Platform.OS_NAME
    if current_system == 'win':
        current_os = 'win'
    elif current_system == 'linux':
        current_os = 'linux'
    elif current_system == 'mac':
        current_os = 'osx'
    else:
        raise APIHelperError('Iris does not yet support your current environment: ' + current_system)
    return current_os
예제 #6
0
def bookmarks_sidebar(option):
    """Toggle open/close the bookmarks sidebar."""
    if Settings.get_os() == Platform.MAC:
        type(text='b', modifier=KeyModifier.CMD)
    else:
        type(text='b', modifier=KeyModifier.CTRL)

    bookmark_sidebar_header_pattern = SidebarBookmarks.BOOKMARKS_HEADER
    if option == 'open':
        try:
            wait(bookmark_sidebar_header_pattern, 10)
            logger.debug('Sidebar is opened.')
        except FindError:
            raise APIHelperError('Sidebar is NOT present on the page, aborting.')
    elif option == 'close':
        try:
            wait_vanish(bookmark_sidebar_header_pattern, 10)
            logger.debug('Sidebar is closed.')
        except FindError:
            raise APIHelperError('Sidebar is NOT closed, aborting.')
    else:
        raise APIHelperError('Option is not supported, aborting')
예제 #7
0
def bookmarks_sidebar(option):
    """Toggle open/close the bookmarks sidebar."""
    if Settings.getOS() == Platform.MAC:
        type(text='b', modifier=KeyModifier.CMD)
    else:
        type(text='b', modifier=KeyModifier.CTRL)

    bookmark_sidebar_img = 'bookmark_sidebar.png'
    if option == 'open':
        try:
            wait(bookmark_sidebar_img, 10)
            logger.debug('Sidebar is opened.')
        except FindError:
            raise APIHelperError(
                'Sidebar is NOT present on the page, aborting.')
    elif option == 'close':
        try:
            waitVanish(bookmark_sidebar_img, 10)
            logger.debug('Sidebar is closed.')
        except FindError:
            raise APIHelperError('Sidebar is NOT closed, aborting.')
    else:
        raise APIHelperError('Option is not supported, aborting')