Пример #1
0
def test_donate_redirects_to_openstax_org(webview_base_url, selenium):
    # GIVEN the home page
    home = Home(selenium, webview_base_url).open()

    # WHEN the Give link is clicked and redirects to openstax.org
    donate = home.header.click_donate()
    assert donate.is_openstax_org_give_page
Пример #2
0
def test_book_cover_loads_correct_page(webview_base_url, selenium,
                                       rex_released_books):
    # GIVEN the webview base url, the Selenium driver, and a similarity ratio
    sim_ratio = 0.4

    # WHEN the home page is fully loaded,
    # AND we have a random OpenStax book title
    # AND we click the book cover link and load a content page
    # AND we have the title from the content page
    # AND we have a similarity ratio of the title
    home = Home(selenium, webview_base_url).open()

    while True:
        book = home.featured_books.get_random_openstax_book()
        if book.cnx_id not in rex_released_books:
            break

    book_title = book.clean_title
    content = book.click_book_cover()
    content_title = content.clean_title

    title_ratio = similar(book_title, content_title)

    # THEN compare the title from the home page and the content page for exact-ness.
    assert book_title == content_title or title_ratio >= sim_ratio
Пример #3
0
def test_get_this_book(webview_base_url, selenium):
    # GIVEN a book's content page
    home = Home(selenium, webview_base_url).open()
    book = home.featured_books.openstax_list[32]
    content = book.click_book_cover()

    # WHEN we click the "Get This Book!" button
    button_displayed = content.is_get_this_book_button_displayed
    if button_displayed:
        get_this_book = content.click_get_this_book_button()
        pdf_displayed = get_this_book.is_pdf_link_displayed
        offline_zip_displayed = get_this_book.is_offline_zip_link_displayed

    # THEN links to download the pdf, epub and offline zip versions are displayed
    # Look at the footer to see which downloads should have been available
    downloads = content.content_footer.click_downloads_tab()

    if not button_displayed:
        assert not downloads.is_any_available
        pytest.skip('No files available to download: "Get This Book!" button not present.')
    else:
        assert pdf_displayed or offline_zip_displayed

    # Check the footer
    if pdf_displayed:
        assert downloads.is_pdf_available

    if offline_zip_displayed:
        assert downloads.is_offline_zip_available
Пример #4
0
def test_search_pagination(webview_base_url, selenium, query):
    # GIVEN the browse page and a query
    home = Home(selenium, webview_base_url).open()
    browse = home.header.click_search()

    # WHEN we search for the query
    search_results = browse.search(query)

    # THEN search results are displayed with pagination
    assert type(search_results) is SearchResults

    pagination = search_results.pagination
    assert len(pagination) >= 4

    prev = pagination[0]
    assert prev.is_disabled
    assert not prev.is_active

    p1 = pagination[1]
    assert not p1.is_disabled
    assert p1.is_active

    p2 = pagination[2]
    assert not p2.is_disabled
    assert not p2.is_active

    next = pagination[-1]
    assert not next.is_disabled
    assert not next.is_active
Пример #5
0
def test_search_click_pagination(webview_base_url, selenium, query):
    # GIVEN the search results page
    home = Home(selenium, webview_base_url).open()
    browse = home.header.click_search()
    search_results = browse.search(query)

    # WHEN we click on the "next" pagination link
    next = search_results.pagination[-1]
    search_results = next.click_link()

    # THEN the pagination is updated
    assert type(search_results) is SearchResults

    pagination = search_results.pagination
    assert len(pagination) >= 4

    prev = pagination[0]
    assert not prev.is_disabled
    assert not prev.is_active

    p1 = pagination[1]
    assert not p1.is_disabled
    assert not p1.is_active

    p2 = pagination[2]
    assert not p2.is_disabled
    assert p2.is_active

    next = pagination[-1]
    # assert next.is_disabled - will change if we have more than 2 pages of results in the future
    assert not next.is_active
