From 00a90489a13bad6ad51b38ca45b585557fbea5b5 Mon Sep 17 00:00:00 2001 From: Shtohryn <pavlo.stogryn@gmail.com> Date: Tue, 20 May 2025 02:21:42 +0300 Subject: [PATCH 1/5] Add assertions for OSFI affiliations on preprint rewiev and detail pages --- pages/preprints.py | 19 +++++++++++++++++++ tests/test_preprints.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/pages/preprints.py b/pages/preprints.py index a2a3358c..6f0b193d 100644 --- a/pages/preprints.py +++ b/pages/preprints.py @@ -100,6 +100,10 @@ class PreprintSubmitPage(BasePreprintPage): By.CSS_SELECTOR, '#ember-basic-dropdown-wormhole > div > ul >li.ember-power-select-option', ) + affiliated_institutions = GroupLocator(By.CSS_SELECTOR, '[data-test-institution]') + + def get_affiliated_institutions(self) -> list: + return [el.text for el in self.affiliated_institutions] def select_from_dropdown_listbox(self, selection): for option in self.dropdown_options: @@ -180,6 +184,10 @@ def select_top_level_subject(self, selection): By.CSS_SELECTOR, '[data-test-create-project-submit]' ) + # Review Page + preprint_institution_list_review = GroupLocator( + By.CSS_SELECTOR, 'img[data-test-preprint-institution-list]' + ) create_preprint_button = Locator(By.CSS_SELECTOR, '[data-test-submit-button]') modal_create_preprint_button = Locator( By.CSS_SELECTOR, @@ -187,6 +195,17 @@ def select_top_level_subject(self, selection): settings.LONG_TIMEOUT, ) + def get_preprint_institution_list_review(self) -> list: + return [el.get_attribute('alt') for el in self.preprint_institution_list_review] + + # Preprint Detail Page + preprint_institution_list_detail = GroupLocator( + By.CSS_SELECTOR, 'img[data-test-preprint-institution-list]' + ) + + def get_preprint_institution_list_detail(self) -> list: + return [el.get_attribute('alt') for el in self.preprint_institution_list_detail] + class PreprintEditPage(PreprintSubmitPage): url_base = urljoin(settings.OSF_HOME, '{guid}') diff --git a/tests/test_preprints.py b/tests/test_preprints.py index 2a31aec6..b525ac7d 100644 --- a/tests/test_preprints.py +++ b/tests/test_preprints.py @@ -99,6 +99,14 @@ def test_create_preprint_from_landing( submit_page.next_button.click() # Metadata page + WebDriverWait(driver, 5).until( + EC.visibility_of_element_located( + (By.CSS_SELECTOR, '[data-test-institution]') + ) + ) + affiliated_institutions_names_metadata_page = ( + submit_page.get_affiliated_institutions() + ) WebDriverWait(driver, 5).until( EC.element_to_be_clickable( (By.CSS_SELECTOR, '[data-test-power-select-dropdown]') @@ -195,11 +203,38 @@ def test_create_preprint_from_landing( submit_page.supplemental_project_create_button.click() submit_page.info_toast.here_then_gone() submit_page.next_button.click() + WebDriverWait(driver, 5).until( + EC.visibility_of_element_located( + (By.CSS_SELECTOR, 'img[data-test-preprint-institution-list]') + ) + ) + affiliated_institutions_names_review_page = ( + submit_page.get_preprint_institution_list_review() + ) + assert ( + affiliated_institutions_names_metadata_page + == affiliated_institutions_names_review_page + ), ( + f'Affiliated institutions on the Review Page do not match expected values.\n' + f'Expected: {affiliated_institutions_names_metadata_page }\n' + f'Actual: {affiliated_institutions_names_review_page}' + ) submit_page.info_toast.here_then_gone() submit_page.create_preprint_button.click() preprint_detail = PreprintDetailPage(driver, verify=True) WebDriverWait(driver, 10).until(EC.visibility_of(preprint_detail.title)) assert preprint_detail.title.text == 'Selenium Test Preprint' + affiliated_institutions_names_detail_page = ( + submit_page.get_preprint_institution_list_detail() + ) + assert ( + affiliated_institutions_names_metadata_page + == affiliated_institutions_names_detail_page + ), ( + f'Affiliated institutions on the Preprint Detail Page do not match expected values.\n' + f'Expected: {affiliated_institutions_names_metadata_page }\n' + f'Actual: {affiliated_institutions_names_detail_page}' + ) # Capture guid of supplemental materials project created during workflow supplemental_url = preprint_detail.view_page.get_attribute('href') supplemental_guid = utils.get_guid_from_url(supplemental_url, 3) From 3442888664a3c973bf90a29674abaffde2b2b04c Mon Sep 17 00:00:00 2001 From: Shtohryn <pavlo.stogryn@gmail.com> Date: Wed, 21 May 2025 00:38:02 +0300 Subject: [PATCH 2/5] Add assertions for OSFI affiliations in test_edit_preprint --- tests/test_preprints.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test_preprints.py b/tests/test_preprints.py index b525ac7d..883aff9f 100644 --- a/tests/test_preprints.py +++ b/tests/test_preprints.py @@ -312,6 +312,9 @@ def test_edit_preprint(self, session, driver, preprint_detail_page): WebDriverWait(driver, 5).until( EC.visibility_of_element_located((By.CSS_SELECTOR, '[data-test-title]')) ) + affiliated_institutions_names_metadata_page = ( + edit_page.get_affiliated_institutions() + ) edit_page.select_top_level_subject('Business') # Add another Tag and click the Save and continue button edit_page.basics_tags_input.send_keys(os.environ['PYTEST_CURRENT_TEST']) @@ -345,6 +348,17 @@ def test_edit_preprint(self, session, driver, preprint_detail_page): # Verify Title and Abstract assert detail_page.title.text == 'Selenium Preprint Edit' assert detail_page.abstract.text == 'Testing Selenium Abstract edit' + affiliated_institutions_names_detail_page = ( + edit_page.get_preprint_institution_list_detail() + ) + assert ( + affiliated_institutions_names_metadata_page + == affiliated_institutions_names_detail_page + ), ( + f'Affiliated institutions on the Preprint Detail Page do not match expected values.\n' + f'Expected: {affiliated_institutions_names_metadata_page}\n' + f'Actual: {affiliated_institutions_names_detail_page}' + ) # Verify new Subject appears on the page subjects = detail_page.subjects subject_found = False From 52abc939ac7b955b567657a443b4ce7dc307a4be Mon Sep 17 00:00:00 2001 From: Shtohryn <pavlo.stogryn@gmail.com> Date: Thu, 29 May 2025 02:02:14 +0300 Subject: [PATCH 3/5] add new method select_all_affiliated_institutions() --- pages/preprints.py | 14 ++++++++++++++ tests/test_preprints.py | 1 + 2 files changed, 15 insertions(+) diff --git a/pages/preprints.py b/pages/preprints.py index 6f0b193d..e1eff91c 100644 --- a/pages/preprints.py +++ b/pages/preprints.py @@ -1,6 +1,7 @@ from urllib.parse import urljoin import pytest +import selenium.webdriver.support.expected_conditions as EC from selenium.webdriver.common.by import By from selenium.webdriver.support.wait import WebDriverWait @@ -101,10 +102,23 @@ class PreprintSubmitPage(BasePreprintPage): '#ember-basic-dropdown-wormhole > div > ul >li.ember-power-select-option', ) affiliated_institutions = GroupLocator(By.CSS_SELECTOR, '[data-test-institution]') + affiliated_institutions_input_lst = GroupLocator( + By.CSS_SELECTOR, '[data-test-institution-input]' + ) def get_affiliated_institutions(self) -> list: return [el.text for el in self.affiliated_institutions] + def select_all_affiliated_institutions(self): + wait = WebDriverWait(self.driver, 5) + wait.until( + EC.element_to_be_clickable( + (By.CSS_SELECTOR, '[data-test-institution-input]') + ) + ) + for subject in self.affiliated_institutions_input_lst: + subject.click() + def select_from_dropdown_listbox(self, selection): for option in self.dropdown_options: if option.text == selection: diff --git a/tests/test_preprints.py b/tests/test_preprints.py index 883aff9f..363dbc04 100644 --- a/tests/test_preprints.py +++ b/tests/test_preprints.py @@ -312,6 +312,7 @@ def test_edit_preprint(self, session, driver, preprint_detail_page): WebDriverWait(driver, 5).until( EC.visibility_of_element_located((By.CSS_SELECTOR, '[data-test-title]')) ) + edit_page.select_all_affiliated_institutions() affiliated_institutions_names_metadata_page = ( edit_page.get_affiliated_institutions() ) From 3d8d4a6c33d7b0017798ab2b544bb22b2dfdc228 Mon Sep 17 00:00:00 2001 From: Shtohryn <pavlo.stogryn@gmail.com> Date: Mon, 9 Jun 2025 20:10:47 +0300 Subject: [PATCH 4/5] Refactor assertions to reusable function for affiliated institutions --- pages/preprints.py | 7 +++++++ tests/test_preprints.py | 22 ++++++++-------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/pages/preprints.py b/pages/preprints.py index 95acf8d0..16d534e7 100644 --- a/pages/preprints.py +++ b/pages/preprints.py @@ -212,6 +212,13 @@ def select_top_level_subject(self, selection): def get_preprint_institution_list_review(self) -> list: return [el.get_attribute('alt') for el in self.preprint_institution_list_review] + def assert_affiliated_institutions_equal(self, expected, actual, page_name): + assert expected == actual, ( + f'Affiliated institutions on the {page_name} do not match expected values.\n' + f'Expected: {expected}\n' + f'Actual: {actual}' + ) + # Preprint Detail Page preprint_institution_list_detail = GroupLocator( By.CSS_SELECTOR, 'img[data-test-preprint-institution-list]' diff --git a/tests/test_preprints.py b/tests/test_preprints.py index 46fc0493..f38ee396 100644 --- a/tests/test_preprints.py +++ b/tests/test_preprints.py @@ -211,13 +211,10 @@ def test_create_preprint_from_landing( affiliated_institutions_names_review_page = ( submit_page.get_preprint_institution_list_review() ) - assert ( - affiliated_institutions_names_metadata_page - == affiliated_institutions_names_review_page - ), ( - f'Affiliated institutions on the Review Page do not match expected values.\n' - f'Expected: {affiliated_institutions_names_metadata_page }\n' - f'Actual: {affiliated_institutions_names_review_page}' + submit_page.assert_affiliated_institutions_equal( + affiliated_institutions_names_metadata_page, + affiliated_institutions_names_review_page, + 'Preprint Review Page', ) submit_page.info_toast.here_then_gone() submit_page.create_preprint_button.click() @@ -227,13 +224,10 @@ def test_create_preprint_from_landing( affiliated_institutions_names_detail_page = ( submit_page.get_preprint_institution_list_detail() ) - assert ( - affiliated_institutions_names_metadata_page - == affiliated_institutions_names_detail_page - ), ( - f'Affiliated institutions on the Preprint Detail Page do not match expected values.\n' - f'Expected: {affiliated_institutions_names_metadata_page }\n' - f'Actual: {affiliated_institutions_names_detail_page}' + submit_page.assert_affiliated_institutions_equal( + affiliated_institutions_names_metadata_page, + affiliated_institutions_names_detail_page, + 'Preprint Detail Page', ) # Capture guid of supplemental materials project created during workflow supplemental_url = preprint_detail.view_page.get_attribute('href') From c5b8ff28e65205630e8545de46c9ca3756b62746 Mon Sep 17 00:00:00 2001 From: Shtohryn <pavlo.stogryn@gmail.com> Date: Mon, 9 Jun 2025 20:19:07 +0300 Subject: [PATCH 5/5] Refactor test_edit_preprint assertions to reusable function for affiliated institutions --- tests/test_preprints.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tests/test_preprints.py b/tests/test_preprints.py index f38ee396..58173724 100644 --- a/tests/test_preprints.py +++ b/tests/test_preprints.py @@ -346,13 +346,10 @@ def test_edit_preprint(self, session, driver, preprint_detail_page): affiliated_institutions_names_detail_page = ( edit_page.get_preprint_institution_list_detail() ) - assert ( - affiliated_institutions_names_metadata_page - == affiliated_institutions_names_detail_page - ), ( - f'Affiliated institutions on the Preprint Detail Page do not match expected values.\n' - f'Expected: {affiliated_institutions_names_metadata_page}\n' - f'Actual: {affiliated_institutions_names_detail_page}' + edit_page.assert_affiliated_institutions_equal( + affiliated_institutions_names_metadata_page, + affiliated_institutions_names_detail_page, + 'Preprint Detail Page', ) # Verify new Subject appears on the page subjects = detail_page.subjects