diff --git a/selene/config.py b/selene/config.py index a8534998..16efcafb 100644 --- a/selene/config.py +++ b/selene/config.py @@ -4,24 +4,37 @@ import time from selene.browsers import Browser +from selene.helpers import env -timeout = 4 -poll_during_waits = 0.1 -app_host = '' +SELENE_TIMEOUT = "selene_timeout" +SELENE_POOLING_INTERVAL = "selene_polling_interval" +SELENE_BASE_URL = 'selene_base_url' +SELENE_BROWSER = 'selene_browser' +SELENE_START_MAXIMIZED = "selene_start_maximized" +SELENE_HOLD_BROWSER_OPEN = "selene_hold_browser_open" +SELENE_CACHE_ELEMENTS = "selene_cache_elements" +SELENE_SCREENSHOT_FOLDER = "selene_screenshot_folder" + +timeout = env(SELENE_TIMEOUT) or 4 +poll_during_waits = env(SELENE_POOLING_INTERVAL) or 0.1 +app_host = env(SELENE_BASE_URL) or '' # todo: make cashing work (currently will not work...) -cash_elements = False +cash_elements = env(SELENE_CACHE_ELEMENTS) == "True" or False """To cash all elements after first successful find config.cash_elements = True""" -browser_name = Browser.FIREFOX -maximize_window = True -hold_browser_open = False +browser_name = env(SELENE_BROWSER) or Browser.FIREFOX + +maximize_window = False if env(SELENE_START_MAXIMIZED) == "False" else True + +hold_browser_open = env(SELENE_HOLD_BROWSER_OPEN) == "True" or False + counter = itertools.count(start=int(round(time.time() * 1000))) -screenshot_folder = os.path.join(os.path.expanduser("~"), - ".selene", - "screenshots", - str(next(counter))) +screenshot_folder = env(SELENE_SCREENSHOT_FOLDER) or os.path.join(os.path.expanduser("~"), + ".selene", + "screenshots", + str(next(counter))) desired_capabilities = None diff --git a/selene/helpers.py b/selene/helpers.py index 418edb3f..98265bb1 100644 --- a/selene/helpers.py +++ b/selene/helpers.py @@ -50,3 +50,10 @@ def css_or_by_to_by(css_selector_or_by): if isinstance(css_selector_or_by, str): return (By.CSS_SELECTOR, css_selector_or_by) raise TypeError('css_selector_or_by should be str with CSS selector or Tuple[by:str, value:str]') + + +def env(key): + try: + return os.environ[key] + except KeyError: + return None