示例#1
0
def _check_sr(sr, expected):  #pylint: disable=too-many-return-statements
    """Check a search result."""

    # check the title and subtitle
    names = get_search_result_names([sr])
    if names[0] != expected[0]:
        return False
    elem = find_child(".subtitle", sr)
    if expected[1]:
        if not elem or elem.text != expected[1]:
            return False
    else:
        if elem is not None:
            return False

    # check the snippet
    if find_child(".snippet", sr).text != expected[2]:
        return False

    # check the authors
    authors = [t.text for t in find_children(".author", sr)]
    if authors != expected[4]:
        return False

    # check the tags
    tags = [t.text for t in find_children(".tag", sr)]
    if tags != expected[5]:
        return False

    # check the article's link
    elem = find_child("a.open-link", sr)
    if expected[6]:
        assert elem
        if elem.get_attribute("href") != expected[6]:
            return False
    else:
        assert elem is None

    return True
示例#2
0
def _do_test_search( query, expected ):
    """Run a search and check the results."""
    results = do_search( query )
    assert set( get_search_result_names( results ) ) == set( expected )
    return results
示例#3
0
 def check_results( expected_url, expected_title, expected_sr ):
     wait_for( 2, lambda: check_title( expected_title ) )
     assert get_url() == "{}/{}".format( url_stem, expected_url ) if expected_url else url_stem
     results = get_search_results()
     assert get_search_result_names( results ) == expected_sr
     return results
示例#4
0
 def click_on_tag( tag, expected ):
     tag.click()
     wait_for( 2, lambda: get_search_result_names() == expected )
     return get_search_results()
示例#5
0
 def click_on_publisher( sr, expected_publ, expected_sr ):
     elem = find_child( ".header .publisher", sr )
     assert elem.text == expected_publ
     elem.click()
     wait_for( 2, lambda: get_search_result_names() == expected_sr )
示例#6
0
 def check_tags( sr ):
     name = get_search_result_names( [sr] )[ 0 ]
     tags = [ t.text for t in find_children( ".tag", sr ) ]
     if tags == expected[name]:
         return name
     return None