Skip to content

Commit 8e2df02

Browse files
authored
Merge pull request CenterForOpenScience#269 from CenterForOpenScience/fix/sel-maintenance
Selenium maintenance fixes
2 parents 7e4808d + 007d4c4 commit 8e2df02

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

api/osf_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import datetime
21
import json
32
import logging
43
import os
4+
from datetime import datetime
55
from urllib.parse import quote
66

77
import requests
@@ -643,7 +643,7 @@ def create_preprint(
643643
# then the Edit Preprint page thinks that the preprint has unsaved changes even if
644644
# you have made no changes on the form page. There is a ticket for this issue:
645645
# ENG-3782.
646-
current_year = datetime.datetime.now().year
646+
current_year = datetime.now().year
647647
# Get subject id for the subject_name parameter. NOTE: Currently we are creating
648648
# the preprint with only a single subject, which is the minimum required to publish.
649649
subject_id = get_subject_id_for_provider(
@@ -1210,7 +1210,7 @@ def get_registration_resource_id(registration_id):
12101210
if data:
12111211
for i in range(0, len(data)):
12121212
date_created = data[i]['attributes']['date_created']
1213-
now = datetime.datetime.now()
1213+
now = datetime.now()
12141214
current_date = now.strftime('%Y-%m-%d')
12151215
if current_date in date_created:
12161216
return data[i]['id']

pages/base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import urllib.parse
22
from time import sleep
3+
from urllib.parse import quote
34

45
from selenium.common.exceptions import NoSuchElementException
56
from selenium.webdriver.common.action_chains import ActionChains
@@ -38,7 +39,10 @@ def goto(self, expect_redirect_to=None):
3839
self.driver.get(self.url)
3940

4041
if expect_redirect_to:
41-
if self.url not in self.driver.current_url:
42+
if (
43+
self.url not in self.driver.current_url
44+
and quote(self.url, safe='') not in self.driver.current_url
45+
):
4246
raise PageException(
4347
'Unexpected url structure: `{}`'.format(self.driver.current_url)
4448
)

pages/preprints.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,7 @@ class PreprintDiscoverPage(BasePreprintPage):
234234
loading_indicator = Locator(By.CSS_SELECTOR, '.ball-scale')
235235
search_box = Locator(By.CSS_SELECTOR, 'input[data-test-search-input]')
236236
sort_button = Locator(By.CSS_SELECTOR, 'div[data-test-topbar-sort-dropdown]')
237-
sort_option_newest_to_oldest = Locator(
238-
By.CSS_SELECTOR, '#sortByOptionList > li:nth-child(3) > button'
239-
)
237+
sort_option_newest_to_oldest = Locator(By.CSS_SELECTOR, '[data-option-index="3"]')
240238

241239
# Group Locators
242240
search_results = GroupLocator(By.CSS_SELECTOR, 'div[data-test-search-result-card]')
@@ -253,9 +251,7 @@ class BrandedPreprintsDiscoverPage(BasePreprintPage):
253251
loading_indicator = Locator(By.CSS_SELECTOR, '.ball-scale')
254252
search_box = Locator(By.CSS_SELECTOR, 'input[data-test-search-input]')
255253
sort_button = Locator(By.CSS_SELECTOR, 'div[data-test-topbar-sort-dropdown]')
256-
sort_option_newest_to_oldest = Locator(
257-
By.CSS_SELECTOR, '#sortByOptionList > li:nth-child(3) > button'
258-
)
254+
sort_option_newest_to_oldest = Locator(By.CSS_SELECTOR, '[data-option-index="3"]')
259255
no_results = Locator(By.CSS_SELECTOR, 'div[_no-results_fvrbco]')
260256

261257
# Group Locators

tests/test_preprints.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,8 @@ def test_approve_withdrawal_request_pre_moderated_preprint(
579579
preprint_page.goto()
580580
assert PreprintDetailPage(driver, verify=True)
581581
WebDriverWait(driver, 5).until(EC.visibility_of(preprint_page.title))
582-
assert preprint_page.title.text == preprint_title
582+
assert preprint_title in preprint_page.title.text
583+
assert 'Withdrawn' in preprint_page.title.text
583584
# TODO: Re-enable assert after [ENG-5092] is fixed.
584585
# assert (
585586
# preprint_page.status_explanation.text == 'This preprint has been withdrawn.'
@@ -846,7 +847,8 @@ def test_moderator_withdrawal_post_moderated_preprint(
846847
preprint_page.goto()
847848
assert PreprintDetailPage(driver, verify=True)
848849
WebDriverWait(driver, 5).until(EC.visibility_of(preprint_page.title))
849-
assert preprint_page.title.text == preprint_title
850+
assert preprint_title in preprint_page.title.text
851+
assert 'Withdrawn' in preprint_page.title.text
850852
# TODO: Re-enable assert after [ENG-5092] is fixed.
851853
# assert (
852854
# preprint_page.status_explanation.text == 'This preprint has been withdrawn.'
@@ -943,7 +945,8 @@ def test_approve_withdrawal_request_post_moderated_preprint(
943945
preprint_page.goto()
944946
assert PreprintDetailPage(driver, verify=True)
945947
WebDriverWait(driver, 5).until(EC.visibility_of(preprint_page.title))
946-
assert preprint_page.title.text == preprint_title
948+
assert preprint_title in preprint_page.title.text
949+
assert 'Withdrawn' in preprint_page.title.text
947950
# Add assert for "This preprint has been withdrawn" after [ENG-5092] is fixed.
948951
assert preprint_page.withdraw_reason.present()
949952

0 commit comments

Comments
 (0)