Click here to Skip to main content
13,834,324 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


9 bookmarked
Posted 14 Nov 2012
Licenced CPOL

Reuse selenium webdriver solution

, 14 Feb 2013
Rate this:
Please Sign up or sign in to vote.
This article describes how to reuse web driver when selenium test crashes or how to debug selenium scripts on the fly.


It's been a while since I have been working with Selenium but once I've started the main problem have risen: "in order to debug a selenium script one needs to rerun the script from the first step", well, that's borring. So I was checking for a solution to overcome this issue. RMI has come into my mind from the first of the beginning.


My aim is to get the WebDriver from a different application so that every time script crashes I am able to start the debug from the last executed function. Also I want to have the posibility to develop a small script to check the page in order to find the problems in it.

I am a QTP developer and from my experience I have found that "find elements in the page" is the most frequent problem. But QTP besides Selenium has a big advantage: it can start run from any point of your script. Taking this into account I've realised that I need this QTP feature into Selenium. So starting with RMI I have made a two applications: a Server with WebDriver and a Client with Selenium scripts. The Server will hold the webdriver during the development of the testing script.

The code is written in Eclipse Juno with JRE 7 installed. I am using Maven to load the required libraries. If you are not familiar with RMI please consider the following resource before going further:

Before starting to run the sollution, install maven plugin, here is a good tuorial:

To run in debug mode, start the server: WebDriverWrapper has the main function impemented so you can run it as a java application.

The Server.

RMI interface:

public interface ReceiveMessageInterface extends Remote
 void startup(String x) throws RemoteException; 
 public void close() throws RemoteException;
 public WebElement findElement(By arg0)  throws RemoteException;
 public List<WebElement> findElements(By arg0)  throws RemoteException;
 public void get(String arg0)  throws RemoteException;
 public String getCurrentUrl()  throws RemoteException;
 public String getPageSource()  throws RemoteException;
 public String getTitle()  throws RemoteException;
 public String getWindowHandle()  throws RemoteException;
 public Set<String> getWindowHandles()  throws RemoteException;
 public Options manage()  throws RemoteException;
 public Navigation navigate()  throws RemoteException;
 public void quit()  throws RemoteException;
 public TargetLocator switchTo()  throws RemoteException; 

Here is the WebDriverWrapper constructor:

private WebDriverWrapper () throws RemoteException
  // get the address of this host.
  thisAddress= (InetAddress.getLocalHost()).toString();
 catch(Exception e){
  throw new RemoteException("can't get inet address.");
 thisPort=3232;  // this port(registry?fs port)
 System.out.println("this address="+thisAddress+",port="+thisPort);
 // create the registry and bind the name and object.
 registry = LocateRegistry.createRegistry( thisPort );
  registry.rebind("rmiServer", this); 
 catch(RemoteException e){
 throw e;

...this script does nothing more than putting the WebDriverWrapper via ReceiveMessageInterface into JVM registry.

The Client.

In "real life testing" you can use WebDriver interface for testing:

WebDriver driver = FirefoxDriver();

In debug mode change the above line to this:

ReceiveMessageInterface driver = DriverFactory.getDriver();

On the client side we obtain the loaded driver from the server and use it via the ReceiveMessageInterface.

DriverFactory.getDriver() method is a pseudo factory fuction in this example.


Additional comments

For each WebDriver functionality you'l need to update the RemoteMessageInterface and implement the method in the Wrapper class, in order to use it in the script.


Version 2


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Mircea Sirghi
Software Developer Endava, Chisinau
Moldova (Republic of) Moldova (Republic of)
Graduate: Romania, University of Bucharest, Mathematical - Informatical faculty.

You may also be interested in...


Comments and Discussions

Questionnot able to check for driver.findElement(By) Pin
Member 1046911216-Dec-13 0:08
memberMember 1046911216-Dec-13 0:08 
GeneralHelp needed Pin
Member 971629628-Dec-12 10:16
memberMember 971629628-Dec-12 10:16 
GeneralRe: Help needed Pin
Mircea Sirghi14-Feb-13 3:33
memberMircea Sirghi14-Feb-13 3:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web03 | 2.8.190114.1 | Last Updated 14 Feb 2013
Article Copyright 2012 by Mircea Sirghi
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid