Archive | September, 2015

Capturing screenshots with Selenium

28 Sep


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


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



captureEntirePageScreenshot(filename, kwargs)

  • 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:
    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


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

Selenium XML Data driven testing… sounds harder than it is.

15 Sep

Selenium is a tool which every tester is using because it is:

  • Open Source
  • Runs multiple tests at a time
  • Supports all browsers like IE, Firefox, Mozilla, Safari
  • Supports all programming languages Ruby,C#, Java and Python.
  • Supports all Operating Systems

Data driven testing means we can run the same test multiple times with different data from an external data XML file instead of using the same hard-coded values each time the test runs

Selenium IDE is a Firefox plugin to record the users use of the browser for testing purposes, by installing the browser extension Sel Blocks, we are able to do Data driven tests

A – To install Selenium IDE
1, Download the latest Selenium IDE version
2, Install the Add-on
3, Restart Firefox
4, From the Firefox application, select Tools then Select Selenium-IDE

Next to do XML data driven testing we need to install SelBlocks

B – To Install SelBlocks
1, Download the latest Selenium SelBlocks version.
2, Install the Add-on
3, Restart Firefox
4, From the Firefox application, select Tools then Select Selenium-IDE

To Do XML Data driven testing, we need to create an XML file, a file with one record would look a bit like this

Example 1:
<vars Email=”” firstname=”First1″ lastname=”LastName1″ password=”123456″ rpassword=”12345″ npassword=”12345cc”/>

Parameterised data source:


C – Create the directory: ’01 Selenium’ on the C drive of your computer

D – Save the following files to the directory called ‘C:\01 Selenium’ on your computer

A, Test.xml
B, Create_Account.HTML

Please Note:

Each time you run this test, you must edit and update the Test.xml file with a unique email address for your test run

Parameterised data displayed in the Selenium IDE

Parameter_DataXE – To run the script:

1, Launch Firefox

2, Launch Selenium IDE

3, Open the Test Case ‘Create_Account’ in ‘C:\01 Selenium’

4, Run the Test Case ‘Create_Account’

Whats happening when you run this?
1, The script is creating an account for every entry in the XML file for a demo shopping site

2, ‘forXml’ command in the script is used to set the target of the XML file’s path. The script ends by adding ‘endForXml’, both these command are provided from the SelBlock Add-on.

3, The variable in test data file is caled by using ‘${VARIABLE}’ in the syntax.

4, When this test is executed, Sel Blocks loads the content of XML file in memory and executes the script for number of times <vars> element present in the XML file.

5, In this example it will execute the test twice. Once you see it working, it is easy to copy and paste more data to be created

6, For all the attributes mentioned in <vars> element, Sel Blocks create internal variables that we can substitute as Selenium command parameters.

Selenium Log:

Selenium log

F – To do:
1, Analyze the Selenium IDE Log tab for the results.
2, If the expected data and actual data do not match, an error is reported in the Selenium IDE Log tab.

I hope this helps some people get started with some data driven tests, until the next time

%d bloggers like this: