UPD: improved tests.

This commit is contained in:
2019-03-14 11:15:05 +01:00
parent 848db26516
commit 3f68579b78
4 changed files with 87 additions and 39 deletions

View File

@@ -172,42 +172,44 @@ class ScreenshotTestCase(SeleniumTestCase):
self.selenium.set_window_size(self.window_width, self.window_height)
def sanitize_filename(self, location):
location = location.lstrip('/')
if location == '':
return 'root'
r = urllib.quote(location, '')
return r
return urllib.quote(location).replace('/', '--')
def save_screenshot(self, name=None, sequence=None):
if name is not None:
pass
elif sequence is not None:
def save_screenshot(self, title=None, sequence=None):
if sequence is None:
sequence = ''
else:
if sequence in self.screenshot_sequences:
self.screenshot_sequences[sequence] += 1
else:
self.screenshot_sequences[sequence] = 1
n = self.screenshot_sequences[sequence]
name = '%s-%04d' % (sequence, n)
else:
sequence = u'%s-%04d-' % (sequence, n)
if title is None:
location = self.selenium.current_url
if location.startswith(self.live_server_url):
location = location[len(self.live_server_url):]
name = location
location = location.lstrip('/')
if location == '':
location = 'root'
title = location
now = datetime.datetime.now()
base_name = '{timestamp}-{prefix}{name}.png'.format(
base_name = u'{timestamp}-{prefix}{sequence}{title}.png'.format(
timestamp=datetime.datetime.now().strftime('%Y%m%d-%H%M%S'),
prefix=self.screenshot_prefix,
name=self.sanitize_filename(name),
timestamp=now.strftime('%Y%m%d-%H%M%S')
sequence=sequence,
title=title,
)
path = os.path.join(self.screenshot_path, base_name)
path = os.path.join(self.screenshot_path, self.sanitize_filename(base_name))
if not os.path.isdir(self.screenshot_path):
os.makedirs(self.screenshot_path, 0700)
self.selenium.save_screenshot(path)
def get(self, location):
return self.selenium.get(self.complete_url(location))
@skip_unless_tag_option()
@tag('screenshots')
def test_screenshots(self):
for location in self.locations:
self.selenium.get(self.complete_url(location))
self.get(location)
self.save_screenshot()