behave_manners.screenshots module

Utilities for browser screenshots, connected to events

class Camera(base_dir='.')

Bases: object

A camera takes screenshots (or element shots) of the browser view

An instance will be attached to the behave context. Configured by site configuration. Then triggered each time a step explicitly wants a screenshot, or the hooks implicitly catching some failure.

capture_missing_elem(context, parent, missing_path)

Screenshot of browser when some element is missing

Parameters:
  • context – behave Context containing site and browser
  • parent – selenium.WebElement under which other was not found
  • missing_path – string of XPath missing
highlight_element(context, component=None, webelem=None, color=None, border=None)

Perform some action with an element visually highlighted

This should place a square rectangle on the DOM, around the element in question. The rectangle is appended into the root of the DOM to avoid any inheritance effects of the interesting element. After the action is performed, the highlight element is removed.

highlight_js = "\n var highlight = document.createElement('div');\n highlight.setAttribute('style',\n 'border: {border}; ' +\n 'border-radius: 1px; ' +\n 'background-color: {color}; ' +\n 'z-index: 9999; ' +\n 'position: absolute; ' +\n 'left: {x}px; top: {y}px; ' +\n 'width: {width}px; height: {height}px;');\n document.body.appendChild(highlight);\n return highlight;\n "
snap_failure(context, *args)
snap_success(context, *args)
take_shot(context, mode='')

Capture the full browser viewport.