Пример #6
0
def test_search_bold(webview_base_url, selenium, query):
    # GIVEN the browse page and a query
    home = Home(selenium, webview_base_url).open()
    browse = home.header.click_search()

    # WHEN we search for the query
    search_results = browse.search(query)

    # THEN search results are displayed with query words bolded
    assert type(search_results) is SearchResults
    assert not search_results.has_no_results

    results = search_results.results
    any_occurrences = False

    # Test that all occurrences are bolded
    for word in query.split():
        for result in results:
            occurrences = result.count_occurrences(word)

            if occurrences > 0:
                any_occurrences = True

            assert occurrences == result.count_bold_occurrences(word)

    # At least one word must show up in the results
    # This could inadvertently become False if other modules with matching metadata are published
    assert any_occurrences, "No words from the query showed up in the results."
Пример #7
0
def test_featured_books_have_title_and_intro(webview_base_url, selenium):
    # GIVEN the webview base url and the Selenium driver

    # WHEN the home page is fully loaded
    home = Home(selenium, webview_base_url).open()

    # THEN all OpenStax books have titles and intros and all CNX books have titles
    # Book intros must not contain `...`. They may contain `…` but can't contain ONLY `…`.
    for book in home.featured_books.openstax_list:
        assert book.title
        intro = book.intro
        assert intro
        assert "..." not in intro
        assert intro != "…"

    # 2 CNX books have no intros and that is a WON'T FIX
    # because it would require us to contact the authors
    num_no_intro_cnx_books = 0
    for book in home.featured_books.cnx_list:
        assert book.title
        intro = book.intro
        if not intro:
            num_no_intro_cnx_books += 1
        assert "..." not in intro
        assert intro != "…"
    assert num_no_intro_cnx_books == 2
Пример #8
0
def test_footer_has_correct_content_and_links(webview_base_url, selenium):
    # GIVEN the home page
    home = Home(selenium, webview_base_url).open()

    # WHEN we scroll to the footer
    footer = home.footer
    footer.scroll_to()

    # THEN the links point to the correct urls and all the content is displayed
    assert footer.is_licensing_link_displayed
    assert footer.licensing_url == urljoin(webview_base_url, "/license")

    assert footer.is_terms_of_use_link_displayed
    assert footer.terms_of_use_url == urljoin(webview_base_url, "/tos")

    assert footer.is_accessibility_statement_link_displayed
    assert footer.accessibility_statement_url == "https://openstax.org/accessibility-statement"

    assert footer.is_contact_link_displayed
    assert footer.contact_url == urljoin(webview_base_url, "/about/contact")

    assert footer.is_foundation_support_paragraph_displayed
    assert footer.foundation_support_text == (
        "Supported by William & Flora Hewlett Foundation, Bill & Melinda Gates Foundation,"
        " Michelson 20MM Foundation, Maxfield Foundation, Open Society Foundations, and"
        " Rice University. Powered by OpenStax CNX.")

    assert footer.is_ap_paragraph_displayed
    assert footer.ap_text == (
        "Advanced Placement® and AP® are trademarks registered and/or owned by the College Board,"
        " which was not involved in the production of, and does not endorse, this site."
    )

    assert footer.is_copyright_statement_paragraph_displayed
    year = datetime.now().year
    assert footer.copyright_statement_text == (
        "© 1999-{year}, Rice University. Except where otherwise noted, content created on this site"
        " is licensed under a Creative Commons Attribution 4.0 License.".
        format(year=year))

    webview_url = urljoin(webview_base_url, "/")

    assert footer.is_facebook_link_displayed
    assert footer.facebook_url == (
        "https://facebook.com/sharer/sharer.php?u={webview_url}".format(
            webview_url=webview_url))

    assert footer.is_twitter_link_displayed
    assert footer.twitter_url == (
        "https://twitter.com/share?url={webview_url}&text=An%20OpenStax"
        "%20CNX%20book&via=cnxorg".format(webview_url=webview_url))

    assert footer.is_email_link_displayed
    assert footer.email_url == "mailto:[email protected]"

    footer_text = footer.text
    assert "Dev Blog" not in footer_text
    assert "iTunes U" not in footer_text
    assert "Google Plus" not in footer_text
Пример #9
0
def test_splash_banner_loads(webview_base_url, selenium):
    # GIVEN the main website URL and the Selenium driver

    # WHEN The home page URL is fully loaded
    page = Home(selenium, webview_base_url).open()

    # THEN The splash text is correct
    assert "Discover learning materials in an Open Space" in page.splash
