'Takes a screenshot of the current page and embeds it into the log.
``filename`` argument specifies the name of the file to write the
screenshot into. If no ``filename`` is given, the screenshot is saved
into file _selenium-screenshot-{index}.png_ under the directory where
the Robot Framework log file is written into. The ``filename`` is
also considered relative to the same directory, if it is not
given in absolute format. If an absolute or relative path is given
but the path does not exist it will be created.
Starting from Selenium2Library 1.8 if ``filename`` contains _{index}_
characters, it will be automatically replaced with running index.
The running index is unique for each different filename. The absolute
path of the saved screenshot is always returned and it does not depend
does the ``filename`` contain _{index}_. See example 1 and 2 for more
details.
The _{index}_ is replaced with the actual index by using Python\'s
[https://docs.python.org/2/library/stdtypes.html#str.format|
str.format] method, and it can be formatted using the standard
[https://docs.python.org/2/library/string.html#format-string-syntax|
format string syntax]. The example 3 shows this by setting the width and
the fill character.
If there is a need to write literal _{index}_ or if ``filename``
contains _{_ or _}_ characters, then the braces must be doubled.
If _{index}_ is used, the computed filename will not overwrite
an existing file. The number chosen will be the first number
that results in a unique filename. For example, if the
computed name is screenshot-1.png but screenshot-1.png already
exists, screenshot-2.png will be tried, and so on, until a
unique name is found.
Example 1:
| ${file1} = | Capture Page Screenshot |
| File Should Exist | ${OUTPUTDIR}${/}selenium-screenshot-1.png |
| Should Be Equal | ${file1} | ${OUTPUTDIR}${/}selenium-screenshot-1.png |
| ${file2} = | Capture Page Screenshot |
| File Should Exist | ${OUTPUTDIR}${/}selenium-screenshot-2.png |
| Should Be Equal | ${file2} | ${OUTPUTDIR}${/}selenium-screenshot-2.png |
Example 2:
| ${file1} = | Capture Page Screenshot | ${OTHER_DIR}${/}other-{index}-name.png |
| ${file2} = | Capture Page Screenshot | ${OTHER_DIR}${/}some-other-name-{index}.png |
| ${file3} = | Capture Page Screenshot | ${OTHER_DIR}${/}other-{index}-name.png |
| File Should Exist | ${OTHER_DIR}${/}other-1-name.png |
| Should Be Equal | ${file1} | ${OTHER_DIR}${/}other-1-name.png |
| File Should Exist | ${OTHER_DIR}${/}some-other-name-1.png |
| Should Be Equal | ${file2} | ${OTHER_DIR}${/}some-other-name-1.png |
| File Should Exist | ${OTHER_DIR}${/}other-2-name.png |
| Should Be Equal | ${file3} | ${OTHER_DIR}${/}other-2-name.png |
Example 3:
| Capture Page Screenshot | ${OTHER_DIR}${/}sc-{index:06}.png |
| File Should Exist | ${OTHER_DIR}${/}sc-000001.png |'

@keyword
def capture_page_screenshot(self, filename='selenium-screenshot-{index}.png'):

    (path, link) = self._get_screenshot_paths(filename)
    self._create_directory(path)
    if hasattr(self.browser, 'get_screenshot_as_file'):
        if (not self.browser.get_screenshot_as_file(path)):
            raise RuntimeError(('Failed    to    save    screenshot    ' + link))
    elif (not self.browser.save_screenshot(path)):
        raise RuntimeError(('Failed    to    save    screenshot    ' + link))
    msg = '</td></tr><tr><td    colspan="3"><a    href="{}"><img    src="{}"    width="800px"></a>'.format(link, link)
    self.info(msg, html=True)
    return path
