From ebe69fe89bbf70edb9158f43dc43843379708aff Mon Sep 17 00:00:00 2001 From: Shtohryn Date: Wed, 5 Feb 2025 01:18:30 +0200 Subject: [PATCH 1/2] Fix test_institution_admin_dashboard --- pages/institutions.py | 50 ++++++++++++++++++++++++++------------ tests/test_institutions.py | 25 +++++++++---------- 2 files changed, 45 insertions(+), 30 deletions(-) diff --git a/pages/institutions.py b/pages/institutions.py index 6c7432cf..2902ed70 100644 --- a/pages/institutions.py +++ b/pages/institutions.py @@ -1,4 +1,7 @@ +import ipdb from selenium.webdriver.common.by import By +from selenium.webdriver.support import expected_conditions as EC +from selenium.webdriver.support.ui import WebDriverWait import settings from base.locators import ( @@ -58,19 +61,15 @@ class InstitutionAdminDashboardPage(BaseInstitutionPage): url_addition = '/dashboard' - identity = Locator(By.CSS_SELECTOR, 'div[data-analytics-scope="Dashboard"]') - loading_indicator = Locator(By.CSS_SELECTOR, '.ball-scale', settings.LONG_TIMEOUT) - departments_listbox_trigger = Locator( + identity = Locator(By.CSS_SELECTOR, '._institution-banner_kv000k') + loading_indicator = Locator(By.CSS_SELECTOR, '.ball-scale ball-dark _LoadingIndicator_k6n1c2', settings.LONG_TIMEOUT) + title_containers = GroupLocator( By.CSS_SELECTOR, - 'div.ember-basic-dropdown-trigger.ember-power-select-trigger._select_tdvp4z', + '._title-container_1d9vmx', ) - total_user_count = Locator( + total_project_count = GroupLocator( By.CSS_SELECTOR, - 'div.ember-view._panel_1dj7yu._sso-users-connected_1w5vdt > div > div._panel-body_1lht4i > div > h3', - ) - total_project_count = Locator( - By.CSS_SELECTOR, - 'div.ember-view._panel_1dj7yu._projects_1w5vdt > div > div._panel-body_1lht4i > div > div > h3', + '._kpi-container_1ge2xx', ) public_project_count = Locator( By.CSS_SELECTOR, 'div._projects-count_1ky9tx > span:nth-child(1) > strong' @@ -78,9 +77,8 @@ class InstitutionAdminDashboardPage(BaseInstitutionPage): private_project_count = Locator( By.CSS_SELECTOR, 'div._projects-count_1ky9tx > span:nth-child(2) > strong' ) - department_options = GroupLocator( - By.CSS_SELECTOR, 'ul.ember-power-select-options > li.ember-power-select-option' + By.CSS_SELECTOR, 'ul._data-list_1d9vmx > li._data-container_1d9vmx' ) user_table_rows = GroupLocator( By.CSS_SELECTOR, @@ -88,7 +86,27 @@ class InstitutionAdminDashboardPage(BaseInstitutionPage): ) def select_department_from_listbox(self, department): - for option in self.department_options: - if option.text == department: - option.click() - break + for element in self.department_options: + name_elem = element.find_element(By.CSS_SELECTOR, "div._name_1d9vmx") + if name_elem.text.strip() == department: + total_elem = element.find_element(By.CSS_SELECTOR, "div._total_1d9vmx") + return int(total_elem.text.strip()) + + def get_total_count_by_kpi_title(self, target_title): + for container in self.total_project_count: + title_element = container.find_element(By.CSS_SELECTOR, "._title_1ge2xx") + if title_element.text.strip() == target_title: + value_element = container.find_element(By.CSS_SELECTOR, "._total-container_1ge2xx") + 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, "._title_1d9vmx") + if title_element.text.strip() == section_title: + button = section.find_element(By.CSS_SELECTOR, "button._Button_6kisxq._FakeLink_6kisxq") + 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" + ) + diff --git a/tests/test_institutions.py b/tests/test_institutions.py index 33f14b55..186ba143 100644 --- a/tests/test_institutions.py +++ b/tests/test_institutions.py @@ -1,3 +1,4 @@ +import ipdb import pytest from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC @@ -45,18 +46,14 @@ def test_institution_admin_dashboard(self, driver, session, must_be_logged_in): dashboard_page.goto() assert InstitutionAdminDashboardPage(driver, verify=True) dashboard_page.loading_indicator.here_then_gone() - # Select 'QA' from Departments listbox and verify that the correct number # of users are displayed in the table - dashboard_page.departments_listbox_trigger.click() - dashboard_page.select_department_from_listbox('QA') - WebDriverWait(driver, 10).until( - EC.visibility_of_element_located((By.CSS_SELECTOR, '[data-test-item-name]')) - ) + dashboard_page.click_on_listbox_trigger('Total Users by Department') + user_table_rows = dashboard_page.select_department_from_listbox('QA') api_qa_users = osf_api.get_institution_users_per_department( session, institution_id='cos', department='QA' ) - assert len(dashboard_page.user_table_rows) == len(api_qa_users) + assert user_table_rows == len(api_qa_users) # Get metrics data using the OSF api metrics_data = osf_api.get_institution_metrics_summary( @@ -66,23 +63,23 @@ 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'] - dashboard_page.scroll_into_view(dashboard_page.total_project_count.element) + total_project_count = dashboard_page.get_total_count_by_kpi_title('OSF Public and Private Projects') # Verify Total User Count - displayed_user_count = dashboard_page.total_user_count.text + displayed_user_count = dashboard_page.get_total_count_by_kpi_title('Total Users') assert int(displayed_user_count) == api_user_count + dashboard_page.click_on_listbox_trigger('Public vs Private Projects') + # Verify Public Project Count - displayed_public_project_count = dashboard_page.public_project_count.text + displayed_public_project_count = dashboard_page.select_department_from_listbox('Public Projects') assert int(displayed_public_project_count) == api_public_project_count # Verify Private Project Count - displayed_private_project_count = dashboard_page.private_project_count.text + displayed_private_project_count = dashboard_page.select_department_from_listbox('Private Projects') assert int(displayed_private_project_count) == api_private_project_count # Verify Total Project Count - total_project_count = dashboard_page.total_project_count.text 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 ) From 29c77bf500ad930c9660104d4ec6ee8c4455f7a0 Mon Sep 17 00:00:00 2001 From: Shtohryn Date: Mon, 17 Feb 2025 19:21:49 +0200 Subject: [PATCH 2/2] Update locators --- pages/institutions.py | 29 ++++++++++++++--------------- tests/test_institutions.py | 15 +++++---------- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/pages/institutions.py b/pages/institutions.py index 2902ed70..97397367 100644 --- a/pages/institutions.py +++ b/pages/institutions.py @@ -1,6 +1,4 @@ -import ipdb from selenium.webdriver.common.by import By -from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.ui import WebDriverWait import settings @@ -61,13 +59,15 @@ class InstitutionAdminDashboardPage(BaseInstitutionPage): url_addition = '/dashboard' - identity = Locator(By.CSS_SELECTOR, '._institution-banner_kv000k') - loading_indicator = Locator(By.CSS_SELECTOR, '.ball-scale ball-dark _LoadingIndicator_k6n1c2', settings.LONG_TIMEOUT) + identity = Locator(By.CSS_SELECTOR, 'img[alt="Center For Open Science [Test]"]') + loading_indicator = Locator( + By.CSS_SELECTOR, '.ball-scale', settings.LONG_TIMEOUT + ) title_containers = GroupLocator( By.CSS_SELECTOR, '._title-container_1d9vmx', ) - total_project_count = GroupLocator( + kpi_container = GroupLocator( By.CSS_SELECTOR, '._kpi-container_1ge2xx', ) @@ -84,26 +84,25 @@ class InstitutionAdminDashboardPage(BaseInstitutionPage): By.CSS_SELECTOR, 'div._table-wrapper_1w5vdt > div > div.ember-view > div > div > table > tbody > tr', ) - - def select_department_from_listbox(self, department): + def get_expanded_total_by_expanded_name(self, department): for element in self.department_options: - name_elem = element.find_element(By.CSS_SELECTOR, "div._name_1d9vmx") + 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, "div._total_1d9vmx") + total_elem = element.find_element(By.CSS_SELECTOR, "[data-test-expanded-total]") return int(total_elem.text.strip()) - def get_total_count_by_kpi_title(self, target_title): - for container in self.total_project_count: - title_element = container.find_element(By.CSS_SELECTOR, "._title_1ge2xx") + 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]") if title_element.text.strip() == target_title: - value_element = container.find_element(By.CSS_SELECTOR, "._total-container_1ge2xx") + 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, "._title_1d9vmx") + 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, "button._Button_6kisxq._FakeLink_6kisxq") + 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( diff --git a/tests/test_institutions.py b/tests/test_institutions.py index 186ba143..244dafd2 100644 --- a/tests/test_institutions.py +++ b/tests/test_institutions.py @@ -1,9 +1,4 @@ -import ipdb import pytest -from selenium.webdriver.common.by import By -from selenium.webdriver.support import expected_conditions as EC -from selenium.webdriver.support.ui import WebDriverWait - import markers from api import osf_api from pages.institutions import ( @@ -49,7 +44,7 @@ def test_institution_admin_dashboard(self, driver, session, must_be_logged_in): # Select 'QA' from Departments listbox and verify that the correct number # of users are displayed in the table dashboard_page.click_on_listbox_trigger('Total Users by Department') - user_table_rows = dashboard_page.select_department_from_listbox('QA') + user_table_rows = dashboard_page.get_expanded_total_by_expanded_name('QA') api_qa_users = osf_api.get_institution_users_per_department( session, institution_id='cos', department='QA' ) @@ -63,20 +58,20 @@ 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_total_count_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_total_count_by_kpi_title('Total Users') + displayed_user_count = dashboard_page.get_kpi_data_by_kpi_title('Total Users') assert int(displayed_user_count) == api_user_count dashboard_page.click_on_listbox_trigger('Public vs Private Projects') # Verify Public Project Count - displayed_public_project_count = dashboard_page.select_department_from_listbox('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.select_department_from_listbox('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