Skip to content

Commit 1d38228

Browse files
authored
adding rex search QA tests (#2469)
1 parent 823937e commit 1d38228

File tree

2 files changed

+131
-1
lines changed

2 files changed

+131
-1
lines changed

playwright/e2e/ui/pages/home.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def book_toc_content(self):
6666

6767
@property
6868
def book_toc_slideout_is_visible(self):
69-
return self.page.locator("div.toc-slideout-contents")
69+
return self.page.get_by_test_id("toc")
7070

7171
@property
7272
def book_link(self):
@@ -542,3 +542,37 @@ def incorrect_page_error_is_visible(self):
542542
@property
543543
def incorrect_page_error_text(self):
544544
return self.page.locator("main > div > p")
545+
546+
# Content search
547+
548+
@property
549+
def content_search_field_is_visible(self):
550+
return self.page.get_by_test_id("desktop-search-input")
551+
552+
@pytest.mark.asyncio
553+
async def click_search(self):
554+
await self.content_search_field_is_visible.click()
555+
556+
@pytest.mark.asyncio
557+
async def click_search_icon(self):
558+
await self.page.get_by_title("Search").click()
559+
560+
@pytest.mark.asyncio
561+
async def fill_search_field(self, value):
562+
await self.content_search_field_is_visible.fill(value)
563+
564+
@property
565+
def search_result_is_visible(self):
566+
return self.page.get_by_test_id("search-results-sidebar")
567+
568+
@pytest.mark.asyncio
569+
async def close_unsuccessful_search_result_sidebar(self):
570+
await self.page.locator("div.styled__SearchResultsBar-as3fh1-4.hpndbT > div > h2 > div > button").click()
571+
572+
@pytest.mark.asyncio
573+
async def close_successful_search_result_sidebar(self):
574+
await self.page.get_by_test_id("close-search").click()
575+
576+
@pytest.mark.asyncio
577+
async def click_first_search_result(self):
578+
await self.page.locator("details > ol > li > a:nth-child(2)").first.click()

playwright/e2e/ui/test_search.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import pytest
2+
3+
from e2e.ui.pages.home import HomeRex
4+
5+
import asyncio
6+
7+
8+
@pytest.mark.asyncio
9+
@pytest.mark.parametrize("book_slug, page_slug", [("astronomy-2e", "9-3-impact-craters")])
10+
async def test_unsuccessful_search(chrome_page, base_url, book_slug, page_slug, rex_user, rex_password):
11+
12+
# GIVEN: Playwright, chromium and the rex_base_url
13+
14+
# WHEN: The Home page is fully loaded
15+
await chrome_page.goto(f"{base_url}/books/{book_slug}/pages/{page_slug}")
16+
home = HomeRex(chrome_page)
17+
18+
assert home.content_search_field_is_visible
19+
20+
await home.click_search()
21+
22+
await home.fill_search_field("mmmxxx11")
23+
24+
# THEN: No search results are shown
25+
26+
await chrome_page.keyboard.press("Enter")
27+
28+
assert "Sorry, no results found for " in await home.search_result_is_visible.inner_text()
29+
30+
assert "Preface" not in await home.book_toc_slideout_is_visible.inner_text()
31+
32+
await home.close_unsuccessful_search_result_sidebar()
33+
34+
assert "Preface" in await home.book_toc_slideout_is_visible.inner_text()
35+
36+
37+
@pytest.mark.asyncio
38+
@pytest.mark.parametrize("book_slug, page_slug", [("astronomy-2e", "9-3-impact-craters")])
39+
async def test_successful_search(chrome_page, base_url, book_slug, page_slug, rex_user, rex_password):
40+
41+
# GIVEN: Playwright, chromium and the rex_base_url
42+
43+
# WHEN: The Home page is fully loaded
44+
await chrome_page.goto(f"{base_url}/books/{book_slug}/pages/{page_slug}")
45+
home = HomeRex(chrome_page)
46+
47+
assert home.content_search_field_is_visible
48+
49+
await home.click_search()
50+
51+
await home.fill_search_field('“cannibal galaxy”')
52+
53+
# THEN: Search results are shown
54+
55+
await chrome_page.keyboard.press("Enter")
56+
57+
assert "4 search results for " in await home.search_result_is_visible.inner_text()
58+
59+
assert '“cannibal galaxy”' in await home.search_result_is_visible.inner_text()
60+
61+
await home.close_successful_search_result_sidebar()
62+
63+
assert "4 search results for " not in await home.book_toc_slideout_is_visible.inner_text()
64+
65+
66+
@pytest.mark.asyncio
67+
@pytest.mark.parametrize("book_slug, page_slug", [("astronomy-2e", "9-3-impact-craters")])
68+
async def test_search_result(chrome_page, base_url, book_slug, page_slug, rex_user, rex_password):
69+
70+
# GIVEN: Playwright, chromium and the rex_base_url
71+
72+
# WHEN: The Home page is fully loaded
73+
await chrome_page.goto(f"{base_url}/books/{book_slug}/pages/{page_slug}")
74+
home = HomeRex(chrome_page)
75+
76+
assert home.content_search_field_is_visible
77+
78+
await home.click_search()
79+
80+
await home.fill_search_field('“cannibal galaxy”')
81+
82+
# THEN: Search results are shown
83+
84+
await chrome_page.keyboard.press("Enter")
85+
86+
assert "6.2 Telescopes Today" in await home.search_result_is_visible.inner_text()
87+
88+
await home.click_first_search_result()
89+
90+
# THEN: Correct page opens with the correct search result
91+
92+
if home.content_page_black_overlay_is_visible:
93+
await home.click_content_page_black_overlay_close()
94+
95+
assert "6.2 Telescopes Today" in await chrome_page.title()
96+
assert "cannibal galaxy" in await chrome_page.content()

0 commit comments

Comments
 (0)