From 7164757c3b48a6a697c132968a06f7eea07c097e Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 20 Jul 2017 14:42:55 +0200 Subject: [test] keep config files from failing tests --- .gitlab-ci.yml | 2 +- tests/functional/features/environment.py | 44 ++++++++++++++++++++++-------- tests/functional/features/steps/bitmask.py | 2 +- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cc7520f0..83fad3a5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -72,7 +72,7 @@ functional_tests: artifacts: when: on_failure paths: - - "/tmp/*.png" + - "/tmp/bitmask-test/artifacts/*" name: "Bitmask_linux64_${CI_BUILD_REF}_e2e_screenshots" expire_in: 1 month tags: diff --git a/tests/functional/features/environment.py b/tests/functional/features/environment.py index 4ed0caa3..cc3179e6 100644 --- a/tests/functional/features/environment.py +++ b/tests/functional/features/environment.py @@ -1,4 +1,5 @@ import os +import shutil import re import time from urlparse import urlparse @@ -6,11 +7,14 @@ import commands from selenium import webdriver from selenium.webdriver.chrome.options import Options +from leap.common.config import get_path_prefix DEFAULT_IMPLICIT_WAIT_TIMEOUT_IN_S = 10 +HOME_PATH = '/tmp/bitmask-test' def before_all(context): + os.environ['HOME'] = HOME_PATH _setup_webdriver(context) userdata = context.config.userdata context.host = userdata.get('host', 'http://localhost') @@ -42,10 +46,39 @@ def after_all(context): def after_step(context, step): if step.status == 'failed': + _prepare_artifacts_folder(step) _save_screenshot(context, step) + _save_config(context, step) _debug_on_error(context, step) +def _prepare_artifacts_folder(step): + try: + os.makedirs(_artifact_path(step)) + except OSError as err: + # directory existed + if err.errno != 17: + raise + + +def _save_screenshot(context, step): + filepath = _artifact_path(step, 'screenshot.png') + context.browser.save_screenshot(filepath) + print('saved screenshot to: file://%s' % filepath) + + +def _save_config(context, step): + filepath = _artifact_path(step, 'config') + shutil.copytree(get_path_prefix(), filepath) + print('copied config to: file://%s' % filepath) + + +def _artifact_path(step, filename=''): + string = 'failed {}'.format(str(step.name)) + slug = re.sub('\W', '-', string) + return os.path.join(HOME_PATH, 'artifacts', slug, filename) + + def _debug_on_error(context, step): if context.config.userdata.getbool("debug"): try: @@ -54,14 +87,3 @@ def _debug_on_error(context, step): 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_) diff --git a/tests/functional/features/steps/bitmask.py b/tests/functional/features/steps/bitmask.py index b5b4cf1e..87582430 100644 --- a/tests/functional/features/steps/bitmask.py +++ b/tests/functional/features/steps/bitmask.py @@ -21,6 +21,6 @@ def initial_run(context): def _initialize_home_path(): home_path = '/tmp/bitmask-test' - shutil.rmtree(home_path, ignore_errors=True) os.environ['HOME'] = home_path + shutil.rmtree(get_path_prefix(), ignore_errors=True) os.makedirs(get_path_prefix()) -- cgit v1.2.3