mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-01-12 09:11:55 -06:00
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>
This commit is contained in:
parent
37c238a6ef
commit
6a61378586
@ -24,9 +24,12 @@ Contains browser driver and common tasks.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import nose
|
import nose
|
||||||
|
from datetime import datetime
|
||||||
import time
|
import time
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
|
from functools import wraps
|
||||||
|
from nose.plugins.skip import SkipTest
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from selenium import webdriver
|
from selenium import webdriver
|
||||||
@ -77,6 +80,29 @@ DEFAULT_PORT = 4444
|
|||||||
DEFAULT_TYPE = 'local'
|
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):
|
class UI_driver(object):
|
||||||
"""
|
"""
|
||||||
Base class for all UI integration tests
|
Base class for all UI integration tests
|
||||||
@ -368,6 +394,14 @@ class UI_driver(object):
|
|||||||
screen = self.get_login_screen()
|
screen = self.get_login_screen()
|
||||||
return screen and screen.is_displayed()
|
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):
|
def navigate_to_entity(self, entity, facet=None):
|
||||||
self.driver.get(self.get_url(entity, facet))
|
self.driver.get(self.get_url(entity, facet))
|
||||||
self.wait_for_request(n=3, d=0.4)
|
self.wait_for_request(n=3, d=0.4)
|
||||||
|
Loading…
Reference in New Issue
Block a user