|
|
|
@ -49,7 +49,8 @@ def init_tests( webdriver, flask_app, dbconn, **kwargs ): |
|
|
|
|
# re-initialize the search engine |
|
|
|
|
if flask_app: |
|
|
|
|
url = flask_app.url_for( "init_search_for_test" ) |
|
|
|
|
_ = urllib.request.urlopen( url ).read() |
|
|
|
|
with urllib.request.urlopen( url ) as resp: |
|
|
|
|
_ = resp.read() |
|
|
|
|
|
|
|
|
|
# initialize the documents directory |
|
|
|
|
dname = kwargs.pop( "docs", None ) |
|
|
|
@ -70,7 +71,10 @@ def init_tests( webdriver, flask_app, dbconn, **kwargs ): |
|
|
|
|
if to_bool( kwargs.pop( "disable_confirm_discard_changes", True ) ): |
|
|
|
|
kwargs[ "disable_confirm_discard_changes" ] = 1 |
|
|
|
|
webdriver.get( webdriver.make_url( "", **kwargs ) ) |
|
|
|
|
wait_for_elem( 2, "#search-form" ) |
|
|
|
|
# FUDGE! Since we switched from running the test Flask server with app.run() to make_server().serve_forever(), |
|
|
|
|
# stopping and starting the server seems to be much quicker, but refreshing the page can be slower when |
|
|
|
|
# running multiple tests :shrug: |
|
|
|
|
wait_for_elem( 10, "#search-form" ) |
|
|
|
|
|
|
|
|
|
return session |
|
|
|
|
|
|
|
|
@ -83,7 +87,8 @@ def load_fixtures( session, fname ): |
|
|
|
|
if fname: |
|
|
|
|
dname = os.path.join( os.path.split(__file__)[0], "fixtures/" ) |
|
|
|
|
fname = os.path.join( dname, fname ) |
|
|
|
|
data = json.load( open( fname, "r" ) ) |
|
|
|
|
with open( fname, "r", encoding="utf-8" ) as fp: |
|
|
|
|
data = json.load( fp ) |
|
|
|
|
else: |
|
|
|
|
data = {} |
|
|
|
|
|
|
|
|
@ -318,21 +323,21 @@ def wait_for_not_elem( timeout, sel ): |
|
|
|
|
def find_child( sel, parent=None ): |
|
|
|
|
"""Find a child element.""" |
|
|
|
|
try: |
|
|
|
|
return (parent if parent else _webdriver).find_element_by_css_selector( sel ) |
|
|
|
|
return (parent if parent else _webdriver).find_element( By.CSS_SELECTOR, sel ) |
|
|
|
|
except NoSuchElementException: |
|
|
|
|
return None |
|
|
|
|
|
|
|
|
|
def find_children( sel, parent=None ): |
|
|
|
|
"""Find child elements.""" |
|
|
|
|
try: |
|
|
|
|
return (parent if parent else _webdriver).find_elements_by_css_selector( sel ) |
|
|
|
|
return (parent if parent else _webdriver).find_elements( By.CSS_SELECTOR, sel ) |
|
|
|
|
except NoSuchElementException: |
|
|
|
|
return None |
|
|
|
|
|
|
|
|
|
def find_parent_by_class( elem, class_name ): |
|
|
|
|
"""Find a parent element with the specified class.""" |
|
|
|
|
while True: |
|
|
|
|
elem = elem.find_element_by_xpath( ".." ) |
|
|
|
|
elem = elem.find_element( By.XPATH, ".." ) |
|
|
|
|
if not elem: |
|
|
|
|
return None |
|
|
|
|
classes = set( elem.get_attribute( "class" ).split() ) |
|
|
|
@ -497,7 +502,8 @@ def call_with_retry( func, expected_exceptions, max_retries=10, delay=0.1 ): |
|
|
|
|
def change_image( dlg, fname ): |
|
|
|
|
"""Click on an image to change it.""" |
|
|
|
|
# NOTE: This is a bit tricky since we started overlaying the image with the "remove image" icon :-/ |
|
|
|
|
data = base64.b64encode( open( fname, "rb" ).read() ) |
|
|
|
|
with open( fname, "rb" ) as fp: |
|
|
|
|
data = base64.b64encode( fp.read() ) |
|
|
|
|
data = "{}|{}".format( os.path.split(fname)[1], data.decode("ascii") ) |
|
|
|
|
elem = find_child( ".row.image img.image", dlg ) |
|
|
|
|
_webdriver.execute_script( "arguments[0].scrollTo( 0, 0 )", find_child( ".MuiDialogContent-root", dlg ) ) |
|
|
|
|