Ejemplo n.º 1
0
        def click_title_link(self):
            self.offscreen_click(self.find_element(*self._title_link_locator))
            from pages.webview.content import Content

            content = Content(self.driver, self.page.base_url,
                              self.page.timeout)
            return content.wait_for_page_to_load()
Ejemplo n.º 2
0
def test_id_links_and_back_button(page_uuid, is_baked_book_index, webview_base_url, selenium):
    # GIVEN an index page in a baked book or a page with anchor links in an unbaked book
    content_page = Content(selenium, webview_base_url, id=page_uuid).open()
    content_url = content_page.current_url
    assert "#" not in content_url

    # WHEN we click on a term (baked index) or an anchor link
    content_region = content_page.content_region
    if is_baked_book_index:
        content_page = content_region.click_index_term()
    else:
        content_page = content_region.click_anchor_link(internal_only=True)
        assert content_page.current_url.startswith(content_url)

    # THEN we end up at the linked page and the element with the same id as the link is displayed
    new_url = content_page.current_url
    assert "#" in new_url
    id = re.search("#(.+)$", new_url)[1]
    assert id
    assert content_page.is_element_id_displayed(id)

    # WHEN we click the browser's back button
    content_page.back()

    # THEN we end up at the previous page
    assert content_page.current_url == content_url
Ejemplo n.º 3
0
        def click_title_link(self):
            self.title_link.click()
            from pages.webview.content import Content

            content = Content(self.driver, self.page.base_url,
                              self.page.timeout)
            return content.wait_for_page_to_load()
Ejemplo n.º 4
0
        def click_book_cover(self):
            self.wait.until(lambda _: self.is_book_cover_clickable)
            self.offscreen_click(self.book_cover_link)
            from pages.webview.content import Content

            content = Content(self.driver, self.page.base_url,
                              self.page.timeout)
            return content.wait_for_page_to_load()
Ejemplo n.º 5
0
def test_newer_version_leads_to_correct_page(webview_base_url, selenium, id):
    # GIVEN the content page
    content = Content(selenium, webview_base_url, id=id).open()
    version = content.book_version
    section_title = content.section_title

    # WHEN the newer version link is clicked
    content = content.click_newer_version_link()

    # THEN we end up in a newer version of the same page
    assert content.section_title == section_title
    assert content.book_version > version
Ejemplo n.º 6
0
def test_page_with_unicode_characters_in_title_loads(webview_base_url, selenium, id):
    # GIVEN the webview base url, the Selenium driver and the id of a page whose title has unicode
    content = Content(selenium, webview_base_url, id=id)

    # WHEN we load the content page
    content = content.open()

    # Ensure it has a figure element
    assert content.content_region.has_figures

    # THEN the page does not reload afterwards
    # Wait 10 seconds to see if the page reloads
    sleep(10)
    # If we don't get a StaleElementReferenceException then the page didn't reload
    assert content.content_region.os_figures
Ejemplo n.º 7
0
def test_canonical_link_is_correct(webview_base_url, selenium, id):
    # GIVEN a book's content page
    content = Content(selenium, webview_base_url, id=id).open()
    section_title = content.section_title

    # WHEN the book's canonical url is visited
    selenium.get(content.canonical_url)
    content.wait_for_page_to_load()

    # THEN we end up in the same page
    # NOTE: we check the section title instead of the url because the canonical link seems to
    #       take us to the latest version of the content, no matter which version we started on
    # NOTE: Newer versions of the book may not have the section number. For this we check in the
    #       section_title string instead of an equality.
    assert content.section_title in section_title
Ejemplo n.º 8
0
def test_books_containing_list_in_sorted_order(webview_base_url, selenium, page_id):
    # GIVEN the webview base url, page_id, and the Selenium driver

    # WHEN we visit that page of the chapter and we have a list of books containing page
    content = Content(selenium, webview_base_url, id=page_id).open()

    # AND store the main author
    main_author = content.content_header.authors

    # AND Save list of authors and dates
    content = ContentPage(selenium, webview_base_url, id=page_id).open()
    dates = content.books_containing.date_list
    author = content.books_containing.author_list

    # THEN main author should be the author of the first book listed
    assert author[0][0] == main_author

    # AND if there are more books with main author, they should be listed first
    i = 1
    while i < len(author) - 1 and author[i][0] == main_author:
        i += 1

    # AND for the rest of the books, the revision dates are sorted in decreasing order
    date_list = []
    for date in dates[i:]:
        date_list.append(datetime.strptime(date[0], "%b %d, %Y"))
    assert date_list == sorted(date_list, reverse=True)
