Skip to content

Commit 0fdd942

Browse files
authored
Merge pull request #273 from Shtogryn/pshtohryn/ENG-6071/fix/select_top_level_subject
Fix select_top_level_subject() method
2 parents f3001f2 + f637a4c commit 0fdd942

6 files changed

+80
-123
lines changed

base/expected_conditions.py

+22
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from selenium.common.exceptions import StaleElementReferenceException
2+
from selenium.webdriver.remote.webdriver import WebDriver
13
from selenium.webdriver.support import expected_conditions as EC
24

35

@@ -25,3 +27,23 @@ def __init__(self, page_index):
2527

2628
def __call__(self, driver):
2729
return len(driver.window_handles) > self.page_index
30+
31+
32+
class text_to_be_present_in_elements(object):
33+
"""An expectation for checking if the given text is present in the
34+
specified element.
35+
locator, text
36+
"""
37+
38+
def __init__(self, locator, text_):
39+
self.locator = locator
40+
self.text = text_
41+
42+
def __call__(self, driver: WebDriver):
43+
try:
44+
return any(
45+
self.text in element.text
46+
for element in driver.find_elements(*self.locator)
47+
)
48+
except StaleElementReferenceException:
49+
return False

pages/counter.java

-84
This file was deleted.

pages/institutions.py

+24-14
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ class InstitutionAdminDashboardPage(BaseInstitutionPage):
6060
url_addition = '/dashboard'
6161

6262
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
65-
)
63+
loading_indicator = Locator(By.CSS_SELECTOR, '.ball-scale', settings.LONG_TIMEOUT)
6664
title_containers = GroupLocator(
6765
By.CSS_SELECTOR,
6866
'._title-container_1d9vmx',
@@ -84,28 +82,40 @@ class InstitutionAdminDashboardPage(BaseInstitutionPage):
8482
By.CSS_SELECTOR,
8583
'div._table-wrapper_1w5vdt > div > div.ember-view > div > div > table > tbody > tr',
8684
)
85+
8786
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]")
87+
for element in self.department_options:
88+
name_elem = element.find_element(
89+
By.CSS_SELECTOR, '[data-test-expanded-name]'
90+
)
91+
if name_elem.text.strip() == department:
92+
total_elem = element.find_element(
93+
By.CSS_SELECTOR, '[data-test-expanded-total]'
94+
)
9295
return int(total_elem.text.strip())
9396

9497
def get_kpi_data_by_kpi_title(self, target_title):
9598
for container in self.kpi_container:
96-
title_element = container.find_element(By.CSS_SELECTOR, "[data-test-kpi-title]")
99+
title_element = container.find_element(
100+
By.CSS_SELECTOR, '[data-test-kpi-title]'
101+
)
97102
if title_element.text.strip() == target_title:
98-
value_element = container.find_element(By.CSS_SELECTOR, "[data-test-kpi-data]")
103+
value_element = container.find_element(
104+
By.CSS_SELECTOR, '[data-test-kpi-data]'
105+
)
99106
return value_element.text.strip()
100107

101108
def click_on_listbox_trigger(self, section_title):
102109
for section in self.title_containers:
103-
title_element = section.find_element(By.CSS_SELECTOR, "[data-test-chart-title]")
110+
title_element = section.find_element(
111+
By.CSS_SELECTOR, '[data-test-chart-title]'
112+
)
104113
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]")
114+
button = section.find_element(
115+
By.CSS_SELECTOR, '[data-test-expand-additional-data]'
116+
)
117+
icon = section.find_element(By.CSS_SELECTOR, '[data-test-toggle-icon]')
107118
button.click()
108119
WebDriverWait(self.driver, 10).until(
109-
lambda d: icon.get_attribute("data-icon") == "caret-up"
120+
lambda d: icon.get_attribute('data-icon') == 'caret-up'
110121
)
111-

pages/preprints.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import pytest
44
from selenium.webdriver.common.by import By
5+
from selenium.webdriver.support.wait import WebDriverWait
56

67
import settings
8+
from base.expected_conditions import text_to_be_present_in_elements
79
from base.locators import (
810
ComponentLocator,
911
GroupLocator,
@@ -113,19 +115,22 @@ def select_from_dropdown_listbox(self, selection):
113115
)
114116

115117
def select_top_level_subject(self, selection):
118+
subject_selector = 'div[data-analytics-scope="Browse"] > ul > li'
119+
wait = WebDriverWait(self.driver, 5)
120+
wait.until(
121+
text_to_be_present_in_elements(
122+
(By.CSS_SELECTOR, subject_selector), selection
123+
)
124+
)
116125
for subject in self.top_level_subjects:
117126
if subject.text == selection:
118-
# Find the checkbox element and click it to select the subject
119-
checkbox = subject.find_element_by_css_selector(
120-
'input.ember-checkbox.ember-view'
121-
)
122-
checkbox.click()
127+
subject.click()
123128
break
124129

125130
first_selected_subject = Locator(By.CSS_SELECTOR, 'li[data-test-selected-subject]')
126131
basics_tags_section = Locator(By.CSS_SELECTOR, '[data-test-no-tags]')
127132
basics_tags_input = Locator(
128-
By.CSS_SELECTOR, 'input[aria-label="Add a tag to enhance discoverability"]'
133+
By.CSS_SELECTOR, 'input[placeholder="Add a tag to enhance discoverability"]'
129134
)
130135
# Author Assertions Page
131136
conflict_of_interest_yes = Locator(

tests/test_institutions.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
23
import markers
34
from api import osf_api
45
from pages.institutions import (
@@ -58,7 +59,9 @@ def test_institution_admin_dashboard(self, driver, session, must_be_logged_in):
5859
api_public_project_count = metrics_data['attributes']['public_project_count']
5960
api_private_project_count = metrics_data['attributes']['private_project_count']
6061

61-
total_project_count = dashboard_page.get_kpi_data_by_kpi_title('OSF Public and Private Projects')
62+
total_project_count = dashboard_page.get_kpi_data_by_kpi_title(
63+
'OSF Public and Private Projects'
64+
)
6265

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

6972
# Verify Public Project Count
70-
displayed_public_project_count = dashboard_page.get_expanded_total_by_expanded_name('Public Projects')
73+
displayed_public_project_count = (
74+
dashboard_page.get_expanded_total_by_expanded_name('Public Projects')
75+
)
7176
assert int(displayed_public_project_count) == api_public_project_count
7277

7378
# Verify Private Project Count
74-
displayed_private_project_count = dashboard_page.get_expanded_total_by_expanded_name('Private Projects')
79+
displayed_private_project_count = (
80+
dashboard_page.get_expanded_total_by_expanded_name('Private Projects')
81+
)
7582
assert int(displayed_private_project_count) == api_private_project_count
7683

7784
# Verify Total Project Count
7885
assert (
79-
int(total_project_count) == api_public_project_count + api_private_project_count
86+
int(total_project_count)
87+
== api_public_project_count + api_private_project_count
8088
)

tests/test_preprints.py

+11-15
Original file line numberDiff line numberDiff line change
@@ -277,34 +277,30 @@ def test_edit_preprint(self, session, driver, preprint_detail_page):
277277
WebDriverWait(driver, 5).until(
278278
EC.visibility_of_element_located((By.CSS_SELECTOR, '[data-test-title]'))
279279
)
280-
edit_page.next_button.click()
281-
282-
# Next add another subject in the Discipline section
283-
WebDriverWait(driver, 5).until(
284-
EC.visibility_of_element_located(
285-
(
286-
By.CSS_SELECTOR,
287-
'div.ember-tabs__tab-panel.ember-tabs__tab-panel--selected > div >ul >li>label > input',
288-
)
289-
)
290-
)
291-
edit_page.scroll_into_view(edit_page.basics_tags_input.element)
292280
edit_page.select_top_level_subject('Business')
293-
294281
# Add another Tag and click the Save and continue button
295282
edit_page.basics_tags_input.send_keys(os.environ['PYTEST_CURRENT_TEST'])
296283
edit_page.basics_tags_input.send_keys(Keys.RETURN)
297284
# Click Return to preprint button to go back to Preprint Detail page
285+
286+
body = driver.find_element(By.TAG_NAME, 'body')
287+
body.send_keys(Keys.HOME)
288+
WebDriverWait(driver, 5).until(
289+
EC.invisibility_of_element_located((By.CLASS_NAME, 'toast-success'))
290+
)
291+
WebDriverWait(driver, 5).until(
292+
EC.visibility_of_element_located(
293+
(By.CSS_SELECTOR, '[data-test-next-button]')
294+
)
295+
)
298296
edit_page.next_button.click()
299297
WebDriverWait(driver, 5).until(
300298
EC.element_to_be_clickable((By.CSS_SELECTOR, '[data-test-next-button]'))
301299
)
302-
303300
edit_page.next_button.click()
304301
WebDriverWait(driver, 5).until(
305302
EC.element_to_be_clickable((By.CSS_SELECTOR, '[data-test-next-button]'))
306303
)
307-
308304
edit_page.next_button.click()
309305
WebDriverWait(driver, 5).until(
310306
EC.element_to_be_clickable((By.CSS_SELECTOR, '[data-test-submit-button]'))

0 commit comments

Comments
 (0)