Currently Browsing

Author Archive

How to read text from PDF file using Java and Selenium Webdriver

Sometimes we need to verify a PDF content but Selenium WebDriver doesn’t have any direct methods to do that.
If we want to extract the PDF content then we can use for example Apache PDFBox.
Simply download the .jar files and add them to your Eclipse Class path.
Here is a sample script which will extract text from a sample PDF file:

How to open a link in a new tab or window and switch to it with Selenium WebDriver

The following codes are works both in Firefox and Chrome browsers.

Open a link in a new window and switch to it:

How to count number of images available on a web page then download them using selenium webdriver?

The simplest way to gather the images from a website is to find them by tagName.
First we create a WebElement list with the elements which tagName is ”img”.
Then we check the elements to be sure that they are displayed.
If they are displayed then we get their names and sources.
To download them we use the “” function.
It is very simple, we just need to add the URL and the file path to it.
In the end we write out the number of displayed elements.

Here is to full code:

VisGrid – a GUI for Selenium Grid

VisGrid is a very useful GUI tool to start/stop the Selenium hub and to add/remove nodes to it.
First step to download the program from and to extract wherever you want.
We can start to program with the ‘VisGrid.jar’ file.


How to install and setup Jenkins

We use Ubuntu system as a base for this tutorial.
Before we want to install Jenkins we need to install Java JDK.
Ubuntu is using Openjdk, to install it type the following to terminal:

$sudo apt-get install openjdk-7-jdk

Ubuntu installs the JDK (in my case)to the /usr/lib/jvm/java-7-openjdk-amd64/  folder. In additional, Ubuntu also puts the JDK bin folder in the system path, via symbolic link (/usr/bin/java).To verify that JDK is installed properly, type:

java –version

The output would be something like this:

Reading test data from a CSV file using JUnit

It is recommended that we store the test data separately from the test scripts.
This data can be exported in CSV format. We can read CSV files using Java IO and utility classes.


In this blog, we will read data from a CSV file and use this data to execute the test script.

Creating a data-driven test with JUnit

We can create data-driven Selenium WebDriver tests using the JUnit parameterization feature. This can be done by using the JUnit parameterized class runner.
In this blog, we will create a simple JUnit test case to test Facebook registration. We will specify the test data within our JUnit test case class. We will use various JUnit annotations to create a data-driven test.

Here is a sample code how to create a data-driven test using JUnit.
Do the following steps:

Recording videos of tests in Java

In Java, we can extend Selenium WebDriver test scripts to record videos by using an open source tool named Monte Media Library.
In this blog we will look at how to configure and use the Monte Media Library’s ScreenRecorder class with Selenium, to record movies of tests.
ScreenRecoder supports the AVI and QuickTime formats for recording movies. The program provides multiple configurations for colors, mouse cursor, screen refresh rate, mouse rate, audio, and so on.
First step is to download the ScreenRecorder.jar file from the site or search  the net for it.
Second step is to add the ScreenRecorder.jar file to the project’s build path.

How to use Windows registry value from Selenium WebDriver

The WindowsUtils class provides various methods to interact with the registry on the Windows operating system. While running tests on the Windows operating system and Internet Explorer, the test might need to read and modify IE settings or there may be a need to get some settings related to the web server or database from the registry in tests, or if you simply want to store and read values from registry. The WindowsUtils class comes handy in these situations.

Read a Windows registry value

We need to import the org.openqa.selenium.os.WindowsUtils class and use the readStringRegistryValue() method for reading a registry value that is represented as a String.

How to connect multiple machines to the Selenium Grid hub

There might an instance in which we would want to run, for example, 50 tests in parallel.
50 browsers would consume the CPU power very fast, so we need to split the load between multiple machines.
Fortunately with Selenium Grid 2 this is not a problem.