Пример #10
0
def test_featured_books_load(webview_base_url, selenium):
    # GIVEN the webview base url and the Selenium driver

    # WHEN the home page is fully loaded
    page = Home(selenium, webview_base_url).open()

    # THEN there are featured books for both OpenStax and CNX
    assert len(page.featured_books.openstax_list) > 0
    assert len(page.featured_books.cnx_list) > 0
Пример #11
0
def test_logo_link_stays_on_home_page(webview_base_url, selenium):
    # GIVEN the home page
    home = Home(selenium, webview_base_url).open()

    # WHEN the OpenStax CNX logo is clicked
    home = home.header.click_cnx_logo()

    # THEN we are still in the home page
    assert type(home) is Home
Пример #12
0
def test_contact_has_questions_header(webview_base_url, selenium):
    # GIVEN the About Us page
    home = Home(selenium, webview_base_url).open()
    about_us = home.header.click_about_us()

    # WHEN the contact link in the navbar is clicked
    contact = about_us.click_contact()

    # THEN the Questions? header is displayed
    assert contact.contact_content.questions_header.text == "Questions?"
Пример #13
0
def test_logo_link_loads_home_page(webview_base_url, selenium):
    # GIVEN the browse page
    home = Home(selenium, webview_base_url).open()
    browse = home.header.click_search()

    # WHEN the OpenStax CNX logo is clicked
    home = browse.header.click_cnx_logo()

    # THEN the home page is loaded
    assert type(home) is Home
Пример #14
0
def test_subject_categories_load(webview_base_url, selenium):
    # GIVEN the webview base url and Selenium driver

    # When the homepage is fully loaded,
    #      and the browse link in the navbar is clicked
    page = Home(selenium, webview_base_url).open()
    browse_page = page.header.click_search()

    # Then The subject categories are loaded
    assert len(browse_page.search_category_list) > 0
Пример #15
0
def test_search_input_and_button_are_displayed(webview_base_url, selenium):
    # GIVEN the webview base url and Selenium driver

    # WHEN the home page URL is fully loaded,
    #      and the browse link in the navbar is clicked
    page = Home(selenium, webview_base_url).open()
    browse_page = page.header.click_search()

    # THEN The search bar and the advanced search button is displayed
    assert browse_page.is_search_input_displayed
    assert browse_page.is_advanced_search_link_displayed
Пример #16
0
def test_about_us_content_includes_openstax_goals(webview_base_url, selenium):
    # GIVEN the home page
    home = Home(selenium, webview_base_url).open()

    # WHEN the About Us link in the navbar is clicked
    about_us = home.header.click_about_us()

    # THEN the content includes a paragraph about the goals of OpenStax
    assert (
        "Today, OpenStax CNX is a dynamic non-profit digital ecosystem serving "
        "millions of users per month in the delivery of educational content "
        "to improve learning outcomes.") in about_us.about_content.text
Пример #17
0
def test_contact_has_correct_email_link(webview_base_url, selenium):
    # GIVEN the About Us page
    home = Home(selenium, webview_base_url).open()
    about_us = home.header.click_about_us()

    # WHEN the contact link in the navbar is clicked
    contact = about_us.click_contact()

    # THEN the contact email is displayed
    contact_content = contact.contact_content
    assert contact_content.is_email_displayed
    assert contact_content.email_url == "mailto:[email protected]"
Пример #18
0
def test_author_contains_openstax(webview_base_url, selenium):
    # GIVEN the home page and a book
    home = Home(selenium, webview_base_url).open()
    book = home.featured_books.openstax_list[59]

    # WHEN the book's cover is clicked
    content = book.click_book_cover()

    # THEN the displayed author is OpenStax
    content_header = content.content_header
    assert content_header.is_book_by_displayed
    assert content_header.are_authors_displayed
    assert "OpenStax" in content_header.authors
Пример #19
0
def test_attribution(webview_base_url, selenium):
    # GIVEN a book's content page
    home = Home(selenium, webview_base_url).open()
    book = home.featured_books.openstax_list[59]
    content = book.click_book_cover()

    # WHEN we click the attribution tab
    attribution = content.content_footer.click_attribution_tab()

    # THEN the attribution is displayed and has the correct support email
    assert attribution.is_displayed
    expected_sentence = "For questions regarding this license, please contact [email protected]."
    assert expected_sentence in attribution.text
Пример #20
0
def test_about_us_content_links(webview_base_url, selenium):
    # GIVEN the home page
    home = Home(selenium, webview_base_url).open()

    # WHEN the About Us link in the navbar is clicked
    about_us = home.header.click_about_us()

    # THEN the content includes learn more links with the correct text
    assert about_us.about_content.learn_more_team_text == "Learn more about the OpenStax team"
    assert (
        about_us.about_content.learn_more_foundations_text ==
        "Learn more about the foundations supporting OpenStax projects like CNX"
    )
Пример #21
0
def test_toc_is_displayed(webview_base_url, selenium):
    # GIVEN a book's content page
    home = Home(selenium, webview_base_url).open()
    book = home.featured_books.openstax_list[59]
    content = book.click_book_cover()

    # WHEN the contents button is clicked
    content.header_nav.click_contents_button()
    toc = content.table_of_contents

    # THEN the table of contents is displayed
    assert toc.is_displayed
    assert toc.number_of_chapters > 0
    assert toc.number_of_pages > 0
Пример #22
0
def test_search_no_results(webview_base_url, selenium):
    # GIVEN the browse page and a bogus query
    home = Home(selenium, webview_base_url).open()
    browse = home.header.click_search()
    query = "".join(choice(digits + ascii_letters) for i in range(32))

    # WHEN we search for the bogus query
    search_results = browse.search(query)

    # THEN the localized "no results found" message is displayed
    assert type(search_results) is SearchResults
    assert search_results.has_no_results
    # Valid only when the website is in English
    assert search_results.no_results_text == "No results found. Please try expanding your search."
def test_vendor_books_not_redirecting(vendor_base_url, selenium):

    home = Home(selenium, vendor_base_url).open()
    books = []

    # GIVEN the openstax list
    for op_book in home.featured_books.openstax_list:

        books.append(op_book.title)

    for book_title in books:

        home = Home(selenium, vendor_base_url).open()

        # using selenium fixture to overcome stale element exception occurring with page objects
        title_link = selenium.find_element_by_link_text(book_title)
        title_link.click()

        current_url = home.current_url
        data = requests.get(current_url)

        assert vendor_base_url in current_url
        assert 200 == data.status_code
Пример #24
0
def test_search_click_result(webview_base_url, selenium, query):
    # GIVEN the search results page
    home = Home(selenium, webview_base_url).open()
    browse = home.header.click_search()
    search_results = browse.search(query)

    # WHEN we click on a search result's title
    result = search_results.results[0]
    result_title = result.title
    content = search_results.results[0].click_title_link()

    # THEN we are taken to the matching content page
    assert type(content) is Content
    assert content.title == result_title
Пример #25
0
def test_nav_and_menus_display_after_scrolling(webview_base_url, selenium):
    # GIVEN a book's content page
    home = Home(selenium, webview_base_url).open()
    book = home.featured_books.openstax_list[59]
    content = book.click_book_cover()
    content_header = content.content_header
    original_content_header_y = content_header.root.location["y"]

    # WHEN we scroll to the bottom
    content.footer.scroll_to()
    content_footer = content.content_footer

    # THEN - the header nav is offscreen but still considered displayed
    #      - the content nav is displayed on top without the site navbar or any social links
    assert content.header.is_nav_displayed

    assert content_header.is_displayed
    assert content_header.is_title_displayed
    assert content_header.is_book_by_displayed
    assert not content_header.is_share_displayed

    header_nav = content_header.nav
    assert header_nav.is_contents_button_displayed
    assert header_nav.is_searchbar_displayed
    assert header_nav.is_back_link_displayed
    assert header_nav.is_progress_bar_displayed
    assert header_nav.is_next_link_displayed

    assert content.is_section_title_displayed

    share = content.share
    assert not share.is_displayed
    assert not share.is_facebook_share_link_displayed
    assert not share.is_twitter_share_link_displayed

    # The footer is displayed at the bottom
    assert content_footer.is_displayed
    assert content_footer.is_downloads_tab_displayed
    assert content_footer.is_history_tab_displayed
    assert content_footer.is_attribution_tab_displayed
    assert content_footer.is_more_information_tab_displayed

    # Hard to check that the content_header is on top after scrolling, but we can check
    # that it at least has the pinned class and is above the footer
    assert content_header.is_pinned
    assert not content_header.is_opened
    assert not content_header.is_closed
    assert content_header.root.location["y"] > original_content_header_y
    assert content_header.root.location["y"] < content_footer.root.location["y"]
