@@ -1219,9 +1219,12 @@ def test_preprint_views_count(self, driver, latest_preprint_node):
1219
1219
count value displayed on the page. Also verifying that the views count will
1220
1220
be incremented if the page is reloaded (only in testing environments).
1221
1221
"""
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
+ )
1223
1225
preprint_page = PreprintDetailPage (driver , guid = latest_preprint_node )
1224
1226
preprint_page .goto ()
1227
+ ui_view_count_before = int (preprint_page .views_count .text )
1225
1228
assert PreprintDetailPage (driver , verify = True )
1226
1229
1227
1230
# 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):
1237
1240
# checking that the views count did increase but not by how much.
1238
1241
# Unfortunately this means that we are not checking for any issues like
1239
1242
# 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 )
1244
1246
)
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
1245
1253
1246
1254
def test_preprint_downloads_count (self , driver , latest_preprint_node ):
1247
1255
"""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):
1250
1258
downloads count will be incremented when the downloads button on the page is
1251
1259
clicked (only in testing environments).
1252
1260
"""
1253
- api_downloads_count = osf_api .get_preprint_downloads_count (
1254
- node_id = latest_preprint_node
1255
- )
1256
1261
preprint_page = PreprintDetailPage (driver , guid = latest_preprint_node )
1257
1262
preprint_page .goto ()
1258
1263
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
1260
1269
# Don't download the Preprint in Production since we don't want to artificially
1261
1270
# inflate the metrics
1262
1271
if not settings .PRODUCTION :
1263
1272
# Verify that the downloads count from the api increases by 1 after we
1264
1273
# download the document.
1265
1274
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
1269
1281
)
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
1270
1285
1271
1286
1272
1287
@pytest .fixture (scope = 'session' )
0 commit comments