Skip to content

Commit faa62dd

Browse files
authored
osweb qa tests to complete existing rex tests (#2570)
* page object changes/updates as per review
1 parent f1b4de9 commit faa62dd

File tree

6 files changed

+221
-25
lines changed

6 files changed

+221
-25
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import pytest
2+
import asyncio
3+
4+
from e2e.ui.pages.home import HomeRex
5+
6+
7+
@pytest.mark.asyncio
8+
async def test_osweb_homepage_loads(chrome_page, base_url):
9+
10+
# GIVEN: Playwright, chromium and the rex_base_url
11+
12+
# WHEN: The Home page is fully loaded
13+
await chrome_page.goto(base_url)
14+
home = HomeRex(chrome_page)
15+
16+
# THEN: Openstax logo and osweb homepage sections are is visible
17+
assert await home.main_menu_and_openstax_logo_is_visible()
18+
assert await home.osweb_homepage_content_sections()
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import pytest
2+
import asyncio
3+
4+
from e2e.ui.pages.home import HomeRex
5+
6+
7+
@pytest.mark.asyncio
8+
async def test_subjects_books_pages_load(chrome_page, base_url):
9+
# GIVEN: Playwright, chromium and the rex_base_url
10+
11+
# WHEN: The Home page is fully loaded
12+
await chrome_page.goto(base_url)
13+
home = HomeRex(chrome_page)
14+
15+
await home.click_subjects_page_menu()
16+
17+
# THEN: Subjects list shows and subjects pages load
18+
scount = await home.subjects_list.count()
19+
20+
for i in range(scount):
21+
item = home.subjects_list.nth(i)
22+
hrefs = await item.get_attribute("href")
23+
slink = f"{base_url}{hrefs}"
24+
25+
slink_resp = await chrome_page.goto(slink)
26+
27+
assert slink_resp.status == 200
28+
29+
try:
30+
assert await home.subjects_intro()
31+
32+
except AssertionError:
33+
continue
34+
35+
else:
36+
mhrefs = hrefs.replace("/subjects/", "")
37+
mod_hrefs = mhrefs.replace("-", " ")
38+
39+
assert await home.subjects_title() in mod_hrefs
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import pytest
2+
import asyncio
3+
4+
from e2e.ui.pages.home import HomeRex
5+
6+
7+
@pytest.mark.asyncio
8+
async def test_subjects_footer(chrome_page, base_url):
9+
10+
# GIVEN: Playwright, chromium and the rex_base_url
11+
12+
# WHEN: The Home page is fully loaded
13+
await chrome_page.goto(base_url)
14+
home = HomeRex(chrome_page)
15+
16+
await home.click_subjects_page_menu()
17+
18+
await home.click_subjects_homepage_link()
19+
20+
# THEN: Footer section loads
21+
assert await home.footer_section()
22+
23+
assert await home.footer_section_help_is_visible()
24+
assert await home.footer_section_openstax_is_visible()
25+
assert await home.footer_section_policies_is_visible()
26+
27+
assert await home.footer_section_bottom_is_visible()
28+
29+
assert ("Rice University" in await home.footer_section_bottom.inner_text()
30+
and "license" in await home.footer_section_bottom.inner_text())
31+
32+
assert "https://creativecommons.org" in await home.footer_section_license_link()
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import pytest
2+
import asyncio
3+
4+
from e2e.ui.pages.home import HomeRex
5+
6+
7+
@pytest.mark.asyncio
8+
async def test_subjects_homepage(chrome_page, base_url):
9+
10+
# GIVEN: Playwright, chromium and the rex_base_url
11+
12+
# WHEN: The Home page is fully loaded
13+
await chrome_page.goto(base_url)
14+
home = HomeRex(chrome_page)
15+
16+
assert await home.subjects_page_menu()
17+
18+
await home.click_subjects_page_menu()
19+
20+
await home.click_subjects_homepage_link()
21+
22+
subjects_list = ["Business", "College Success", "Computer Science", "Humanities", "Math", "Nursing",
23+
"Science", "Social Sciences"]
24+
25+
# THEN: Book subjects homepage opens
26+
assert "English, Spanish, and Polish" in await home.language_selector_section.inner_text()
27+
28+
for subject in subjects_list:
29+
assert subject in await home.subjects_listing_section.inner_text()
30+
31+
about = await home.about_openstax_section.inner_text()
32+
assert "about openstax textbooks" in about.lower()
33+
34+
await home.click_learn_about_openstax_link()
35+
36+
assert f"{base_url}/about" == chrome_page.url
37+
assert ("Who we are" in await home.about_page.inner_text() and "What we do" in await home.about_page.inner_text()
38+
and "Where we're going" in await home.about_page.inner_text())
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import pytest
2+
import asyncio
3+
4+
from e2e.ui.pages.home import HomeRex
5+
6+
7+
@pytest.mark.asyncio
8+
async def test_subjects_philanthropic_support(chrome_page, base_url):
9+
10+
# GIVEN: Playwright, chromium and the rex_base_url
11+
12+
# WHEN: The Home page is fully loaded
13+
await chrome_page.goto(base_url)
14+
home = HomeRex(chrome_page)
15+
16+
await home.click_subjects_page_menu()
17+
18+
await home.click_subjects_homepage_link()
19+
20+
assert await home.philanthropic_support_section()
21+
22+
# THEN: Philanthropic support section opens
23+
await home.click_our_impact_link()
24+
25+
assert f"{base_url}/impact" == chrome_page.url
26+
27+
assert await home.give_today_link_is_visible()
28+
29+
async with chrome_page.expect_popup() as popup_info:
30+
await home.click_give_today_link()
31+
32+
new_tab = await popup_info.value
33+
34+
assert "riceconnect.rice.edu/donation/support-openstax-" in new_tab.url

playwright/e2e/ui/pages/home.py

Lines changed: 60 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,31 @@ def __init__(self, page):
1616
async def click_openstax_logo(self):
1717
await self.page.get_by_test_id("navbar").get_by_role("img").click()
1818

19-
# Subjects homepage
19+
@pytest.mark.asyncio
20+
async def main_menu_and_openstax_logo_is_visible(self):
21+
return await self.page.locator("div.menus.desktop > nav.nav").is_visible()
22+
23+
@pytest.mark.asyncio
24+
async def osweb_homepage_content_is_visible(self):
25+
return await self.page.locator("main > section:nth-child(5)").is_visible()
2026

2127
@property
22-
def subjects_page_menu(self):
23-
return self.page.get_by_role("button", name="Subjects")
28+
def osweb_homepage_sections(self):
29+
return self.page.locator("main")
30+
31+
@pytest.mark.asyncio
32+
async def osweb_homepage_content_sections(self):
33+
return await self.page.locator(f"main > section:nth-child(5)").is_visible()
34+
35+
# Subjects homepage
36+
37+
@pytest.mark.asyncio
38+
async def subjects_page_menu(self):
39+
return await self.page.get_by_role("button", name="Subjects").is_visible()
2440

2541
@pytest.mark.asyncio
2642
async def click_subjects_page_menu(self):
27-
await self.subjects_page_menu.hover()
43+
await self.page.get_by_role("button", name="Subjects").hover()
2844

2945
@property
3046
def subjects_homepage_link(self):
@@ -118,6 +134,22 @@ async def click_instructor_resources_tab(self):
118134
async def click_student_resources_tab(self):
119135
await self.page.locator("id=Student resources-tab").click()
120136

137+
@pytest.mark.asyncio
138+
async def click_subjects_science_link(self):
139+
await self.subjects_science_link.click()
140+
141+
@property
142+
def subjects_list(self):
143+
return self.page.locator("#ddId-Subjects > a")
144+
145+
@pytest.mark.asyncio
146+
async def subjects_intro(self):
147+
return await self.page.locator("section.subject-intro").is_visible()
148+
149+
@pytest.mark.asyncio
150+
async def subjects_title(self):
151+
return (await self.page.locator("section.subject-intro > div > h1").inner_text()).lower()
152+
121153
# Highlights and Notes
122154

123155
@property
@@ -212,9 +244,9 @@ async def close_giving_tuesday_popup(self):
212244

213245
# Philanthropic support
214246

215-
@property
216-
def philanthropic_support_section(self):
217-
return self.page.locator("section.philanthropic-support")
247+
@pytest.mark.asyncio
248+
async def philanthropic_support_section(self):
249+
return await self.page.locator("section.philanthropic-support").is_visible()
218250

219251
@property
220252
def our_impact_link(self):
@@ -224,37 +256,40 @@ def our_impact_link(self):
224256
async def click_our_impact_link(self):
225257
await self.our_impact_link.click()
226258

227-
@property
228-
def give_today_link_is_visible(self):
229-
return self.page.locator("#footer").get_by_role("link", name="Give today")
259+
@pytest.mark.asyncio
260+
async def give_today_link_is_visible(self):
261+
return await self.page.locator("#footer").get_by_role("link", name="Give today").is_visible()
230262

231263
@pytest.mark.asyncio
232264
async def click_give_today_link(self):
233-
await self.give_today_link_is_visible.click()
265+
await self.page.locator("#footer").get_by_role("link", name="Give today").click()
234266

235267
# Subjects page footer section
236268

237-
@property
238-
def footer_section(self):
239-
return self.page.locator("id=footer")
269+
@pytest.mark.asyncio
270+
async def footer_section(self):
271+
return await self.page.locator("id=footer").is_visible()
240272

241-
@property
242-
def footer_section_help_is_visible(self):
243-
return self.page.locator("div.column.col1")
273+
@pytest.mark.asyncio
274+
async def footer_section_help_is_visible(self):
275+
return await self.page.locator("div.column.col1").is_visible()
244276

245-
@property
246-
def footer_section_openstax_is_visible(self):
247-
return self.page.locator("div.column.col2")
277+
@pytest.mark.asyncio
278+
async def footer_section_openstax_is_visible(self):
279+
return await self.page.locator("div.column.col2").is_visible()
248280

249-
@property
250-
def footer_section_policies_is_visible(self):
251-
return self.page.locator("div.column.col3")
281+
@pytest.mark.asyncio
282+
async def footer_section_policies_is_visible(self):
283+
return await self.page.locator("div.column.col3").is_visible()
284+
285+
@pytest.mark.asyncio
286+
async def footer_section_bottom_is_visible(self):
287+
return await self.page.locator("div.bottom").is_visible()
252288

253289
@property
254-
def footer_section_bottom_is_visible(self):
290+
def footer_section_bottom(self):
255291
return self.page.locator("div.bottom")
256292

257-
@property
258293
@pytest.mark.asyncio
259294
async def footer_section_license_link(self):
260295
return await self.page.locator("div.copyrights").get_by_role("link").get_attribute("href")

0 commit comments

Comments
 (0)