19 from robot.utils
import get_link_path
47 path = os.path.abspath(path)
49 previous = self.
ctxctx.screenshot_root_directory
50 self.
ctxctx.screenshot_root_directory = path
87 self.
infoinfo(
'Cannot capture screenshot because no browser is open.')
92 raise RuntimeError(
"Failed to save screenshot '{}'.".format(path))
117 self.
infoinfo(
'Cannot capture screenshot from element because no browser is open.')
121 element = self.
find_elementfind_element(locator, required=
True)
122 if not element.screenshot(path):
123 raise RuntimeError(
"Failed to save element screenshot '{}'.".format(path))
129 filename = filename.replace(
'/', os.sep)
133 formatted = filename.format(index=index)
134 path = os.path.join(directory, formatted)
136 if formatted == filename
or not os.path.exists(path):
140 target_dir = os.path.dirname(path)
141 if not os.path.exists(target_dir):
142 os.makedirs(target_dir)
147 self.
infoinfo(
'</td></tr><tr><td colspan="3">'
148 '<a href="{src}"><img src="{src}" width="{width}px"></a>'
149 .format(src=get_link_path(path, self.
log_dirlog_dirlog_dir), width=width), html=
True)
def find_element(self, locator, tag=None, required=True, parent=None)
Find element matching locator.
def info(self, msg, html=False)
def capture_element_screenshot(self, locator, filename='selenium-element-screenshot-{index}.png')
Captures screenshot from the element identified by locator and embeds it into log file.
def _create_directory(self, path)
def _embed_to_log(self, path, width)
def _get_screenshot_path(self, filename)
def set_screenshot_directory(self, path)
Sets the directory for captured screenshots.
def capture_page_screenshot(self, filename='selenium-screenshot-{index}.png')
Takes screenshot of the current page and embeds it into log file.