Commit beb061d8 authored by Jérome Perrin's avatar Jérome Perrin

ERP5TypeFunctionalTestCase: take screenshot and dump the page on error

This is not really for errors during the test itself, but for errors when
ERP5TypeFunctionalTestCase manipulates browser to execute selenium test.
parent f10cc273
Pipeline #16170 failed with stage
in 0 seconds
...@@ -49,7 +49,7 @@ import certifi ...@@ -49,7 +49,7 @@ import certifi
import urllib3 import urllib3
from selenium import webdriver from selenium import webdriver
from selenium.webdriver.common.by import By from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support.ui import WebDriverWait as _WebDriverWait
from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.remote.remote_connection import RemoteConnection from selenium.webdriver.remote.remote_connection import RemoteConnection
...@@ -167,6 +167,31 @@ class Xvfb(Process): ...@@ -167,6 +167,31 @@ class Xvfb(Process):
logger.debug('Xvfb : %d', self.process.pid) logger.debug('Xvfb : %d', self.process.pid)
logger.debug('Take screenshots using xwud -in %s/Xvfb_screen0', self.fbdir) logger.debug('Take screenshots using xwud -in %s/Xvfb_screen0', self.fbdir)
class WebDriverWait(_WebDriverWait):
"""Wrapper for WebDriverWait which dumps the test page and take a
screenshot in case of error.
"""
def until(self, *args):
try:
return super(WebDriverWait, self).until(*args)
except:
logger.exception("unable to find login field, dumping the page")
try:
with open(os.path.join(log_directory, 'page.html'), 'w') as f:
f.write(
self._driver.execute_script(
"return document.getElementById('testSuiteFrame').contentDocument.querySelector('html').innerHTML"))
except:
logger.exception("error when dumping page")
try:
with open(os.path.join(log_directory, 'page-screenshot.png'), 'wb') as f:
f.write(self._driver.get_screenshot_as_png())
except:
logger.exception("error when taking screenshot")
raise
class FunctionalTestRunner: class FunctionalTestRunner:
# There is no test that can take more than 6 hours # There is no test that can take more than 6 hours
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment