Skip to content

Commit a7cc840

Browse files
committed
ENG-8210: Stabilize preprint downloads/views count tests by decoupling API and UI checks
1 parent 69d0c9c commit a7cc840

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

tests/test_preprints.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,9 +1219,12 @@ def test_preprint_views_count(self, driver, latest_preprint_node):
12191219
count value displayed on the page. Also verifying that the views count will
12201220
be incremented if the page is reloaded (only in testing environments).
12211221
"""
1222-
api_views_count = osf_api.get_preprint_views_count(node_id=latest_preprint_node)
1222+
api_views_count_before = osf_api.get_preprint_views_count(
1223+
node_id=latest_preprint_node
1224+
)
12231225
preprint_page = PreprintDetailPage(driver, guid=latest_preprint_node)
12241226
preprint_page.goto()
1227+
ui_view_count_before = int(preprint_page.views_count.text)
12251228
assert PreprintDetailPage(driver, verify=True)
12261229

12271230
# Don't reload the page in Production since we don't want to artificially
@@ -1237,11 +1240,16 @@ def test_preprint_views_count(self, driver, latest_preprint_node):
12371240
# checking that the views count did increase but not by how much.
12381241
# Unfortunately this means that we are not checking for any issues like
12391242
# double-counting.
1240-
preprint_page.reload()
1241-
assert (
1242-
osf_api.get_preprint_views_count(node_id=latest_preprint_node)
1243-
> api_views_count
1243+
preprint_page.goto()
1244+
WebDriverWait(driver, settings.TIMEOUT).until(
1245+
EC.visibility_of(preprint_page.views_count)
12441246
)
1247+
api_views_count_after = osf_api.get_preprint_views_count(
1248+
node_id=latest_preprint_node
1249+
)
1250+
ui_view_count_after = int(preprint_page.views_count.text)
1251+
assert ui_view_count_after == ui_view_count_before + 1
1252+
assert api_views_count_after > api_views_count_before
12451253

12461254
def test_preprint_downloads_count(self, driver, latest_preprint_node):
12471255
"""Test the Downloads Count functionality on the Preprint Detail page by
@@ -1250,23 +1258,30 @@ def test_preprint_downloads_count(self, driver, latest_preprint_node):
12501258
downloads count will be incremented when the downloads button on the page is
12511259
clicked (only in testing environments).
12521260
"""
1253-
api_downloads_count = osf_api.get_preprint_downloads_count(
1254-
node_id=latest_preprint_node
1255-
)
12561261
preprint_page = PreprintDetailPage(driver, guid=latest_preprint_node)
12571262
preprint_page.goto()
12581263
assert PreprintDetailPage(driver, verify=True)
1259-
assert api_downloads_count == int(preprint_page.downloads_count.text)
1264+
ui_download_count_before = int(preprint_page.downloads_count.text)
1265+
api_downloads_count_before = osf_api.get_preprint_downloads_count(
1266+
node_id=latest_preprint_node
1267+
)
1268+
assert api_downloads_count_before == ui_download_count_before
12601269
# Don't download the Preprint in Production since we don't want to artificially
12611270
# inflate the metrics
12621271
if not settings.PRODUCTION:
12631272
# Verify that the downloads count from the api increases by 1 after we
12641273
# download the document.
12651274
preprint_page.download_button.click()
1266-
assert (
1267-
osf_api.get_preprint_downloads_count(node_id=latest_preprint_node)
1268-
== api_downloads_count + 1
1275+
preprint_page.goto()
1276+
WebDriverWait(driver, settings.TIMEOUT).until(
1277+
EC.visibility_of(preprint_page.downloads_count)
1278+
)
1279+
api_downloads_count_after = osf_api.get_preprint_downloads_count(
1280+
node_id=latest_preprint_node
12691281
)
1282+
ui_download_count_after = int(preprint_page.downloads_count.text)
1283+
assert api_downloads_count_after == api_downloads_count_before + 1
1284+
assert ui_download_count_after == ui_download_count_before + 1
12701285

12711286

12721287
@pytest.fixture(scope='session')

0 commit comments

Comments
 (0)