Robot Framework
robot.libraries.Screenshot.Screenshot Class Reference

Library for taking screenshots on the machine where tests are executed. More...

Public Member Functions

def __init__ (self, screenshot_directory=None, screenshot_module=None)
 Configure where screenshots are saved. More...
 
def set_screenshot_directory (self, path)
 Sets the directory where screenshots are saved. More...
 
def take_screenshot (self, name="screenshot", width="800px")
 Takes a screenshot in JPEG format and embeds it into the log file. More...
 
def take_screenshot_without_embedding (self, name="screenshot")
 Takes a screenshot and links it from the log file. More...
 

Static Public Attributes

string ROBOT_LIBRARY_SCOPE = 'TEST SUITE'
 
 ROBOT_LIBRARY_VERSION = get_version()
 

Properties

 _log_dir = property
 
 _screenshot_dir = property
 

Private Member Functions

def _embed_screenshot (self, path, width)
 
def _get_screenshot_path (self, basename)
 
def _link_screenshot (self, path)
 
def _log_dir (self)
 
def _norm_path (self, path)
 
def _save_screenshot (self, name)
 
def _screenshot_dir (self)
 
def _screenshot_to_file (self, path)
 
def _validate_screenshot_path (self, path)
 

Private Attributes

 _given_screenshot_dir
 
 _screenshot_taker
 

Detailed Description

Library for taking screenshots on the machine where tests are executed.

Taking the actual screenshot requires a suitable tool or module that may
need to be installed separately. Taking screenshots also requires tests
to be run with a physical or virtual display.

== Table of contents ==

%TOC%

= Supported screenshot taking tools and modules =

How screenshots are taken depends on the operating system. On OSX
screenshots are taken using the built-in ``screencapture`` utility. On
other operating systems you need to have one of the following tools or
Python modules installed. You can specify the tool/module to use when
`importing` the library. If no tool or module is specified, the first
one found will be used.

- wxPython :: http://wxpython.org :: Generic Python GUI toolkit.
- PyGTK :: http://pygtk.org :: This module is available by default on most
  Linux distributions.
- Pillow :: http://python-pillow.github.io ::
  Only works on Windows. Also the original PIL package is supported.
- Scrot :: http://en.wikipedia.org/wiki/Scrot :: Not used on Windows.
  Install with ``apt-get install scrot`` or similar.

= Where screenshots are saved =

By default screenshots are saved into the same directory where the Robot
Framework log file is written. If no log is created, screenshots are saved
into the directory where the XML output file is written.

It is possible to specify a custom location for screenshots using
``screenshot_directory`` argument when `importing` the library and
using `Set Screenshot Directory` keyword during execution. It is also
possible to save screenshots using an absolute path.

= ScreenCapLibrary =

