responsive_layout: Add collection of browser logs

This commit is contained in:
Marian Steinbach 2018-09-29 01:37:50 +02:00
parent 8a5229861e
commit b8e54c576a

View file

@ -1,13 +1,19 @@
"""
Check for responsive layout.
This relies on
This loads any input URL once in Chrome and checks whether the document width
adapts well to viewports as little as 360 pixels wide.
In addition, the check captures javascript errors and warnings from
missing resources
"""
import logging
import time
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
import tenacity
from checks.abstract_checker import AbstractChecker
@ -39,14 +45,24 @@ class Checker(AbstractChecker):
results = {}
for url in self.config.urls:
sizes = self.check_responsiveness(url)
results[url] = {
'sizes': sizes,
'min_document_width': min([s['document_width'] for s in sizes]),
}
try:
sizes = self.check_responsiveness(url)
results[url] = {
'sizes': sizes,
'min_document_width': min([s['document_width'] for s in sizes]),
'logs': self.capture_log(),
}
except TimeoutException as e:
logging.warn("TimeoutException when checking responsiveness for %s sizes %r: %s" % (url, sizes, e))
pass
self.driver.quit()
return results
@tenacity.retry(stop=tenacity.stop_after_attempt(3),
retry=tenacity.retry_if_exception_type(TimeoutException))
def check_responsiveness(self, url):
result = []
@ -69,4 +85,14 @@ class Checker(AbstractChecker):
'document_width': int(doc_width),
})
return result
return result
def capture_log(self):
"""
Returns log elements with level "SEVERE"
"""
entries = []
for entry in self.driver.get_log('browser'):
if entry['level'] in ('WARNING', 'SEVERE'):
entries.append(entry)
return entries