Пример #26
0
def test_search_displays_results(webview_base_url, selenium, query):
    # GIVEN the browse page and a query
    home = Home(selenium, webview_base_url).open()
    browse = home.header.click_search()

    # WHEN we search for the query
    search_results = browse.search(query)

    # THEN search results are displayed with the query text
    assert type(search_results) is SearchResults

    for (word, breadcrumb) in zip(query.split(), search_results.breadcrumbs):
        assert breadcrumb.is_text
        assert breadcrumb.value == word

    assert not search_results.has_no_results
Пример #27
0
def test_click_subject_category(webview_base_url, selenium):
    # GIVEN the browse page
    home = Home(selenium, webview_base_url).open()
    browse = home.header.click_search()

    # WHEN a subject category is clicked
    subject = browse.search_category_list[3]
    subject_name = subject.name
    search_results = subject.click()

    # THEN search results are displayed with the correct subject title
    assert type(search_results) is SearchResults
    breadcrumb = search_results.breadcrumbs[0]
    assert breadcrumb.is_subject
    assert breadcrumb.subject == subject_name
    assert not search_results.has_no_results
Пример #28
0
def test_navs_and_elements_are_displayed(webview_base_url, selenium):
    # GIVEN the home page
    home = Home(selenium, webview_base_url).open()

    # WHEN a book is clicked
    book = home.featured_books.openstax_list[59]
    content = book.click_book_cover()

    # THEN the site navbar and content nav are displayed
    assert content.header.is_nav_displayed

    content_header = content.content_header
    assert content_header.is_displayed
    assert content_header.is_title_displayed
    assert content_header.is_book_by_displayed
    assert content_header.is_share_displayed

    header_nav = content_header.nav
    assert header_nav.is_contents_button_displayed
    assert header_nav.is_searchbar_displayed
    assert header_nav.is_back_link_displayed
    assert header_nav.is_progress_bar_displayed
    assert header_nav.is_next_link_displayed
    assert content.is_section_title_displayed

    # Section title is on top of main content section (white area)
    main_content_section = content.main_content_section
    section_title_div_location = content.section_title_div_location
    section_title_div_size = content.section_title_div_size

    # Section title inside main content section
    assert section_title_div_location["x"] >= main_content_section.location["x"]
    assert section_title_div_location["y"] >= main_content_section.location["y"]
    assert (
        section_title_div_location["x"] + section_title_div_size["width"]
        <= main_content_section.location["x"] + main_content_section.size["width"]
    )
    assert (
        section_title_div_location["y"] + section_title_div_size["height"]
        <= main_content_section.location["y"] + main_content_section.size["height"]
    )

    # Section title on top of main content section
    assert (
        section_title_div_location["y"] - main_content_section.location["y"]
        <= section_title_div_size["height"]
    )
Пример #29
0
def test_share_on_top_right_corner(webview_base_url, selenium):
    # GIVEN the home page
    home = Home(selenium, webview_base_url).open()

    # WHEN a book is clicked
    book = home.featured_books.openstax_list[59]
    content = book.click_book_cover()

    # THEN social share links are displayed in the top right corner
    share = content.share
    assert share.is_displayed
    assert share.is_facebook_share_link_displayed
    assert share.is_twitter_share_link_displayed
    root = content.share.root
    # Top half
    assert root.location["y"] + root.size["height"] < selenium.get_window_size()["height"] / 2
    # Right half
    assert root.location["x"] > selenium.get_window_size()["width"] / 2
Пример #30
0
def test_search_unfilter(webview_base_url, selenium, query):
    # GIVEN the search results page
    home = Home(selenium, webview_base_url).open()
    browse = home.header.click_search()
    search_results = browse.search(query)

    # WHEN we click on breadcrumb's X link
    search_results = search_results.breadcrumbs[0].click_x_link()

    # THEN search results are displayed with one less filter
    assert type(search_results) is SearchResults

    for (word, breadcrumb) in zip(query.split()[1:],
                                  search_results.breadcrumbs):
        assert breadcrumb.is_text
        assert breadcrumb.value == word

    assert not search_results.has_no_results