[https://github.com/mihaiparvu/ScreenCapLibrary|ScreenCapLibrary] is an
external Robot Framework library that can be used as an alternative,
which additionally provides support for multiple formats, adjusting the
quality, using GIFs and video capturing.

Definition at line 84 of file Screenshot.py.

Constructor & Destructor Documentation

◆ __init__()

def robot.libraries.Screenshot.Screenshot.__init__ (   self,
  screenshot_directory = None,
  screenshot_module = None 
)

Configure where screenshots are saved.

    If ``screenshot_directory`` is not given, screenshots are saved into
    same directory as the log file. The directory can also be set using
    `Set Screenshot Directory` keyword.

    ``screenshot_module`` specifies the module or tool to use when using
    this library outside OSX. Possible values are ``wxPython``,
    ``PyGTK``, ``PIL`` and ``scrot``, case-insensitively. If no value is
    given, the first module/tool found is used in that order.

    Examples:
    | =Setting= |  =Value=   |  =Value=   |
    | Library   | Screenshot |            |
    | Library   | Screenshot | ${TEMPDIR} |
    | Library   | Screenshot | screenshot_module=PyGTK |

Definition at line 106 of file Screenshot.py.

Member Function Documentation

◆ _embed_screenshot()

def robot.libraries.Screenshot.Screenshot._embed_screenshot (   self,
  path,
  width 
)
private

Definition at line 224 of file Screenshot.py.

◆ _get_screenshot_path()

def robot.libraries.Screenshot.Screenshot._get_screenshot_path (   self,
  basename 
)
private

Definition at line 214 of file Screenshot.py.

◆ _link_screenshot()

def robot.libraries.Screenshot.Screenshot._link_screenshot (   self,
  path 
)
private

Definition at line 229 of file Screenshot.py.

◆ _log_dir()

def robot.libraries.Screenshot.Screenshot._log_dir (   self)
private

Definition at line 128 of file Screenshot.py.

◆ _norm_path()

def robot.libraries.Screenshot.Screenshot._norm_path (   self,
  path 
)
private

Definition at line 110 of file Screenshot.py.

◆ _save_screenshot()

def robot.libraries.Screenshot.Screenshot._save_screenshot (   self,
  name 
)
private

Definition at line 190 of file Screenshot.py.

◆ _screenshot_dir()

def robot.libraries.Screenshot.Screenshot._screenshot_dir (   self)
private

Definition at line 122 of file Screenshot.py.

◆ _screenshot_to_file()

def robot.libraries.Screenshot.Screenshot._screenshot_to_file (   self,
  path 
)
private

Definition at line 195 of file Screenshot.py.

◆ _validate_screenshot_path()

def robot.libraries.Screenshot.Screenshot._validate_screenshot_path (   self,
  path 
)
private

Definition at line 207 of file Screenshot.py.

◆ set_screenshot_directory()

def robot.libraries.Screenshot.Screenshot.set_screenshot_directory (   self,
  path 
)

Sets the directory where screenshots are saved.

    It is possible to use ``/`` as a path separator in all operating
    systems. Path to the old directory is returned.

    The directory can also be set in `importing`.

Definition at line 142 of file Screenshot.py.

◆ take_screenshot()

def robot.libraries.Screenshot.Screenshot.take_screenshot (   self,
  name = "screenshot",
  width = "800px" 
)

Takes a screenshot in JPEG format and embeds it into the log file.

    Name of the file where the screenshot is stored is derived from the
    given ``name``. If the ``name`` ends with extension ``.jpg`` or
    ``.jpeg``, the screenshot will be stored with that exact name.
    Otherwise a unique name is created by adding an underscore, a running
    index and an extension to the ``name``.

    The name will be interpreted to be relative to the directory where
    the log file is written. It is also possible to use absolute paths.
    Using ``/`` as a path separator works in all operating systems.

    ``width`` specifies the size of the screenshot in the log file.

    Examples: (LOGDIR is determined automatically by the library)
    | Take Screenshot |                  |     | # LOGDIR/screenshot_1.jpg (index automatically incremented) |
    | Take Screenshot | mypic            |     | # LOGDIR/mypic_1.jpg (index automatically incremented) |
    | Take Screenshot | ${TEMPDIR}/mypic |     | # /tmp/mypic_1.jpg (index automatically incremented) |
    | Take Screenshot | pic.jpg          |     | # LOGDIR/pic.jpg (always uses this file) |
    | Take Screenshot | images/login.jpg | 80% | # Specify both name and width. |
    | Take Screenshot | width=550px      |     | # Specify only width. |

    The path where the screenshot is saved is returned.

Definition at line 174 of file Screenshot.py.

◆ take_screenshot_without_embedding()

def robot.libraries.Screenshot.Screenshot.take_screenshot_without_embedding (   self,
  name = "screenshot" 
)

Takes a screenshot and links it from the log file.

    This keyword is otherwise identical to `Take Screenshot` but the saved
    screenshot is not embedded into the log file. The screenshot is linked
    so it is nevertheless easily available.

Definition at line 185 of file Screenshot.py.

Member Data Documentation

◆ _given_screenshot_dir

robot.libraries.Screenshot.Screenshot._given_screenshot_dir
private

Definition at line 107 of file Screenshot.py.

◆ _screenshot_taker

robot.libraries.Screenshot.Screenshot._screenshot_taker
private

Definition at line 108 of file Screenshot.py.

◆ ROBOT_LIBRARY_SCOPE

string robot.libraries.Screenshot.Screenshot.ROBOT_LIBRARY_SCOPE = 'TEST SUITE'
static

Definition at line 86 of file Screenshot.py.

◆ ROBOT_LIBRARY_VERSION

robot.libraries.Screenshot.Screenshot.ROBOT_LIBRARY_VERSION = get_version()
static

Definition at line 87 of file Screenshot.py.

Property Documentation

◆ _log_dir

robot.libraries.Screenshot.Screenshot._log_dir = property
staticprivate

Definition at line 126 of file Screenshot.py.

◆ _screenshot_dir

robot.libraries.Screenshot.Screenshot._screenshot_dir = property
staticprivate

Definition at line 120 of file Screenshot.py.


The documentation for this class was generated from the following file: