Browse Category: Programming

Firebug, Firepath, and other developer tools.

Firebug, Firepath, and other developer tools.

First thing should come to your mind, what are Firebug and firepath and why do I need to learn this? The answer is pretty simple, you should know that what you want to tell your selenium code to perform some action, and where? As a human, you exactly know that where you want to click on the screen or what kind of items you like to interact with. If you want to click on third menu item out of six on the screen, your mind will tell your hand or finger to move the cursor to that menu item and click but in case of selenium or another test tool, your test code should know that unique location before the click. Firebug and firepath help you to make your life easier by identifying your target element in your Firefox browser.

Installation Steps:

Firefox Users


Start firefox browser, open URL and search for Firebug add-on. You will see the following screen. You may notice different version of firebug based on your existing firefox version. Add this extension to your Firefox by clicking button ‘Add to Firefox’.
Firepath Addon

This action may ask to restart your firefox. Make sure you do not have any unsaved changes on any firefox instance opened on your computer. Once Firefox restarts, you will see the following icon in the browser’s add-on area. Now you can start using firebug.



Firepath is firebug extension and adds a development tool to edit and identify XPath or CSS selector of web element. To install firepath, you need to do the same as firebug in above steps and restart the browser. Once browser started, you can start using it.


Now you want to understand about an element like HTML code, XPath, and properties of that target element. Take an example, my application under test is, and I want to click on ‘Add to Cart’ button on the Nexus phone. Take your cursor to the desired button or element, do right click and choose “Inspect Element with firebug’ as below.

Firepath Addon

As soon as you click on the last option in the above dialog, you will see developer tool open where you can see all HTML code for the web page. There is no need to go into detail with other tabs which I will go in later chapters.

Firepath Addon

you can see Firepath tab on the above screen too. Now you if you want to have your script to click on this button, you have to give the locator of the button. The locator is a unique address of an element on the webpage so that your script can find and act on it. To find the locator either you can right click on the highlighted element on the above screen inside developer tool and select “Copy XPath” or “Copy CSS Path” as given below and save in your script at an appropriate place.

Firepath Addon

Firepath can better help to get CSS or XPath than getting from here. Go to FirePath tab in firebug tool and click inspect element and then point to target element on the webpage. It will highlight target element and give you the option to choose XPath/classpath as per your choice as below.

Firepath Addon

In Chrome Browser

If you are using google chrome, developer tool is already there. You do not have to worry about. Put your mouse cursor to the element where you want to perform the action, and do right click and choose “Inspect”. Developer tool will automatically open. right click on the highlighted and you can choose to copy XPath or CSS Selector as below.

Firepath Addon

There are many chrome extensions are available which can help you to find locator from chrome browser. You can play along with them and see if those are easy enough to use. There is no perfect tool but each developer in the world building something which is making our life easier. You can see various tabs above and we will talk more about that some other time.


Thanks for reading and your valuable feedback is important to make this website helpful for others. Do not hesitate to correct if you find any mistake or unclear line. I will try to improve and update periodically.


Singleton Design Pattern

Singleton Design Pattern


In some cases, it is important to have exactly one instance of a class. Although you have many electric appliance in your house but you have only one main switch box for incoming electricity in house. You have only one control panel in your windows Operating system. There is only one payroll software system to handle paychecks.

How do you ensure that you have only one instance of a class and that is also easily accessible? A global variable makes an object accessible but it does not prevent you from instantiating multiple objects.

A better solution is to make class itself responsible for keeping track of its single instance. The class can ensure that no other instance can be created and it can provide a way to access the instance. This is called Singleton Pattern.


Whenever you are looking for single point of connection to use at multiple places. Best example is logging. To access logging process in a program in various classes you don’t want to end up with creating objects of logger class and access methods. Rather you would prefer to have one instance of class and use everywhere in solution or project. Thus in Singleton pattern, Information flows in one way.


Client can access a Singleton instance solely through Singleton’s Instance operation. Instance is a class operation similar to static member function in C++.


The Singleton pattern has several benefits.

1. Controlled access to its solo instance: Singleton class encapsulates its solo instance, which has strict control over how and when client can access it.

2. Flexibility over instances: Because the class controls the instantiation process, the class has the flexibility to change the instantiation process too.


1. Overhead: Though the is minimal time but still there is some overhead involving to check whether an instance class already exists every time an object request a reference.

2. Object lifetime:


Following implementation is singleton Pattern given in MSDN

