Skip to content

Commit

Permalink
Add utility method & steps for capturing screenshots
Browse files Browse the repository at this point in the history
  • Loading branch information
npilon committed Mar 13, 2014
1 parent 911e3af commit 94f24f9
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions lettuce_webdriver/screenshot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""Steps and utility functions for taking screenshots."""

from lettuce import (
step,
world,
)
import os.path

def set_save_directory(root):
"""Sets the root save directory for saving screenshots.
Screenshots will be saved in subdirectories under this directory by
browser window size. """
if not os.path.isdir(root):
os.makedirs(root)

world.screenshot_root = root


@step(r'I capture a screenshot named "(.*?)"$')
def capture_screenshot(step, name):
window_size = world.browser.get_window_size()
dir_path = os.path.join(
world.screenshot_root,
'{}x{}'.format(window_size['width'], window_size['height']),
)
if not os.path.isdir(dir_path):
os.makedirs(dir_path)
filename = os.path.join(
dir_path,
'{}.png'.format(name)
)
world.browser.get_screenshot_as_file(filename)


@step(r'I capture a screenshot named "(.*?)" after (\d+) seconds?$')
def capture_screenshot_delay(step, name, delay):
time.sleep(delay)
capture_screenshot(name)

0 comments on commit 94f24f9

Please sign in to comment.