summaryrefslogtreecommitdiffstats
path: root/ipatests
diff options
context:
space:
mode:
authorPetr Vobornik <pvoborni@redhat.com>2014-04-28 16:59:50 +0200
committerPetr Vobornik <pvoborni@redhat.com>2014-05-12 18:52:57 +0200
commit6a61378586eb51eaa271ce492566309b0f68de59 (patch)
treebbe0832cb37d3f1d2350bf11eec8c68ff7062a55 /ipatests
parent37c238a6ef8f825f85351a5974b4270998bc0661 (diff)
downloadfreeipa-6a61378586eb51eaa271ce492566309b0f68de59.tar.gz
freeipa-6a61378586eb51eaa271ce492566309b0f68de59.tar.xz
freeipa-6a61378586eb51eaa271ce492566309b0f68de59.zip
webui-ci: save screenshot on test failure
New decorator: ui_driver.screenshot created. It should be applied on test methods. Screenshot is saved on each exception except SkipTest. Configuration: - add: `save_screenshots: True` to ~/.ipa/ui_test.conf to enable saving screenshots - optionally add `screenshot_dir: /path/to/dir` to specify target directory otherwise screenshots are saved to current directory Reviewed-By: Adam Misnyovszki <amisnyov@redhat.com>
Diffstat (limited to 'ipatests')
-rw-r--r--ipatests/test_webui/ui_driver.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/ipatests/test_webui/ui_driver.py b/ipatests/test_webui/ui_driver.py
index ce63d570e..0516c6b6f 100644
--- a/ipatests/test_webui/ui_driver.py
+++ b/ipatests/test_webui/ui_driver.py
@@ -24,9 +24,12 @@ Contains browser driver and common tasks.
"""
import nose
+from datetime import datetime
import time
import re
import os
+from functools import wraps
+from nose.plugins.skip import SkipTest
try:
from selenium import webdriver
@@ -77,6 +80,29 @@ DEFAULT_PORT = 4444
DEFAULT_TYPE = 'local'
+def screenshot(fn):
+ """
+ Decorator for saving screenshot on exception (test fail)
+ Should be applied on methods of UI_driver subclasses
+ """
+ @wraps(fn)
+ def screenshot_wrapper(*args):
+ try:
+ return fn(*args)
+ except SkipTest:
+ raise
+ except Exception:
+ self = args[0]
+ name = '%s_%s_%s' % (
+ datetime.now().isoformat(),
+ self.__class__.__name__,
+ fn.__name__)
+ self.take_screenshot(name)
+ raise
+
+ return screenshot_wrapper
+
+
class UI_driver(object):
"""
Base class for all UI integration tests
@@ -368,6 +394,14 @@ class UI_driver(object):
screen = self.get_login_screen()
return screen and screen.is_displayed()
+ def take_screenshot(self, name):
+ if self.config.get('save_screenshots'):
+ scr_dir = self.config.get('screenshot_dir')
+ path = name + '.png'
+ if scr_dir:
+ path = os.path.join(scr_dir, path)
+ self.driver.get_screenshot_as_file(path)
+
def navigate_to_entity(self, entity, facet=None):
self.driver.get(self.get_url(entity, facet))
self.wait_for_request(n=3, d=0.4)