Skip to content

Commit

Permalink
FE Selenium test: Updates to smoke tests (#2237)
Browse files Browse the repository at this point in the history
* update search results

* discard modal updates

* correct typos
  • Loading branch information
Malar-Natarajan authored May 14, 2024
1 parent 25533ec commit 151ed1f
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 101 deletions.
13 changes: 13 additions & 0 deletions pytest-selenium/pages/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
BOUNDING_RECTANGLE = "return arguments[0].getBoundingClientRect();"
COMPUTED_STYLES = "return window.getComputedStyle(arguments[0]){field};"
ELEMENT_SELECT = "return document.querySelector('{selector}');"
FOCUSED_HIGHLIGHT_LOCATOR = "[data-highlight-id='{n}'][aria-current=true]"


class ContentError(Exception):
Expand Down Expand Up @@ -746,6 +747,18 @@ def highlight_ids(self) -> List[str]:
set([highlight.get_attribute("data-highlight-id") for highlight in self.highlights])
)

def highlight_focused(self, highlight_id) -> bool:
"""Return True if the highlight is focused.
:return: ``True`` if the highlight is focused
:rtype: bool
"""
focused_highlight_locator = self.find_elements(
By.CSS_SELECTOR, FOCUSED_HIGHLIGHT_LOCATOR.format(n=highlight_id)
)
return bool(focused_highlight_locator)

@property
def images(self) -> List[WebElement]:
"""Return the content images.
Expand Down
30 changes: 11 additions & 19 deletions pytest-selenium/tests/test_highlighting_56.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ def test_modal_for_unsaved_notes_appears_on_clicking_another_highlight(

assert book.content.highlight_box.is_open, "Highlight box not open"
assert book.content.highlight_box.is_edit_box
highlight = book.content.get_highlight(by_id=id_2)[0]
assert "focus" in highlight.get_attribute("class"), "highlight is not in focus"
assert book.content.highlight_focused(id_2), "highlight is not in focus"
assert book.content.highlight_box.note == note

# WHEN: click the 1st highlight again
Expand All @@ -79,8 +78,7 @@ def test_modal_for_unsaved_notes_appears_on_clicking_another_highlight(

# THEN: Unsaved note is abandoned and the highlight box is opened for the 1st highlight
assert book.content.highlight_box.is_open, "Highlight box not open"
highlight = book.content.get_highlight(by_id=id_1)[0]
assert "focus" in highlight.get_attribute("class"), "highlight is not in focus"
assert book.content.highlight_focused(id_1), "highlight is not in focus"
assert book.content.highlight_box.note == ""


Expand Down Expand Up @@ -127,8 +125,7 @@ def test_modal_for_unsaved_notes_appears_on_page_navigation_using_toc(
# THEN: The modal is closed and the unsaved note is retained on the page
assert book.content.highlight_box.is_open, "Highlight box not open"
assert book.content.highlight_box.is_edit_box
highlight = book.content.get_highlight(by_id=highlight_id)[0]
assert "focus" in highlight.get_attribute("class"), "highlight is not in focus"
assert book.content.highlight_focused(highlight_id), "highlight is not in focus"
assert book.content.highlight_box.note == note

# WHEN: Click the TOC link again
Expand Down Expand Up @@ -202,8 +199,7 @@ def test_modal_for_unsaved_notes_appears_on_page_navigation_using_prev_link(
# THEN: The modal is closed and the unsaved note is retained on the page
assert book.content.highlight_box.is_open, "Highlight box not open"
assert book.content.highlight_box.is_edit_box
highlight = book.content.get_highlight(by_id=highlight_id)[0]
assert "focus" in highlight.get_attribute("class"), "highlight is not in focus"
assert book.content.highlight_focused(highlight_id), "highlight is not in focus"
assert book.content.highlight_box.note == note

# WHEN: Click previous link again
Expand Down Expand Up @@ -277,8 +273,7 @@ def test_modal_for_unsaved_notes_appears_on_page_navigation_using_next_link(
# THEN: The modal is closed and the unsaved note is retained on the page
assert book.content.highlight_box.is_open, "Highlight box not open"
assert book.content.highlight_box.is_edit_box
highlight = book.content.get_highlight(by_id=highlight_id)[0]
assert "focus" in highlight.get_attribute("class"), "highlight is not in focus"
assert book.content.highlight_focused(highlight_id), "highlight is not in focus"
assert book.content.highlight_box.note == note

# WHEN: Click next link again
Expand Down Expand Up @@ -351,8 +346,7 @@ def test_modal_for_unsaved_notes_appears_on_clicking_book_title(
# THEN: The modal is closed and the unsaved note is retained on the page
assert book.content.highlight_box.is_open, "Highlight box not open"
assert book.content.highlight_box.is_edit_box
highlight = book.content.get_highlight(by_id=highlight_id)[0]
assert "focus" in highlight.get_attribute("class"), "highlight is not in focus"
assert book.content.highlight_focused(highlight_id), "highlight is not in focus"
assert book.content.highlight_box.note == note

# WHEN: Click on book title again
Expand Down Expand Up @@ -424,8 +418,7 @@ def test_modal_for_unsaved_notes_appears_on_selecting_new_text(
# THEN: The modal is closed and the unsaved note is retained in the page
assert book.content.highlight_box.is_open, "Highlight box not open"
assert book.content.highlight_box.is_edit_box
highlight = book.content.get_highlight(by_id=id_1)[0]
assert "focus" in highlight.get_attribute("class"), "highlight is not in focus"
assert book.content.highlight_focused(id_1), "highlight is not in focus"
assert book.content.highlight_box.note == note

# WHEN: Select some text in the page again
Expand Down Expand Up @@ -500,8 +493,7 @@ def test_modal_for_unsaved_notes_appears_on_clicking_search_result_same_page(
# THEN: The modal is closed and the unsaved note is retained in the page
assert book.content.highlight_box.is_open, "Highlight box not open"
assert book.content.highlight_box.is_edit_box
highlight = book.content.get_highlight(by_id=id_1)[0]
assert "focus" in highlight.get_attribute("class"), "highlight is not in focus"
assert book.content.highlight_focused(id_1), "highlight is not in focus"
assert book.content.highlight_box.note == note

# WHEN: Click the same search result again
Expand All @@ -512,6 +504,7 @@ def test_modal_for_unsaved_notes_appears_on_clicking_search_result_same_page(
book.wait_for_page_to_load()

# THEN: Unsaved note of the user highlight is abandoned
highlight = book.content.get_highlight(by_id=id_1)[0]
assert not selenium.execute_script(HAS_INDICATOR, highlight), "note is saved for the highlight"

# AND: The selected search result is highlighted
Expand Down Expand Up @@ -573,8 +566,7 @@ def test_modal_for_unsaved_notes_appears_on_clicking_search_result_different_pag
# THEN: The modal is closed and the unsaved note is retained in the page
assert book.content.highlight_box.is_open, "Highlight box not open"
assert book.content.highlight_box.is_edit_box
highlight = book.content.get_highlight(by_id=id_1)[0]
assert "focus" in highlight.get_attribute("class"), "highlight is not in focus"
assert book.content.highlight_focused(id_1), "highlight is not in focus"
assert book.content.highlight_box.note == note

# WHEN: Click the same search result again
Expand Down Expand Up @@ -654,7 +646,7 @@ def test_modal_for_unsaved_notes_appears_on_clicking_content_links(
assert book.content.highlight_box.is_open, "Highlight box not open"
assert book.content.highlight_box.is_edit_box
highlight = book.content.get_highlight(by_id=id_1)[0]
assert "focus" in highlight.get_attribute("class"), "highlight is not in focus"
assert book.content.highlight_focused(id_1), "highlight is not in focus"
assert book.content.highlight_box.note == note

# WHEN: Click the same link again
Expand Down
Loading

0 comments on commit 151ed1f

Please sign in to comment.