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

firebug:

Start firefox browser, open URL https://addons.mozilla.org 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:

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.

Usage:

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, http://www.donethedeal.com/ 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.

 

Selenium versus HP LeanFT

Selenium has carved a niche in the software testing tools world, and has a dedicated user base with consistently increasing adoption in the last few years. While this tool was always popular with Open Source enthusiasts since the RC days, we now have increased acceptance in enterprises as well. In the last couple of years, quite a few Fortune 500 companies and banks have diversified their skill-base and tool portfolio with Selenium, in addition to traditional HP toolset.


Let’s look at a recent product offering in the market-place, which could be very relevant to continued growth of Selenium user base. This post describes a brief analysis of HP LeanFT with respect to Selenium. Unsure if Learn-Selenium blog is the right medium for comment on HP tool, but it seems that this tool is HP’s response specifically to counter the increasing popularity of Selenium in the testing world.

Selenium – what has worked

1. Cost. Cost. Cost.

Cost by far remains the biggest differentiator for Selenium. Being open-source, this becomes the automation tool of choice for browser based applications in small and medium enterprises. Vibrant user community and strong support base help mitigate concerns around open source usage in enterprises. HP licensing is disproportionately expensive.

2. Object Identification

As web technologies get advanced, we have third party toolsets that cause issues in object identification during automation with HP QTP-UFT. AngularJS, Ajax, Oracle Forms are examples. While HP keeps refining with every version, there are easy alternatives. Selenium uses XPATH, and identifies objects where we face challenges in detecting unique properties using QTP.

3. The Buzz around Dev-Ops

Dev-Ops is the approach of leveraging test assets and automation in Development and Operations. With increasing agile adoption, the lines blur between traditional roles of developer, functional tester, and test automation specialist.

Application Development Leads and Architects are interested in test-automation for continuous integration, build sanity, and unit-testing. This is a community with expertise in Java/C#, and very comfortable with IDEs like Eclipse. They find it difficult to digest that anything worthwhile can be done with VBscript. These stakeholders are often key influencers in management decision-making on Enterprise Tool Usage, leading to increased acceptability for Selenium in large enterprises.

4. Multi-browser Testing

Even today, Selenium is a clear winner in cross-browser testing against UFT. Multiple UFT add-ins have to be tried for different browser versions and we have compatibility issues. Examples – UFT 11.5 does not support Chrome v40, you need to downgrade to Chrome v36 for automating scripts, which would not be in sync with production. HP license upgrades do not keep pace with browser version changes.

Selenium – where it falters

1. End-To-End Automation

Large Enterprises have multiple applications under test and end-to-end testing flows that traverse more than one application. Any tool restricted to browser testing would limit coverage of automation. Example – A very common scenario in banking systems would be transaction initiated on front-end web application that would have validation step on mainframe and backend database.

2. Object Identification and Script Build Productivity

While XPATH usage helps identify problematic objects, we have lot of instances where QTP can easily get unique property index, which may be cumbersome in Selenium. HP QTP/UFT are feature rich and easy to use. Invariably, script build productivity is higher as compared to Selenium, although this would vary based on application under test.

3. Skill-base and staffing

HP QTP has been the industry leader since ages, and sourcing experienced automation testers skilled in coding with VBscript is relatively easier. In comparison, ramping a project team on Selenium skills may be more of a challenge. Note- this is a snapshot as of mid-2015, things change very fast.

HP LeanFT – What’s on offer

Circa 2015 July, HP has introduced LeanFT along with the UFT 12.5 upgrade. Refer the figure below.

image

    Figure: Reproduced from datasheet on HP home-site

We have detailed below features and observations of LeanFT, which bear relevance to the analysis above.

