summaryrefslogtreecommitdiff
path: root/tests/functional/features/environment.py
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2017-07-20 13:46:01 +0200
committerAzul <azul@riseup.net>2017-07-20 13:46:01 +0200
commiteecf6ad13801b63c6b7664d8a2e98e905262aaa0 (patch)
treefadf7d8270106a628c31b1f7017f343a94f311f0 /tests/functional/features/environment.py
parentc81b98df15e3d2006c991c9ca9d86500e3599e9b (diff)
parentd6abd906cb64ae68eed3348eba521bc44ebed7b2 (diff)
Merge branch 'functional_tests'
Diffstat (limited to 'tests/functional/features/environment.py')
-rw-r--r--tests/functional/features/environment.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/functional/features/environment.py b/tests/functional/features/environment.py
new file mode 100644
index 00000000..4ed0caa3
--- /dev/null
+++ b/tests/functional/features/environment.py
@@ -0,0 +1,67 @@
+import os
+import re
+import time
+from urlparse import urlparse
+import commands
+
+from selenium import webdriver
+from selenium.webdriver.chrome.options import Options
+
+DEFAULT_IMPLICIT_WAIT_TIMEOUT_IN_S = 10
+
+
+def before_all(context):
+ _setup_webdriver(context)
+ userdata = context.config.userdata
+ context.host = userdata.get('host', 'http://localhost')
+ if not context.host.startswith('http'):
+ context.host = 'https://{}'.format(context.host)
+ context.hostname = urlparse(context.host).hostname
+
+ context.username = os.environ['TEST_USERNAME']
+ context.password = os.environ['TEST_PASSWORD']
+ context.user_email = '{}@{}'.format(context.username, context.hostname)
+
+
+def _setup_webdriver(context):
+ chrome_options = Options()
+ # argument to switch off suid sandBox and no sandBox in Chrome
+ chrome_options.add_argument("--no-sandbox")
+ chrome_options.add_argument("--disable-setuid-sandbox")
+
+ context.browser = webdriver.Chrome(chrome_options=chrome_options)
+ context.browser.set_window_size(1280, 1024)
+ context.browser.implicitly_wait(DEFAULT_IMPLICIT_WAIT_TIMEOUT_IN_S)
+ context.browser.set_page_load_timeout(60)
+
+
+def after_all(context):
+ context.browser.quit()
+ commands.getoutput('bitmaskctl stop')
+
+
+def after_step(context, step):
+ if step.status == 'failed':
+ _save_screenshot(context, step)
+ _debug_on_error(context, step)
+
+
+def _debug_on_error(context, step):
+ if context.config.userdata.getbool("debug"):
+ try:
+ import ipdb
+ ipdb.post_mortem(step.exc_traceback)
+ except ImportError:
+ import pdb
+ pdb.post_mortem(step.exc_traceback)
+
+
+def _save_screenshot(context, step):
+ timestamp = time.strftime("%Y-%m-%d-%H-%M-%S")
+ filename = _slugify('{} failed {}'.format(timestamp, str(step.name)))
+ filepath = os.path.join('/tmp/', filename + '.png')
+ context.browser.save_screenshot(filepath)
+
+
+def _slugify(string_):
+ return re.sub('\W', '-', string_)