Skip to content

Commit

Permalink
Merge pull request #632 from HEPData/fix-e2e-tests
Browse files Browse the repository at this point in the history
tests: use implicit wait for Selenium WebDriver
  • Loading branch information
GraemeWatt committed Apr 4, 2023
2 parents c8838f4 + ed636ae commit 22b4af9
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 18 deletions.
2 changes: 1 addition & 1 deletion hepdata/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
and parsed by ``setup.py``.
"""

__version__ = "0.9.4dev20230327"
__version__ = "0.9.4dev20230404"
3 changes: 2 additions & 1 deletion tests/e2e/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ def finalizer():
# Run tests locally instead of on Sauce Labs (requires local chromedriver installation).
browser = getattr(webdriver, request.param)()

browser.set_window_size(1280,1024)
browser.set_window_size(1280, 1024)
browser.implicitly_wait(10) # seconds

# Go to homepage and click cookie accept button so cookie bar is out of the way
browser.get(flask.url_for('hepdata_theme.index', _external=True))
Expand Down
6 changes: 1 addition & 5 deletions tests/e2e/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"""HEPData end to end testing of general pages."""
import flask
import requests
import requests_mock
import zipfile
import io

Expand All @@ -33,14 +32,11 @@
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from functools import reduce
from tests.conftest import import_default_data

from hepdata.ext.opensearch.api import reindex_all
from hepdata.modules.records.importer.api import import_records
from hepdata.modules.submission.api import get_latest_hepsubmission
from hepdata.modules.records.utils.submission import unload_submission, get_or_create_hepsubmission
from hepdata.modules.records.utils.workflow import create_record
from hepdata.modules.records.utils.submission import unload_submission


def test_home(app, live_server, env_browser, e2e_identifiers):
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_search_from_home(live_server, env_browser, search_tests):
# Click 'View all'
search_all_link = browser.find_element(By.CSS_SELECTOR, '#latest_records_section').find_element(By.TAG_NAME, 'a')
search_all_link.click()
element = WebDriverWait(browser, 10).until(
WebDriverWait(browser, 10).until(
EC.url_contains('search')
)
assert (flask.url_for('os_search.search', _external=True) in
Expand Down Expand Up @@ -110,7 +110,7 @@ def test_search_from_home(live_server, env_browser, search_tests):
search_input.send_keys(search_term)

search_form.submit()
element = WebDriverWait(browser, 10).until(
WebDriverWait(browser, 10).until(
EC.presence_of_element_located((By.CLASS_NAME, 'search-result-item'))
)

Expand Down
11 changes: 2 additions & 9 deletions tests/e2e/test_submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
# as an Intergovernmental Organization or submit itself to any jurisdiction.

"""HEPData end to end testing of record submission."""
import flask
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
Expand Down Expand Up @@ -87,24 +86,21 @@ def test_create_submission(live_server, logged_in_browser):

# Click continue and wait for animation to finish
browser.find_element(By.ID, 'people_continue_btn').click()
WebDriverWait(browser, 10).until(
EC.visibility_of_element_located((By.CSS_SELECTOR, "#uploader_message h4"))
)

# Add message for uploader
browser.find_element(By.ID, 'uploader-message-input').send_keys('Please could you upload something?')

# Click continue and wait for animation to finish
browser.find_element(By.ID, 'message_continue_btn').click()
submission_state_p = WebDriverWait(browser, 10).until(
WebDriverWait(browser, 10).until(
EC.text_to_be_present_in_element(
(By.CSS_SELECTOR, "#submission_state p"),
"You are about to create a submission for")
)

# Click continue and wait for animation to finish
browser.find_element(By.ID, 'submit_btn').click()
submission_state_p = WebDriverWait(browser, 10).until(
WebDriverWait(browser, 10).until(
EC.text_to_be_present_in_element(
(By.CSS_SELECTOR, "#submission_state p"),
"Submission Complete!"
Expand Down Expand Up @@ -136,9 +132,6 @@ def test_create_submission(live_server, logged_in_browser):
continue_button = browser.find_element(By.ID, 'continue_btn')
continue_button.click()
# Wait for alert to appear
WebDriverWait(browser, 10).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "#inspire-result .alert-danger"))
)
alert = browser.find_element(By.CSS_SELECTOR, "#inspire-result .alert-danger")
assert alert.text == 'A record with this Inspire ID already exists in HEPData.'
record_link = alert.find_element(By.TAG_NAME, 'a')
Expand Down

0 comments on commit 22b4af9

Please sign in to comment.