1. LeanFT provides Support for multiple IDEs (Eclipse, Visual Studio) and coding languages (Java, C#).

HP keeps pushing features every few years to retain its dominance (and premium licensing), BPT was introduced to sell the concept of BA–Tester, now LeanFT is built to whet the interest of the Dev-Tester. IDE and language flexibility would make the tool popular with the Application Developers community.

2. Dev-Ops and CI support. LeanFT supposedly integrates well with standard SCMs, build/deploy tools and approaches, as compared to UFT which is heavily ALM centric. Selenium was an easy choice compared to QTP in building CI/CD solutions closely integrated with dev-workflows. This may change with LeanFT and needs to be investigated.

3. Object identification & Multi-browser support. LeanFT has an object identification engine similar to Spy in UFT which is installed as plug-in to the IDE. This is an advantage and could be quite powerful. HP datasheet indicates LeanFT to be light weight tool with good cross browser support. This could potentially address a gap in HP toolset where Selenium has an edge over QTP.

4. Cost: LeanFT licenses are free for HP UFT12.5 users, this helps penetrate the existing user base in large organizations and halts the move to Selenium.

5. We have clean integration of LeanFT with UFT12.5, which aids in end to end automation. This permits automation beyond browser based applications, a clear advantage over Selenium in organizations like banks and insurance companies.

6. QTP-skilled staff have no learning curve to start automation using LeanFT. Existing resources can be used for automation, as against Selenium projects which need well-thought out staffing and training strategy.

To Conclude:

It seems that LeanFT has been specifically targeted at the Selenium user base – would be very interesting to see how this pans out in the marketplace in the next 12 months. Much of the recent increase in Selenium projects has been because of large organizations seeking to diversify their tools portfolios. Technology trends are extremely dynamic and you prepare today for anticipated changes or risk obsolescence. Would LeanFT stem the tide? – We would watch the events and follow up on this in another six months.

Rest API Testing using C#

Rest API has become very popular and it’s nowadays, it is kind of must-have skill set to have for any developer or tester. In Every other job description, you can see having experience with API with always preferred. REST API is most popular and you can see Facebook, Twitter, Flickr etc. are coming with APIs and you can build your own application based on that. All major products are providing API interface so developers can utilize and build own product based on the data provided by API services. In this article, I will explain to you how to use REST web services using C#. Along with explanations, I would keep writing different part of code There.




Rest stands for Representational State Transfer (ReST). It relies on stateless, client-server, cacheable communication protocol mainly running over HTTP protocol. Thus RESTful services are URL based https://api.product.com/categories/machines/id/123

Consumers are capable of sending GET, POST, PUT and DELETE verbs and these verbs indicate you what the purpose of the request. There are many other verbs can be used with rest but these are being used heavily across the products.

Verbs:

GET:

To read specific resource or collection of resources.

POST:

create a new resource

PUT:

Update a specific resource or collection of resources.

DELETE:

Remove specific resource based on the identifier.

 

Resource:

You resource is in URL. Resources are viewed via their URI names, offering consumers a friendly name, the easily understandable hierarchy of resource into that. There is some standard but restrict the rule to have into resources structures.

  • a. identifier should be in URL instead of into query. It’s good to have /serialnumbers/1234 instead of /api?rnum=1234.
  • b. Resource name should be a noun instead of verb else it may confuse with our request verbs.
  • c. Keep URL as short as possible.
  • d. avoid hyphen(-) or underscores(_).

Response:


Response with status code is part of the HTTP specification. There are tons of status code you can find on the internet. Refer w3.org or RestAPITutorial. I will list my Top 5 which you should memorize and this can be part of your interview too.

  1. 200 OK: Success code.
  2. 201  CREATED: Successfully created happened using POST/PUT.
  3. 401 UNAUTHORIZED:  In response to missing token or invalid authentication.
  4. 404 NOT FOUND: This error occurred when resource not found.
  5. 500 INTERNAL SERVER ERROR: Usually this happens when the server is down.

Moreover, RESTful services also support JSON and XML. You can get output in either format.

Usage:

 

Writing Rest Client in C#:

Let’s start with C#. First, we need to think what we want. It’s simple, we want to create a client at our end where we can use REST API to access or manipulate the different type of resources via URL because all resources are mapped to URL only. Now you solved many things. Read again previous lines and you will find some special words, ‘access or manipulate resource’, ‘url’ and ‘different type of resource’. Since REST is URL based and you access the resource via URL then you call the url as ‘EndPoint’. Type of resources is termed as ‘Content Type’ and access are termed as ‘httpVerb(get/post/put/delete/….)’  and if you need some data to manipulate then this will be termed as ‘Post Data’.

first, we will try to access some API via browser or by using API client as a chrome extension and see the output and later we will write code to replicate the same. One the Rest API service I found is http://restcountries.eu/ this is one of the most simplest REST API I have seen where you do not need to register or use app id to access resources.  We will use these API to learn how to access via client and try to write code which can accommodate both simple and complex type of APIs.

Install PostMan Rest Client in your chrome browser. Open PostMan and supply endpoint to get Calling Code as given in http://restcountries.eu/https://restcountries.eu/rest/v1/callingcode/65

 

you can notice above that you are using verb GET from end point “” and once you click on send button you are getting response in JSON. You can change the format from that drop down and see the response.

based on above screenshot you lets design the client via code. You need to create first client class and this client class should have above attributes.

httpVerb –> GET/POST/PUT/DELETE

endpoint –> some url

ContentType –> json/xml/html

since we need multiple verbs so we can have enum of httpVerb.

public enum httpVerb
{
GET,
POST,
PUT,
DELETE
}

Now create client class  and have all properties into that class that required for accessing resources.

to for and have multiple constructor using method overloading just in case if you like to

public class Client
{
public string EndPoint { get; set; }
public Verb Method { get; set; }
public string ContentType { get; set; }
public string PostData { get; set; }

public Client()
{
EndPoint = "";
Method = Verb.GET;
ContentType = "application/JSON";
PostData = "";
}

public Client(string endpoint, Verb method, string postData)
{
EndPoint = endpoint;
Method = method;
ContentType = "text/json";
PostData = postData;
}

}

Once you have object you need methods to perform the the actions on the object. You need to write a method MakeRequest which should perform real action utilizing all variable in that object. Lets work on GET/POST request first.

public string Request(string parameters)
{
var request = (HttpWebRequest)WebRequest.Create(EndPoint + parameters);
request.Method = Method.ToString();
request.ContentLength = 0;
request.ContentType = ContentType;

using (var response = (HttpWebResponse)request.GetResponse())
{
var responseValue = string.Empty;

if (response.StatusCode != HttpStatusCode.OK)
{
var message = String.Format("Faile: Received HTTP {0}", response.StatusCode);
throw new ApplicationException(message);
}

using (var responseStream = response.GetResponseStream())
{
if (responseStream != null)
using (var reader = new StreamReader(responseStream))
{
responseValue = reader.ReadToEnd();
}
}

return responseValue;
}
}

Now its time to call the class and create rest client object and call method to access to your object.

 

In your main method, create client object and supply required info and call appropriate method.

var client = new Client();
client.EndPoint = @"<a href="https://restcountries.eu";">https://restcountries.eu";</a>
client.Method = Verb.GET;
var pdata = client.PostData;
var response = client.Request("/rest/v1/currency/eur");

You can see parse response and get your desired output in JSON.

You can find complete code here.

using System;
using System.IO;
using System.Net;
using System.Text;

public enum Verb
{
GET,
POST,
PUT,
DELETE
}

namespace RestAPITesting
{
class Program
{
static void Main(string[] args)
{

var client = new Client();
client.EndPoint = @"https://restcountries.eu";
client.Method = Verb.GET;
var pdata = client.PostData;
var response = client.Request("/rest/v1/currency/eur");
}
}
public class Client
{
public string EndPoint { get; set; }
public Verb Method { get; set; }
public string ContentType { get; set; }
public string PostData { get; set; }

public Client()
{
EndPoint = "";
Method = Verb.GET;
ContentType = "application/JSON";
PostData = "";
}

public Client(string endpoint, Verb method, string postData)
{
EndPoint = endpoint;
Method = method;
ContentType = "text/json";
PostData = postData;
}

public string Request()
{
return Request("");
}

public string Request(string parameters)
{
var request = (HttpWebRequest)WebRequest.Create(EndPoint + parameters);
request.Method = Method.ToString();
request.ContentLength = 0;
request.ContentType = ContentType;

using (var response = (HttpWebResponse)request.GetResponse())
{
var responseValue = string.Empty;

if (response.StatusCode != HttpStatusCode.OK)
{
var message = String.Format("Faile: Received HTTP {0}", response.StatusCode);
throw new ApplicationException(message);
}

using (var responseStream = response.GetResponseStream())
{
if (responseStream != null)
using (var reader = new StreamReader(responseStream))
{
responseValue = reader.ReadToEnd();
}
}

return responseValue;
}
}

}
}