Skip to content
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
22 changes: 22 additions & 0 deletions base/expected_conditions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from selenium.common.exceptions import StaleElementReferenceException
from selenium.webdriver.remote.webdriver import WebDriver
from selenium.webdriver.support import expected_conditions as EC


Expand Down Expand Up @@ -25,3 +27,23 @@ def __init__(self, page_index):

def __call__(self, driver):
return len(driver.window_handles) > self.page_index


class text_to_be_present_in_elements(object):
"""An expectation for checking if the given text is present in the
specified element.
locator, text
"""

def __init__(self, locator, text_):
self.locator = locator
self.text = text_

def __call__(self, driver: WebDriver):
try:
return any(
self.text in element.text
for element in driver.find_elements(*self.locator)
)
except StaleElementReferenceException:
return False
84 changes: 0 additions & 84 deletions pages/counter.java

This file was deleted.

38 changes: 24 additions & 14 deletions pages/institutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ class InstitutionAdminDashboardPage(BaseInstitutionPage):
url_addition = '/dashboard'

identity = Locator(By.CSS_SELECTOR, 'img[alt="Center For Open Science [Test]"]')
loading_indicator = Locator(
By.CSS_SELECTOR, '.ball-scale', settings.LONG_TIMEOUT
)
loading_indicator = Locator(By.CSS_SELECTOR, '.ball-scale', settings.LONG_TIMEOUT)
title_containers = GroupLocator(
By.CSS_SELECTOR,
'._title-container_1d9vmx',
Expand All @@ -84,28 +82,40 @@ class InstitutionAdminDashboardPage(BaseInstitutionPage):
By.CSS_SELECTOR,
'div._table-wrapper_1w5vdt > div > div.ember-view > div > div > table > tbody > tr',
)

def get_expanded_total_by_expanded_name(self, department):
for element in self.department_options:
name_elem = element.find_element(By.CSS_SELECTOR, "[data-test-expanded-name]")
if name_elem.text.strip() == department:
total_elem = element.find_element(By.CSS_SELECTOR, "[data-test-expanded-total]")
for element in self.department_options:
name_elem = element.find_element(
By.CSS_SELECTOR, '[data-test-expanded-name]'
)
if name_elem.text.strip() == department:
total_elem = element.find_element(
By.CSS_SELECTOR, '[data-test-expanded-total]'
)
return int(total_elem.text.strip())

def get_kpi_data_by_kpi_title(self, target_title):
for container in self.kpi_container:
title_element = container.find_element(By.CSS_SELECTOR, "[data-test-kpi-title]")
title_element = container.find_element(
By.CSS_SELECTOR, '[data-test-kpi-title]'
)
if title_element.text.strip() == target_title:
value_element = container.find_element(By.CSS_SELECTOR, "[data-test-kpi-data]")
value_element = container.find_element(
By.CSS_SELECTOR, '[data-test-kpi-data]'
)
return value_element.text.strip()

def click_on_listbox_trigger(self, section_title):
for section in self.title_containers:
title_element = section.find_element(By.CSS_SELECTOR, "[data-test-chart-title]")
title_element = section.find_element(
By.CSS_SELECTOR, '[data-test-chart-title]'
)
if title_element.text.strip() == section_title:
button = section.find_element(By.CSS_SELECTOR, "[data-test-expand-additional-data]")
icon = section.find_element(By.CSS_SELECTOR, "[data-test-toggle-icon]")
button = section.find_element(
By.CSS_SELECTOR, '[data-test-expand-additional-data]'
)
icon = section.find_element(By.CSS_SELECTOR, '[data-test-toggle-icon]')
button.click()
WebDriverWait(self.driver, 10).until(
lambda d: icon.get_attribute("data-icon") == "caret-up"
lambda d: icon.get_attribute('data-icon') == 'caret-up'
)

17 changes: 11 additions & 6 deletions pages/preprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import pytest
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait

import settings
from base.expected_conditions import text_to_be_present_in_elements
from base.locators import (
ComponentLocator,
GroupLocator,
Expand Down Expand Up @@ -113,19 +115,22 @@ def select_from_dropdown_listbox(self, selection):
)

def select_top_level_subject(self, selection):
subject_selector = 'div[data-analytics-scope="Browse"] > ul > li'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could this be constructed from top_level_subjects, which has the same selector, but is a GroupLocator? I wonder if there's a .first method or something like that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't found the method like this one in GroupLocator()

wait = WebDriverWait(self.driver, 5)
wait.until(
text_to_be_present_in_elements(
(By.CSS_SELECTOR, subject_selector), selection
)
)
for subject in self.top_level_subjects:
if subject.text == selection:
# Find the checkbox element and click it to select the subject
checkbox = subject.find_element_by_css_selector(
'input.ember-checkbox.ember-view'
)
checkbox.click()
subject.click()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: does this work? I always remember checkboxes being difficult to trigger a click on. If this works, awesome!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works.

break

first_selected_subject = Locator(By.CSS_SELECTOR, 'li[data-test-selected-subject]')
basics_tags_section = Locator(By.CSS_SELECTOR, '[data-test-no-tags]')
basics_tags_input = Locator(
By.CSS_SELECTOR, 'input[aria-label="Add a tag to enhance discoverability"]'
By.CSS_SELECTOR, 'input[placeholder="Add a tag to enhance discoverability"]'
)
# Author Assertions Page
conflict_of_interest_yes = Locator(
Expand Down
16 changes: 12 additions & 4 deletions tests/test_institutions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest

import markers
from api import osf_api
from pages.institutions import (
Expand Down Expand Up @@ -58,7 +59,9 @@ def test_institution_admin_dashboard(self, driver, session, must_be_logged_in):
api_public_project_count = metrics_data['attributes']['public_project_count']
api_private_project_count = metrics_data['attributes']['private_project_count']

total_project_count = dashboard_page.get_kpi_data_by_kpi_title('OSF Public and Private Projects')
total_project_count = dashboard_page.get_kpi_data_by_kpi_title(
'OSF Public and Private Projects'
)

# Verify Total User Count
displayed_user_count = dashboard_page.get_kpi_data_by_kpi_title('Total Users')
Expand All @@ -67,14 +70,19 @@ def test_institution_admin_dashboard(self, driver, session, must_be_logged_in):
dashboard_page.click_on_listbox_trigger('Public vs Private Projects')

# Verify Public Project Count
displayed_public_project_count = dashboard_page.get_expanded_total_by_expanded_name('Public Projects')
displayed_public_project_count = (
dashboard_page.get_expanded_total_by_expanded_name('Public Projects')
)
assert int(displayed_public_project_count) == api_public_project_count

# Verify Private Project Count
displayed_private_project_count = dashboard_page.get_expanded_total_by_expanded_name('Private Projects')
displayed_private_project_count = (
dashboard_page.get_expanded_total_by_expanded_name('Private Projects')
)
assert int(displayed_private_project_count) == api_private_project_count

# Verify Total Project Count
assert (
int(total_project_count) == api_public_project_count + api_private_project_count
int(total_project_count)
== api_public_project_count + api_private_project_count
)
26 changes: 11 additions & 15 deletions tests/test_preprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,34 +277,30 @@ 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.next_button.click()

# Next add another subject in the Discipline section
WebDriverWait(driver, 5).until(
EC.visibility_of_element_located(
(
By.CSS_SELECTOR,
'div.ember-tabs__tab-panel.ember-tabs__tab-panel--selected > div >ul >li>label > input',
)
)
)
edit_page.scroll_into_view(edit_page.basics_tags_input.element)
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'])
edit_page.basics_tags_input.send_keys(Keys.RETURN)
# Click Return to preprint button to go back to Preprint Detail page

body = driver.find_element(By.TAG_NAME, 'body')
body.send_keys(Keys.HOME)
WebDriverWait(driver, 5).until(
EC.invisibility_of_element_located((By.CLASS_NAME, 'toast-success'))
)
WebDriverWait(driver, 5).until(
EC.visibility_of_element_located(
(By.CSS_SELECTOR, '[data-test-next-button]')
)
)
edit_page.next_button.click()
WebDriverWait(driver, 5).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, '[data-test-next-button]'))
)

edit_page.next_button.click()
WebDriverWait(driver, 5).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, '[data-test-next-button]'))
)

edit_page.next_button.click()
WebDriverWait(driver, 5).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, '[data-test-submit-button]'))
Expand Down