Ejemplo n.º 9
0
        def open(self):
            from pages.webview.content import Content

            return Content(self.driver,
                           self.page.base_url,
                           self.page.timeout,
                           id=self.content_id).open()
Ejemplo n.º 10
0
def test_chapter_review_version_matches_book_version(webview_base_url, selenium, ch_review_id):
    # GIVEN the webview base url, a chapter review id, and the Selenium driver

    # WHEN we visit the chapter review page
    content = Content(selenium, webview_base_url, id=ch_review_id).open()

    # THEN the chapter review version matches the book version
    assert content.page_version == content.book_version
Ejemplo n.º 11
0
def test_ncy_is_not_displayed(webview_base_url, american_gov_uuid, selenium):
    # GIVEN the webview base url, an American Government content page UUID, and the Selenium driver

    # WHEN the page is fully loaded using the URL
    page = Content(selenium, webview_base_url, id=american_gov_uuid).open()

    # THEN :NOT_CONVERTED_YET is not displayed
    assert page.is_ncy_displayed is False
Ejemplo n.º 12
0
def test_in_book_search(
    webview_base_url,
    selenium,
    uuid,
    query,
    has_results,
    result_index,
    has_os_figures,
    has_os_tables,
):
    # GIVEN a book's content page and a query
    content = Content(selenium, webview_base_url, id=uuid).open()

    # WHEN we search the book for the given query
    search_results = content.header_nav.search(query)

    # THEN search results are present (or not) and bolded and link to the matching content
    results = search_results.results
    result_count = search_results.result_count
    assert len(results) == result_count

    if not has_results:
        assert result_count == 0
        return

    assert result_count > 0

    words = query.split()
    for result in results:
        for word in words:
            assert result.count_occurrences(word) == result.count_bold_occurrences(word)

    result = results[result_index]
    title = result.title
    content = result.click_link()
    assert content.section_title == title

    content_region = content.content_region

    assert content_region.has_os_figures == has_os_figures
    for figure in content_region.os_figures:
        assert figure.caption.is_labeled
        assert figure.caption.is_numbered

    assert content_region.has_os_tables == has_os_tables
    for table in content_region.os_tables:
        assert table.caption.is_labeled
        assert table.caption.is_numbered
def test_vendor_pages_load(vendor_base_url, selenium,
                           openstax_all_books_uuids):

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

    vendor_content = Content(selenium,
                             vendor_base_url,
                             id=openstax_all_books_uuids).open()

    content = vendor_content.open()
    content.header_nav.click_contents_button()
    toc = content.table_of_contents

    # testing American Government 2e book as it requires different indexing
    if openstax_all_books_uuids == "9d8df601-4f12-4ac1-8224-b450bf739e5f":

        # WHEN a chapter is expanded and we navigate to one of its pages
        chapter = toc.chapters[2]
        chapter = chapter.click()
        page = chapter.pages[0]
        title = page.title
        content = page.click()

        # THEN we end up at the correct page
        current_url = home.current_url
        data = requests.get(current_url)

        assert vendor_base_url in current_url, "vendor_base_url is NOT in current_url"
        assert 200 == data.status_code, "status code is NOT 200"
        assert content.section_title == title, "section titles does NOT match"

    elif (openstax_all_books_uuids == "4eaa8f03-88a8-485a-a777-dd3602f6c13e"
          or openstax_all_books_uuids == "16ab5b96-4598-45f9-993c-b8d78d82b0c6"
          or openstax_all_books_uuids
          == "bb62933e-f20a-4ffc-90aa-97b36c296c3e"):
        # testing 3 Polish books as I cannot find appropriate indexes
        selenium.find_element_by_link_text("Rozdział 1").click()

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

        assert vendor_base_url in current_url, "vendor_base_url is NOT in current_url"
        assert 200 == data.status_code, "status code is NOT 200"

    else:
        # checking rest of the books that title and chapter/pages redirects

        # WHEN a chapter is expanded and we navigate to one of its pages
        chapter = toc.chapters[1]
        chapter = chapter.click()
        page = chapter.pages[1]
        title = page.title
        content = page.click()

        # THEN we end up at the correct page
        current_url = home.current_url
        data = requests.get(current_url)

        assert vendor_base_url in current_url, "vendor_base_url is NOT in current_url"
        assert 200 == data.status_code, "status code is NOT 200"
        assert content.section_title == title, "section titles does NOT match"