Skip to content

Commit f3001f2

Browse files
authored
Merge pull request #275 from Shtogryn/pshtohryn/ENG-7020/fix/test_institution_admin_dashboard
Fix test_institution_admin_dashboard
2 parents b9e3457 + 29c77bf commit f3001f2

File tree

2 files changed

+43
-34
lines changed

2 files changed

+43
-34
lines changed

pages/institutions.py

+33-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from selenium.webdriver.common.by import By
2+
from selenium.webdriver.support.ui import WebDriverWait
23

34
import settings
45
from base.locators import (
@@ -58,37 +59,53 @@ class InstitutionAdminDashboardPage(BaseInstitutionPage):
5859

5960
url_addition = '/dashboard'
6061

61-
identity = Locator(By.CSS_SELECTOR, 'div[data-analytics-scope="Dashboard"]')
62-
loading_indicator = Locator(By.CSS_SELECTOR, '.ball-scale', settings.LONG_TIMEOUT)
63-
departments_listbox_trigger = Locator(
64-
By.CSS_SELECTOR,
65-
'div.ember-basic-dropdown-trigger.ember-power-select-trigger._select_tdvp4z',
62+
identity = Locator(By.CSS_SELECTOR, 'img[alt="Center For Open Science [Test]"]')
63+
loading_indicator = Locator(
64+
By.CSS_SELECTOR, '.ball-scale', settings.LONG_TIMEOUT
6665
)
67-
total_user_count = Locator(
66+
title_containers = GroupLocator(
6867
By.CSS_SELECTOR,
69-
'div.ember-view._panel_1dj7yu._sso-users-connected_1w5vdt > div > div._panel-body_1lht4i > div > h3',
68+
'._title-container_1d9vmx',
7069
)
71-
total_project_count = Locator(
70+
kpi_container = GroupLocator(
7271
By.CSS_SELECTOR,
73-
'div.ember-view._panel_1dj7yu._projects_1w5vdt > div > div._panel-body_1lht4i > div > div > h3',
72+
'._kpi-container_1ge2xx',
7473
)
7574
public_project_count = Locator(
7675
By.CSS_SELECTOR, 'div._projects-count_1ky9tx > span:nth-child(1) > strong'
7776
)
7877
private_project_count = Locator(
7978
By.CSS_SELECTOR, 'div._projects-count_1ky9tx > span:nth-child(2) > strong'
8079
)
81-
8280
department_options = GroupLocator(
83-
By.CSS_SELECTOR, 'ul.ember-power-select-options > li.ember-power-select-option'
81+
By.CSS_SELECTOR, 'ul._data-list_1d9vmx > li._data-container_1d9vmx'
8482
)
8583
user_table_rows = GroupLocator(
8684
By.CSS_SELECTOR,
8785
'div._table-wrapper_1w5vdt > div > div.ember-view > div > div > table > tbody > tr',
8886
)
87+
def get_expanded_total_by_expanded_name(self, department):
88+
for element in self.department_options:
89+
name_elem = element.find_element(By.CSS_SELECTOR, "[data-test-expanded-name]")
90+
if name_elem.text.strip() == department:
91+
total_elem = element.find_element(By.CSS_SELECTOR, "[data-test-expanded-total]")
92+
return int(total_elem.text.strip())
93+
94+
def get_kpi_data_by_kpi_title(self, target_title):
95+
for container in self.kpi_container:
96+
title_element = container.find_element(By.CSS_SELECTOR, "[data-test-kpi-title]")
97+
if title_element.text.strip() == target_title:
98+
value_element = container.find_element(By.CSS_SELECTOR, "[data-test-kpi-data]")
99+
return value_element.text.strip()
100+
101+
def click_on_listbox_trigger(self, section_title):
102+
for section in self.title_containers:
103+
title_element = section.find_element(By.CSS_SELECTOR, "[data-test-chart-title]")
104+
if title_element.text.strip() == section_title:
105+
button = section.find_element(By.CSS_SELECTOR, "[data-test-expand-additional-data]")
106+
icon = section.find_element(By.CSS_SELECTOR, "[data-test-toggle-icon]")
107+
button.click()
108+
WebDriverWait(self.driver, 10).until(
109+
lambda d: icon.get_attribute("data-icon") == "caret-up"
110+
)
89111

90-
def select_department_from_listbox(self, department):
91-
for option in self.department_options:
92-
if option.text == department:
93-
option.click()
94-
break

tests/test_institutions.py

+10-18
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
import pytest
2-
from selenium.webdriver.common.by import By
3-
from selenium.webdriver.support import expected_conditions as EC
4-
from selenium.webdriver.support.ui import WebDriverWait
5-
62
import markers
73
from api import osf_api
84
from pages.institutions import (
@@ -45,18 +41,14 @@ def test_institution_admin_dashboard(self, driver, session, must_be_logged_in):
4541
dashboard_page.goto()
4642
assert InstitutionAdminDashboardPage(driver, verify=True)
4743
dashboard_page.loading_indicator.here_then_gone()
48-
4944
# Select 'QA' from Departments listbox and verify that the correct number
5045
# of users are displayed in the table
51-
dashboard_page.departments_listbox_trigger.click()
52-
dashboard_page.select_department_from_listbox('QA')
53-
WebDriverWait(driver, 10).until(
54-
EC.visibility_of_element_located((By.CSS_SELECTOR, '[data-test-item-name]'))
55-
)
46+
dashboard_page.click_on_listbox_trigger('Total Users by Department')
47+
user_table_rows = dashboard_page.get_expanded_total_by_expanded_name('QA')
5648
api_qa_users = osf_api.get_institution_users_per_department(
5749
session, institution_id='cos', department='QA'
5850
)
59-
assert len(dashboard_page.user_table_rows) == len(api_qa_users)
51+
assert user_table_rows == len(api_qa_users)
6052

6153
# Get metrics data using the OSF api
6254
metrics_data = osf_api.get_institution_metrics_summary(
@@ -66,23 +58,23 @@ def test_institution_admin_dashboard(self, driver, session, must_be_logged_in):
6658
api_public_project_count = metrics_data['attributes']['public_project_count']
6759
api_private_project_count = metrics_data['attributes']['private_project_count']
6860

69-
dashboard_page.scroll_into_view(dashboard_page.total_project_count.element)
61+
total_project_count = dashboard_page.get_kpi_data_by_kpi_title('OSF Public and Private Projects')
7062

7163
# Verify Total User Count
72-
displayed_user_count = dashboard_page.total_user_count.text
64+
displayed_user_count = dashboard_page.get_kpi_data_by_kpi_title('Total Users')
7365
assert int(displayed_user_count) == api_user_count
7466

67+
dashboard_page.click_on_listbox_trigger('Public vs Private Projects')
68+
7569
# Verify Public Project Count
76-
displayed_public_project_count = dashboard_page.public_project_count.text
70+
displayed_public_project_count = dashboard_page.get_expanded_total_by_expanded_name('Public Projects')
7771
assert int(displayed_public_project_count) == api_public_project_count
7872

7973
# Verify Private Project Count
80-
displayed_private_project_count = dashboard_page.private_project_count.text
74+
displayed_private_project_count = dashboard_page.get_expanded_total_by_expanded_name('Private Projects')
8175
assert int(displayed_private_project_count) == api_private_project_count
8276

8377
# Verify Total Project Count
84-
total_project_count = dashboard_page.total_project_count.text
8578
assert (
86-
int(total_project_count)
87-
== api_public_project_count + api_private_project_count
79+
int(total_project_count) == api_public_project_count + api_private_project_count
8880
)

0 commit comments

Comments
 (0)