using System;
public class Singleton {
	private static Singleton instance;
	private Singleton() {}
	public static Singleton Instance {
		get {
			if (instance == null) {
				instance = new Singleton();
			return instance;

Look at the code, you will notice at line 5; class constructor is defined as private which ensures that no other object can create a new instance of this Singleton class.

This implementation has two advantages:

1. Because instance has created inside the instance property method, the class can perform another actions as well like instantiating subclasses, though it may introduce unwanted dependencies.

2. Instantiation is not performed until an object asks for the instance.

The disadvantage of this pattern is that it is not safe in multi threaded environment. If at the same time, two separate thread ask for instance, it will check at line 10 before creating a instance. At this point, there is a possibility of race condition. To avoid that, Static Initialization is the solution.

Static Initialization

public sealed class Singleton
	private static readonly Singleton instance = new Singleton();
	private Singleton() {}
	public static Singleton Instance
			return instance;

In this strategy, member of the class is creating the instance first time inside class itself. The Common Language Runtime (CLR) will take care of variable initialization. The class is marked sealed to prevent any derivation. The variable marked as read-only, which means that it can be assigned only during static initialization or in the class constructor.

For detailed implementation of Singleton Design Pattern refer the section 4.


1. Design Pattern: Element of Reusable Object-Oriented Software By: Erich Richard Ralph and John.

2. MSDN Library.

Abstract Class Vs Interface


Often, an API is referred as a framework. We will consider a contract as an agreement that requires a developer to comply with the specification of an Application Programming Interface (API). As per English dictionary meaning of contract;


When using contracts, the developer is required to comply with the rules defined in the framework. This includes issues like method names, number of parameters, and so on. In short, standards are created to facilitate best practices for coding.

Enforcement is vital because it is always possible for a developer to breach the contract. But in the absence of a contract, a rough developer could decide to reinvent the wheel and write her own code rather than use the specification provided by the framework. In Java and the .NET languages, there are two ways to implement contracts are to use abstract classes and interfaces.

Abstract Classes:

One way to implement contract is via an abstract class. An abstract class is a class that contains one or more methods that do not have any implementation. Since every class is responsible for its own action but in this case, there are some methods which have no implementation thus they are abstract and that is why you cannot instantiate this class. Hence ‘abstract class cannot be instantiated’.

Let’s try to understand with an example. If I ask you to calculate an area, the first question you will be asking area of what? Circle or triangle or other. So the ‘CalculateArea’ is an abstract but area of circle or triangle not.  We can implement ‘calculateArea’ for circle and triangle separately.

We will try to understand using UML diagrams;


This reflects the true polymorphic system. Any class using this Circle can use draw method and implement differently and get different result set.  Let’s see in the form of code.

public abstract class Area {
public abstract double CaluclateArea();// no implementation for an abstract method

Note that this class does not provide any implementation for CaluclateArea method which makes this class abstract. There are two reasons it should be abstract, the first Area does not know what kind of area I am going to calculate and;

Second, we want a subclass of this base class to provide an implementation. i.e.;

public class Circle extends Area {
double radius = 2.0;
double PI=3.14;
public double CaluclateArea() {
return PI*(radius * radius);

To calculate Area of a triangle you can use as follows.

public class Triangle extends Area{
double base = 2;
double height =4;
public double CaluclateArea() {
return (base * height)/2;

If you ‘extends’ Area in Circle class and do not implement CalcualteArea method then the code will not compile and ask you to override and implement this method.

Though the concept of an abstract class is all around abstract method, there is nothing stopping Area from actually providing some concrete methods with complete implementation. Which is common to all subclasses.  Just make sure if you have abstract methods in abstract class then you have to override and implement abstract method in a subclass. If you do not implement all abstract methods then the base class should be abstract.

  • Remember

An abstract class is classified as strict inheritance, means is-a relationship works as opposed to an interface that is a has-a relationship which we will talk about in the next topic.


I am sure you must want to ask a question that if we have an abstract class that can provide the same functionality as an interface then why we need at the very first point.

Java and .NET do not provide multiple inheritances like C++. Java and .NET classes can inherit only one class so we can implement a number of interfaces.

Try to understand interface by UML diagram;


Note that in UML diagram Nameable is identified as an interface which distinguishes it from class. It has two methods GetColor() and SetColor ().

public interface Colorable {
String getColor();
void(String colorName);

In the above code, notice that Colorable is not declared as a class but as an interface. Thus, both methods, getColor() and setColor(), are considered abstract and there should be no implementation of any method in the interface.  You can point some difference between interface and abstract class.

  • An abstract class can have one or more abstract methods and methods with implementation while interface provides no implementation at all.
  • Subclass extends an abstract class but implements the interface.
  • Subclasses have to implement all methods of interface else give compiler error while you may or may not implement all abstract methods from abstract classes.  In case if you are not implementing all method, you need to make a subclass as an abstract class using abstract keyword.

  • 1
  • 2