Skip to content

Commit

Permalink
Added new fixture method registration_details_page_with_resource for …
Browse files Browse the repository at this point in the history
…edit and delete tests
  • Loading branch information
Ramya Virajamangala authored and jh27539 committed Jun 11, 2024
1 parent 0c877b7 commit 78bba40
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 58 deletions.
3 changes: 3 additions & 0 deletions pages/registries.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ class RegistrationDetailPage(BaseSubmittedRegistrationPage):
open_practice_resource_data = Locator(By.CSS_SELECTOR, '[data-test-resource-link]')
add_resource_button = Locator(By.CSS_SELECTOR, 'button[aria-label="Add resource"]')
doi_input_field = Locator(By.XPATH, '//input[@name="pid"]')
resource_list = Locator(
By.XPATH, '//li[text()="This registration has no resources."]'
)
resource_type_dropdown = Locator(
By.CSS_SELECTOR, '[data-test-power-select-dropdown]'
)
Expand Down
88 changes: 30 additions & 58 deletions tests/test_registration_sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,17 @@ def registration_details_page(self, driver, registration_guid):
registration_details_page.goto()
return registration_details_page

@pytest.fixture()
def registration_details_page_with_resource(self, driver, registration_guid):
registration_details_page = RegistrationDetailPage(
driver, guid=registration_guid
)
osf_api.create_registration_resource(registration_guid, resource_type='Data')
registration_details_page.goto()
return registration_details_page

def create_new_resource(
self, driver, registration_guid, registration_details_page, resource_type
self, registration_guid, registration_details_page, resource_type
):
"""This method creates new resource of the type given for the given registration"""
doi = '10.17605'
Expand Down Expand Up @@ -138,9 +147,7 @@ def test_add_new_resource_data(
)
)

self.create_new_resource(
self, driver, registration_details_page, resource_type='Data'
)
self.create_new_resource(self, registration_details_page, resource_type='Data')

data_resource = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, '//li/p[text()="Data"]'))
Expand All @@ -149,78 +156,43 @@ def test_add_new_resource_data(
osf_api.delete_registration_resource(registration_guid)

def test_edit_resource_data(
self, driver, registration_details_page, registration_guid, fake
self, driver, registration_details_page_with_resource, registration_guid, fake
):
"""This test updates the description of data output resource for a given registration"""
resource_description = fake.sentence(nb_words=1)
registration_details_page.open_practice_resource_data.click()
# Verify n and delete the resource if already exists
resource_id = osf_api.get_registration_resource_id(
registration_id=registration_guid
)
if resource_id is not None:
osf_api.delete_registration_resource(registration_guid)
registration_details_page.reload()
WebDriverWait(driver, 10).until(
EC.invisibility_of_element_located((By.XPATH, '//li/p[text()="Data"]'))
)

osf_api.create_registration_resource(registration_guid, resource_type='Data')
registration_details_page.reload()
WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, '//li/p[text()="Data"]'))
)
registration_details_page.resource_type_edit_button.click()
registration_details_page.resource_description.click()
registration_details_page.resource_description.clear()
registration_details_page.resource_description.send_keys(resource_description)
registration_details_page.save_button.click()
registration_details_page_with_resource.open_practice_resource_data.click()

registration_details_page.reload()
WebDriverWait(driver, 5).until(
EC.presence_of_element_located((By.XPATH, '//li/p[text()="Data"]'))
registration_details_page_with_resource.resource_type_edit_button.click()
registration_details_page_with_resource.resource_description.click()
registration_details_page_with_resource.resource_description.clear()
registration_details_page_with_resource.resource_description.send_keys(
resource_description
)
registration_details_page_with_resource.save_button.click()
assert (
registration_details_page.resource_card_description.text
registration_details_page_with_resource.resource_card_description.text
== resource_description
)
osf_api.delete_registration_resource(registration_guid)

def test_delete_resource_data(
self, driver, registration_details_page, registration_guid, fake
self, driver, registration_details_page_with_resource, registration_guid, fake
):
"""This test verifies delete functionality of data output resource for a registration"""

registration_details_page.open_practice_resource_data.click()
# Verify and delete the resource if already exists
resource_id = osf_api.get_registration_resource_id(
registration_id=registration_guid
)
if resource_id is not None:
osf_api.delete_registration_resource(registration_guid)
registration_details_page.reload()
WebDriverWait(driver, 10).until(
EC.invisibility_of_element_located((By.XPATH, '//li/p[text()="Data"]'))
)
registration_details_page_with_resource.open_practice_resource_data.click()

osf_api.create_registration_resource(registration_guid, resource_type='Data')
registration_details_page.reload()
WebDriverWait(driver, 5).until(
EC.visibility_of_element_located((By.XPATH, '//li/p[text()="Data"]'))
)
registration_details_page_with_resource.resource_type_delete_button.click()
registration_details_page_with_resource.resource_type_delete_confirm.click()

orig_data_icon_color = driver.find_element_by_css_selector(
'img[data-analytics-name="data"]'
).get_attribute('src')
registration_details_page.resource_type_delete_button.click()
registration_details_page.resource_type_delete_confirm.click()
registration_details_page.reload()
registration_details_page_with_resource.reload()
WebDriverWait(driver, 10).until(
EC.visibility_of_element_located(
(By.CSS_SELECTOR, '[data-test-add-resource-section]')
)
)
new_data_icon_color = driver.find_element_by_css_selector(
'img[data-analytics-name="data"]'
).get_attribute('src')
assert new_data_icon_color != orig_data_icon_color

assert (
registration_details_page_with_resource.resource_list.text
== 'This registration has no resources.'
)

0 comments on commit 78bba40

Please sign in to comment.