diff options
author | Tulio Casagrande <tcasagra@thoughtworks.com> | 2016-11-29 16:38:58 -0200 |
---|---|---|
committer | Tulio Casagrande <tcasagra@thoughtworks.com> | 2016-11-29 16:45:06 -0200 |
commit | b07f0748a4cff3a3310327a9182d9458d0983613 (patch) | |
tree | 2dc9e7ae471f868981ee2f1ed4577b1ed9fc71e0 /service/test/functional/features | |
parent | d662fa63a0a7f7f2ae31cf1968f61db8b6240a5a (diff) |
Add support for parameterization on error
We added debug on error, default to false and save screenshots, default
to true
Diffstat (limited to 'service/test/functional/features')
-rw-r--r-- | service/test/functional/features/environment.py | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/service/test/functional/features/environment.py b/service/test/functional/features/environment.py index 33e0f5fe..b7dbba3f 100644 --- a/service/test/functional/features/environment.py +++ b/service/test/functional/features/environment.py @@ -14,7 +14,8 @@ # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. import os -import uuid +import re +import time from crochet import setup, wait_for from leap.common.events.server import ensure_server @@ -68,12 +69,23 @@ def before_feature(context, feature): def after_step(context, step): - if step.status == 'failed': - id = str(uuid.uuid4()) - os.chdir("screenshots") - context.browser.save_screenshot('failed ' + str(step.name) + '_' + id + ".png") - save_source(context, 'failed ' + str(step.name) + '_' + id + ".html") - os.chdir("../") + _debug_on_error(context, step) + _save_screenshot(context, step) + + +def _debug_on_error(context, step): + if step.status == 'failed' and context.config.userdata.getbool("debug"): + import pdb + pdb.post_mortem(step.exc_traceback) + + +def _save_screenshot(context, step): + if (step.status == 'failed' and + context.config.userdata.getbool("screenshots", True)): + timestamp = time.strftime("%Y-%m-%d-%H-%M-%S") + filename = re.sub('\W', '-', timestamp + ' failed ' + str(step.name)) + filepath = os.path.join('screenshots', filename + '.png') + context.browser.save_screenshot(filepath) def after_feature(context, feature): @@ -92,8 +104,3 @@ def cleanup_all_mails(context): yield context.client.mail_store.delete_mail(mail.ident) return _delete_all_mails() - - -def save_source(context, filename='/tmp/source.html'): - with open(filename, 'w') as out: - out.write(context.browser.page_source.encode('utf8')) |