Capturing screenshots with Selenium

28 Sep

web

Continuing from last weeks XML Data driven testing, this week i thought i’d cover a nice and easy feature of Selenium with, Capturing a screenshot for a test case

There are two ways to capture screenshots, you can use:

1, The Selenium command captureEntirePageScreenshot or

2, The Firefox add on Screen shot on fail

Option 1, From Selenium

From Selenium IDE, at the check point where you would like to capture the screenshot

1, Select the command ‘captureEntirePageScreenshot‘ from the command drop down box

2, Enter the directory and file name on your PC where you would like to save the file i.e.

Path = C:/01 Selenium/Madison Screenshots/X.png

3, Save the test case

Note:

Make sure the directory is created on your computer before running the test

This is what it should look like, note the target path, C:/01 Selenium/Madison Screenshots/X.png

ScreenShots

Reference

captureEntirePageScreenshot(filename, kwargs)

Arguments:
  • filename – the path to the file to persist the screenshot as. No filename extension will be appended by default. Directories will not be created if they do not exist, and an exception will be thrown, possibly by native code.
  • kwargs – a kwargs string that modifies the way the screenshot is captured. Example: “background=#CCFFDD” .
  • Currently valid options:
    background
    the background CSS for the HTML document. This may be useful to set for capturing screenshots of less-than-ideal layouts, for example where absolute positioning causes the calculation of the canvas dimension to fail and a black background is exposed (possibly obscuring black text).

Saves the entire contents of the current window canvas to a PNG file. Contrast this with the captureScreenshot command, which captures the contents of the OS viewport (i.e. whatever is currently being displayed on the monitor), and is implemented in the RC only

Option 2, using the GUI Selenium IDE Plugin

1, Install the Selenium IDE Plugin for Firefox

2, Restart Firefox

3, Select the new red Screen Capture Icon on the toolbar

Icon should be now displayed

Icon

4, Select the ‘Change reports folder’ from the drop down option and set the path to the directory on your computer i.e.C:\01 Selenium\Madison Screenshots

5, Confirm the option by selecting the Capture Icon again and selecting the option ‘View failure report’

6, Run your test case and view the screen shot

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: