def test_books_containing_list_is_on_left_of_page(webview_base_url, selenium, page_id): # GIVEN the webview base url, page_id, and the Selenium driver # WHEN we load the page of the chapter and we have the width of the window content = ContentPage(selenium, webview_base_url, id=page_id).open() window_width = content.get_window_size("width") # THEN check if the books list exists and on the left assert content.books_containing.book_list assert content.location["x"] < window_width / 2
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)
def test_books_containing_have_revised_date(webview_base_url, selenium, ch_review_id): # GIVEN the webview base url, a chapter review id, and the Selenium driver # WHEN the content_page is fully loaded and we have a list of books containing the page content = ContentPage(selenium, webview_base_url, id=ch_review_id).open() books = content.books_containing.book_list # THEN all the Books should contain revision date for book in books: assert book.revision_date.is_displayed
def test_books_containing_have_authors(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 = ContentPage(selenium, webview_base_url, id=page_id).open() books = content.books_containing.book_list # THEN the authors of the book should be displayed for book in books: assert book.author.is_displayed()
def test_books_containing_title_not_limited(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 the page content = ContentPage(selenium, webview_base_url, id=page_id).open() books = content.books_containing.book_list # THEN the title of the books are not truncated by ellipses for book in books: assert "..." not in book.title
def test_button_open_with_certain_window_size(webview_base_url, selenium, page_id, width, height): # 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 the page content = ContentPage(selenium, webview_base_url, id=page_id).open() # THEN if window width >= 640, button should be open if width >= 640: assert content.books_containing.overview_is_displayed # AND if window width < 640, button should be closed else: assert not content.books_containing.overview_is_displayed
def test_books_containing_go_to_book_link(webview_base_url, selenium, ch_review_id): # GIVEN the webview base url, a chapter review id, and the Selenium driver content = ContentPage(selenium, webview_base_url, id=ch_review_id).open() books = content.books_containing.book_list # WHEN we click the link to the first book title = books[0].title book = books[0].click_go_to_book_link # THEN we are on the About this Book page and it is displayed assert type(book) == AboutBook assert book.about_this_book_section.is_displayed assert book.title == title
def test_books_containing_message_is_correct(webview_base_url, selenium, page_id): # GIVEN the webview base url, page_id, and the Selenium driver # WHEN we visit the content page # AND we have a books containing count # AND we have the overview message content = ContentPage(selenium, webview_base_url, id=page_id).open() book_count = len(content.books_containing.book_list) overview = content.books_containing.overview # THEN ensure the proper books containing overview message is displayed if book_count > 1: assert overview == f"This page is in {book_count} books:" elif book_count > 0: assert overview == "This page is in this book:" else: assert overview == "This page is not in any books."
def test_book_title_link_and_highlight_on_view(webview_base_url, id, selenium, highlight_color): # GIVEN the webview base url, a chapter page id, the color and the Selenium driver # WHEN we visit that page of the chapter content = ContentPage(selenium, webview_base_url, id=id).open() content_page_title = content.title # AND click the title content.books_containing.book_list[0].click_title_link() # AND get and click the Contents button content.header_nav.click_contents_button() # AND find the on viewing title and get the color active_color = content.table_of_contents.active_page_color # THEN make sure the section matches the original page title and the highlight color is correct assert content_page_title == content.section_title_without_chapter_section assert active_color == highlight_color
def test_books_containing_button_toggles_and_labelled_books(webview_base_url, selenium, page_id): # GIVEN the webview base url, page_id, and the Selenium driver # WHEN we visit a single content page (not a book) content = ContentPage(selenium, webview_base_url, id=page_id).open() books_containing = content.books_containing # THEN the button that opens and closes the "ToC" is labelled "Books" instead of "Contents" # AND the button opens and closes the "This page is in # books" side nav contents_button = content.header_nav.contents_button assert contents_button.text == "Books" # The side nav area should be open by default assert books_containing.is_displayed content.header_nav.click_contents_button() assert not books_containing.is_displayed content.header_nav.click_contents_button() content.books_containing.wait_for_region_to_display() assert books_containing.is_displayed