Skip to content

Commit 4c11ca1

Browse files
committed
Add a11y tests for Registration Files Pages
1 parent d4c240a commit 4c11ca1

File tree

4 files changed

+149
-2
lines changed

4 files changed

+149
-2
lines changed

pages/registrations.py

+11
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class MyRegistrationsPage(OSFBasePage):
3434
draft_registration_cards = GroupLocator(
3535
By.CSS_SELECTOR, 'div[data-test-draft-registration-card]'
3636
)
37+
registration_cards = GroupLocator(By.CSS_SELECTOR, 'div[data-test-node-card]')
3738

3839
def get_first_draft_id_by_template(self, template_name):
3940
for draft_card in self.draft_registration_cards:
@@ -44,3 +45,13 @@ def get_first_draft_id_by_template(self, template_name):
4445
).get_attribute('href')
4546
draft_id = url.split('drafts/', 1)[1]
4647
return draft_id
48+
49+
def get_node_id_by_title(self, title):
50+
for registration_card in self.registration_cards:
51+
node_title = registration_card.find_element_by_css_selector(
52+
'[data-test-node-title]'
53+
)
54+
if title in node_title.text:
55+
url = node_title.get_attribute('href')
56+
node_id = url.split('osf.io/', 1)[1]
57+
return node_id

pages/registries.py

+24-1
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,34 @@ def get_first_non_withdrawn_registration(self):
6565
)
6666

6767

68-
class RegistrationDetailPage(GuidBasePage):
68+
class BaseSubmittedRegistrationPage(GuidBasePage):
69+
base_url = settings.OSF_HOME
70+
url_addition = ''
71+
72+
@property
73+
def url(self):
74+
return self.base_url + '/' + self.guid + '/' + self.url_addition
75+
76+
77+
class RegistrationDetailPage(BaseSubmittedRegistrationPage):
78+
"""This is the Registration Overview Page"""
79+
6980
identity = Locator(By.CSS_SELECTOR, '[data-test-registration-title]')
7081
loading_indicator = Locator(By.CSS_SELECTOR, '.ball-scale', settings.LONG_TIMEOUT)
7182

7283

84+
class RegistrationFileListPage(BaseSubmittedRegistrationPage):
85+
url_addition = 'files'
86+
identity = Locator(By.CSS_SELECTOR, '[data-test-file-providers-list]')
87+
file_list_button = Locator(By.CSS_SELECTOR, '[data-test-file-list-link]')
88+
loading_indicator = Locator(By.CSS_SELECTOR, '.ball-scale')
89+
first_file_link = Locator(By.CSS_SELECTOR, '[data-analytics-name="Open file"]')
90+
91+
92+
class RegistrationFileDetailPage(GuidBasePage):
93+
identity = Locator(By.CSS_SELECTOR, '[data-test-file-renderer')
94+
95+
7396
class RegistrationAddNewPage(BaseRegistriesPage):
7497
url_addition = 'new'
7598
identity = Locator(

tests/test_a11y_registries.py

+107
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
DraftRegistrationReviewPage,
1717
RegistrationAddNewPage,
1818
RegistrationDetailPage,
19+
RegistrationFileDetailPage,
20+
RegistrationFileListPage,
1921
RegistriesDiscoverPage,
2022
RegistriesLandingPage,
2123
RegistriesModerationModeratorsPage,
@@ -155,6 +157,111 @@ def log_in_as_user_with_draft_registrations(driver):
155157
)
156158

157159

