UPD: improved tests.
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user