Skip to content

Commit fc3b601

Browse files
committed
Update data-test locators for preprints to eow rework
1 parent 87698f9 commit fc3b601

File tree

2 files changed

+32
-38
lines changed

2 files changed

+32
-38
lines changed

pages/preprints.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -266,14 +266,26 @@ class PreprintDetailPage(GuidBasePage, BasePreprintPage):
266266
url_base = urljoin(settings.OSF_HOME, '{guid}')
267267
identity = Locator(
268268
By.CSS_SELECTOR,
269-
'[data-analytics-scope="preprints detail page"]',
269+
'[data-test-preprint-header]',
270270
settings.LONG_TIMEOUT,
271271
)
272272

273273
# This locator needs a data-test-selector from software devs
274-
title = Locator(By.CSS_SELECTOR, 'h1', settings.LONG_TIMEOUT)
274+
title = Locator(
275+
By.CSS_SELECTOR, 'h1[data-test-preprint-title]', settings.LONG_TIMEOUT
276+
)
277+
view_page = Locator(By.ID, 'view-page')
278+
views_count = Locator(By.CSS_SELECTOR, '[data-test-view-count]')
279+
downloads_count = Locator(By.CSS_SELECTOR, '[data-test-download-count]')
280+
download_button = Locator(By.CSS_SELECTOR, '[data-test-download-button]')
281+
edit_preprint_button = Locator(By.CSS_SELECTOR, 'div[class="edit-preprint-button"]')
282+
default_citation = Locator(By.CSS_SELECTOR, '[data-test-default-citation="apa"]')
283+
response_404 = Locator(By.CSS_SELECTOR, 'pre[style]')
284+
285+
# Locators for the reviews app preprint detail page
275286
status = Locator(By.CSS_SELECTOR, 'span._status-badge_7ivjq4')
276287
status_explanation = Locator(By.CSS_SELECTOR, 'div.status-explanation')
288+
withdraw_reason = Locator(By.CSS_SELECTOR, '[data-test-withdrawal-justification]')
277289
make_decision_button = Locator(
278290
By.CSS_SELECTOR, 'button.btn.dropdown-toggle.btn-success'
279291
)
@@ -282,19 +294,11 @@ class PreprintDetailPage(GuidBasePage, BasePreprintPage):
282294
withdraw_radio_button = Locator(By.CSS_SELECTOR, 'input[value="withdrawn"]')
283295
reason_textarea = Locator(By.CSS_SELECTOR, 'textarea.form-control.ember-text-area')
284296
submit_decision_button = Locator(By.ID, 'submit-btn')
285-
view_page = Locator(By.ID, 'view-page')
286-
views_downloads_counts = Locator(
287-
By.CSS_SELECTOR, 'div.share-row.p-sm.osf-box-lt.clearfix > div'
288-
)
289-
download_button = Locator(
290-
By.CSS_SELECTOR, 'div.share-row.p-sm.osf-box-lt.clearfix > a'
291-
)
292-
edit_preprint_button = Locator(By.CSS_SELECTOR, 'div[class="edit-preprint-button"]')
293297

294298
# Group Locators
295299
subjects = GroupLocator(
296300
By.CSS_SELECTOR,
297-
'#view-page > div.container > div > div.col-md-5 > div:nth-child(6) > span',
301+
'[class="subject-preview"]',
298302
)
299303
tags = GroupLocator(By.CSS_SELECTOR, 'div.tag-section.p-t-xs > span')
300304