160+
# User with registrations is not setup in production
161+
@markers.dont_run_on_prod
162+
class TestSubmittedRegistrationPages:
163+
@pytest.fixture()
164+
def my_registrations_page(self, driver, log_in_as_user_with_draft_registrations):
165+
"""Fixture that logs in as a user that already has submitted registrations
166+
and navigates to the My Registrations page from which the desired registration
167+
can be selected.
168+
"""
169+
my_registrations_page = MyRegistrationsPage(driver)
170+
my_registrations_page.goto()
171+
# Wait for registration cards to load on page
172+
WebDriverWait(driver, 5).until(
173+
EC.presence_of_element_located((By.CSS_SELECTOR, '[data-test-node-card]'))
174+
)
175+
registration_cards = my_registrations_page.registration_cards
176+
assert registration_cards
177+
return my_registrations_page
178+
179+
@markers.ember_page
180+
def test_accessibility_files_list_page(
181+
self, driver, session, write_files, exclude_best_practice, my_registrations_page
182+
):
183+
"""This test is for checking the accessibility of the Registration File List
184+
Page of a submitted registration. First search through the registration cards
185+
on the Submitted tab of the My Registration Page for the registration that has
186+
files (searching by registration title). When you find the desired registration
187+
get the registration node id from its link and then use the node id to navigate
188+
to the Files List page for this registration.
189+
"""
190+
registration_node = my_registrations_page.get_node_id_by_title(
191+
'Registration With Files for A11y Testing'
192+
)
193+
registration_file_list_page = RegistrationFileListPage(
194+
driver, guid=registration_node
195+
)
196+
registration_file_list_page.goto()
197+
assert RegistrationFileListPage(driver, verify=True)
198+
# Click the 'Archive of OSF Storage' button to expand the list of files
199+
registration_file_list_page.file_list_button.click()
200+
# Wait for file list items to load on page
201+
WebDriverWait(driver, 5).until(
202+
EC.presence_of_element_located(
203+
(By.CSS_SELECTOR, '[data-test-file-list-item]')
204+
)
205+
)
206+
a11y.run_axe(
207+
driver,
208+
session,
209+
'regfilelist',
210+
write_files=write_files,
211+
exclude_best_practice=exclude_best_practice,
212+
)
213+
214+
@markers.ember_page
215+
def test_accessibility_file_detail_page(
216+
self, driver, session, write_files, exclude_best_practice, my_registrations_page
217+
):
218+
"""This test is for checking the accessibility of the Registration File Detail
219+
Page of a submitted registration. First search through the registration cards
220+
on the Submitted tab of the My Registration Page for the registration that has
221+
files (searching by registration title). When you find the desired registration
222+
get the registration node id from its link and then use the node id to navigate
223+
to the Files List page for this registration. Then click the first file link
224+
to open the File Detail page for that file.
225+
"""
226+
registration_node = my_registrations_page.get_node_id_by_title(
227+
'Registration With Files for A11y Testing'
228+
)
229+
registration_file_list_page = RegistrationFileListPage(
230+
driver, guid=registration_node
231+
)
232+
registration_file_list_page.goto()
233+
assert RegistrationFileListPage(driver, verify=True)
234+
# Click the 'Archive of OSF Storage' button to expand the list of files
235+
registration_file_list_page.file_list_button.click()
236+
# Wait for file list items to load on page
237+
WebDriverWait(driver, 5).until(
238+
EC.presence_of_element_located(
239+
(By.CSS_SELECTOR, '[data-test-file-list-item]')
240+
)
241+
)
242+
# Click the first file from the list to open the File Detail page in a new tab
243+
registration_file_list_page.scroll_into_view(
244+
registration_file_list_page.first_file_link.element
245+
)
246+
registration_file_list_page.first_file_link.click()
247+
# Wait for the new tab to open - window count should then = 2
248+
WebDriverWait(driver, 5).until(EC.number_of_windows_to_be(2))
249+
# Switch focus to the new tab
250+
driver.switch_to.window(driver.window_handles[1])
251+
assert RegistrationFileDetailPage(driver)
252+
# Wait for File Renderer to load
253+
WebDriverWait(driver, 5).until(
254+
EC.visibility_of_element_located((By.CSS_SELECTOR, 'iframe'))
255+
)
256+
a11y.run_axe(
257+
driver,
258+
session,
259+
'regfiledet',
260+
write_files=write_files,
261+
exclude_best_practice=exclude_best_practice,
262+
)
263+
264+
158265
# User with registrations is not setup in production
159266
@markers.dont_run_on_prod
160267
class TestDraftRegistrationPages:

utils.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def launch_driver(driver_name=settings.DRIVER, desired_capabilities=None):
6363
driver = driver_cls(chrome_options=chrome_options)
6464
elif driver_name == 'Firefox' and not settings.HEADLESS:
6565
from selenium.webdriver import FirefoxProfile
66+
from selenium.webdriver.firefox.options import Options
6667

6768
ffp = FirefoxProfile()
6869
# Set the default download location [0=Desktop, 1=Downloads, 2=Specified location]
@@ -74,7 +75,12 @@ def launch_driver(driver_name=settings.DRIVER, desired_capabilities=None):
7475
'text/plain, application/octet-stream, application/binary, text/csv, application/csv, '
7576
'application/excel, text/comma-separated-values, text/xml, application/xml',
7677
)
77-
driver = driver_cls(firefox_profile=ffp)
78+
# Force Firefox to open links in new tab instead of new browser window. Have to
79+
# use Options instead of Firefox Profile because the profile preference doesn't
80+
# work.
81+
ffo = Options()
82+
ffo.set_preference('browser.link.open_newwindow', 3)
83+
driver = driver_cls(firefox_profile=ffp, options=ffo)
7884
elif driver_name == 'Edge' and not settings.HEADLESS:
7985
from msedge.selenium_tools import Edge
8086

0 commit comments

Comments
 (0)