Skip to content

Add assertions for OSFI affiliations on preprint rewiev and detail pages #284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions pages/preprints.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -100,6 +101,23 @@ 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]')
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:
Expand Down Expand Up @@ -180,13 +198,35 @@ 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,
'.modal-footer button.btn-success:nth-child(2)',
settings.LONG_TIMEOUT,
)

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]'
)

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}')
Expand Down
41 changes: 41 additions & 0 deletions tests/test_preprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]')
Expand Down Expand Up @@ -195,11 +203,32 @@ 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()
)
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()
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()
)
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')
supplemental_guid = utils.get_guid_from_url(supplemental_url, 3)
Expand Down Expand Up @@ -277,6 +306,10 @@ 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()
)
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'])
Expand Down Expand Up @@ -310,6 +343,14 @@ 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()
)
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
subject_found = False
Expand Down