tests/test_preprints.py

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,6 @@ def test_reject_pre_moderated_preprint(
489489
page_not_found_page = PreprintPageNotFoundPage(driver, verify=True)
490490
assert page_not_found_page.page_header.text == 'Page not found'
491491

492-
@pytest.mark.skip
493-
# skip until bug is fixed [ENG-5055]
494492
def test_approve_withdrawal_request_pre_moderated_preprint(
495493
self, session, driver, log_in_if_not_already
496494
):
@@ -582,9 +580,8 @@ def test_approve_withdrawal_request_pre_moderated_preprint(
582580
assert PreprintDetailPage(driver, verify=True)
583581
WebDriverWait(driver, 5).until(EC.visibility_of(preprint_page.title))
584582
assert preprint_page.title.text == preprint_title
585-
assert (
586-
preprint_page.status_explanation.text == 'This preprint has been withdrawn.'
587-
)
583+
# Add assert for "This preprint has been withdrawn" after [ENG-5092] is fixed.
584+
assert preprint_page.withdraw_reason.present()
588585

589586
def test_decline_withdrawal_request_pre_moderated_preprint(
590587
self, session, driver, log_in_if_not_already
@@ -763,8 +760,6 @@ def test_accept_post_moderated_preprint(
763760
assert preprint_page.title.text == preprint_title
764761
assert provider_id in driver.current_url
765762

766-
@pytest.mark.skip
767-
# Skip until bug is fixed [ENG-5055]
768763
def test_moderator_withdrawal_post_moderated_preprint(
769764
self, session, driver, log_in_if_not_already
770765
):
@@ -849,12 +844,9 @@ def test_moderator_withdrawal_post_moderated_preprint(
849844
assert PreprintDetailPage(driver, verify=True)
850845
WebDriverWait(driver, 5).until(EC.visibility_of(preprint_page.title))
851846
assert preprint_page.title.text == preprint_title
852-
assert (
853-
preprint_page.status_explanation.text == 'This preprint has been withdrawn.'
854-
)
847+
# Add assert for "This preprint has been withdrawn" after [ENG-5092] is fixed.
848+
assert preprint_page.withdraw_reason.present()
855849

856-
@pytest.mark.skip
857-
# Skip until bug is fixed [ENG-5055]
858850
def test_approve_withdrawal_request_post_moderated_preprint(
859851
self, session, driver, log_in_if_not_already
860852
):
@@ -946,9 +938,8 @@ def test_approve_withdrawal_request_post_moderated_preprint(
946938
assert PreprintDetailPage(driver, verify=True)
947939
WebDriverWait(driver, 5).until(EC.visibility_of(preprint_page.title))
948940
assert preprint_page.title.text == preprint_title
949-
assert (
950-
preprint_page.status_explanation.text == 'This preprint has been withdrawn.'
951-
)
941+
# Add assert for "This preprint has been withdrawn" after [ENG-5092] is fixed.
942+
assert preprint_page.withdraw_reason.present()
952943

953944
def test_decline_withdrawal_request_post_moderated_preprint(
954945
self, session, driver, log_in_if_not_already
@@ -1089,8 +1080,6 @@ def test_preprint_detail_page(self, driver):
10891080

10901081
@markers.smoke_test
10911082
@markers.core_functionality
1092-
@pytest.mark.skip
1093-
# skip until we have reliable data test locators [ENG-5046]
10941083
class TestPreprintMetrics:
10951084
@pytest.fixture(scope='session')
10961085
def latest_preprint_node(self):
@@ -1107,12 +1096,16 @@ def test_preprint_views_count(self, driver, latest_preprint_node):
11071096
preprint_page = PreprintDetailPage(driver, guid=latest_preprint_node)
11081097
preprint_page.goto()
11091098
assert PreprintDetailPage(driver, verify=True)
1110-
match = re.search(
1111-
r'Views: (\d+) \| Downloads:', preprint_page.views_downloads_counts.text
1099+
1100+
# Preprint page shows a string on the front end and api returns a non-string value from the db
1101+
assert preprint_page.views_count.text == str(api_views_count)
1102+
# Wait for most of the page to finish loading before reloading page
1103+
WebDriverWait(driver, 10).until(
1104+
EC.visibility_of(preprint_page.default_citation)
11121105
)
1113-
assert match is not None
1114-
page_views_count = int(match.group(1))
1115-
assert api_views_count == page_views_count
1106+
# "response 404 (backend NotFound), service rules for the path non-existent"
1107+
# error message shows when the preprint fails to load
1108+
assert not preprint_page.response_404
11161109
# Don't reload the page in Production since we don't want to artificially
11171110
# inflate the metrics
11181111
if not settings.PRODUCTION:
@@ -1122,7 +1115,7 @@ def test_preprint_views_count(self, driver, latest_preprint_node):
11221115
# The initial load of the page above adds 1 to the views count, and the
11231116
# following reload adds a 2nd view to the count. But the update to the
11241117
# database can take a couple of seconds, so immediately accessing the api
1125-
# to get the count below may not show the 2nd view. Hence we are just
1118+
# to get the count below may not show the 2nd view. Hence, we are just
11261119
# checking that the views count did increase but not by how much.
11271120
# Unfortunately this means that we are not checking for any issues like
11281121
# double-counting.
@@ -1145,10 +1138,7 @@ def test_preprint_downloads_count(self, driver, latest_preprint_node):
11451138
preprint_page = PreprintDetailPage(driver, guid=latest_preprint_node)
11461139
preprint_page.goto()
11471140
assert PreprintDetailPage(driver, verify=True)
1148-
page_downloads_count = int(
1149-
preprint_page.views_downloads_counts.text.split('Downloads:')[1]
1150-
)
1151-
assert api_downloads_count == page_downloads_count
1141+
assert str(api_downloads_count) == preprint_page.downloads_count.text
11521142
# Don't download the Preprint in Production since we don't want to artificially
11531143
# inflate the metrics
11541144
if not settings.PRODUCTION:

0 commit comments

Comments
 (0)