assertScreenshot() takes two arguments: a CSS selector for the element to
capture, and a filename for the image.

The following example uses the same my_test.py test case shown in the
previous section, with an assertion added to check that the site logo for the
edx.org home page has not changed.

The first argument, img.site-logo is the css locator for the element
that we want to capture and compare.

The second argument, edx_logo_header is the filename that will be used
for both the baseline and the actual results. The .png extension is appended
automatically.

Note

For test reliability and synchronization purposes, a bok-choy best
practice is to employ Promises to ensure that the page has been fully
rendered before you take the screenshot. At the very least, you should
first assert that the element you want to capture is present and visible on
the screen.

Setting the viewport’s size - This feature is particularly useful for
predicting the size of the resulting screenshots when taking full screen
captures, and for testing responsive sites.

Difference engine - Instead of PIL (the default), you might want to use
PerceptualDiff. In addition to being much faster than PIL, PerceptualDiff
generates a diff PNG file when a test fails, highlighting the differences
between the baseline image and the new screenshot.

File cleanup - Each time you run tests, new screenshot images are saved to
disk, for comparison with the baseline screenshots. You might want to set
your configuration to delete these files for all successful tests.