Saturday, March 1, 2014

Using Configuration (Config File) While Test Automation.

It is always advised to use a config file in your test automation. The purpose of having a config file is to have few variables outside of code so that if you can change variables' values without changing your code.

To use a config file in Java, Apache's common configuration jar is very popular and easy to use.

Download the latest version of these jar and add them to Project's Build Path.
commons-lang-2.6.jar
commons-configuration-1.10.jar

Here is the sample code to read config:

public static void InitializeConfiguration()  
{
        PropertiesConfiguration propertyConfigFile;
try
{
propertyConfigFile = new PropertiesConfiguration();
String config = "/config/config.txt"; //Location of config file
propertyConfigFile.load(config);

        //Read variable from config 
        String url = propertyConfigFile.getProperty("qaURL").toString();
}
catch(ConfigurationException e)
{
System.out.println("Error Occured While Reading Config File");
}

}

Copy the below line in a notepad and save it with some valid extension. qaURL is the variable being called in above program. This will serve the purpose of a config file.
## is used to comment the line.

Sample:

## Please provide the URL here:
qaURL = https://www.google.com





Reading and Writing Excel Sheet

Reading and Writing Excel Sheets:

While automating your tests using selenium, its quiet frequent to use excel sheet as Object Repository or test data sheet or may be a result sheet.
Here I am gonna tell you some ways to read / write excel sheet in Java for Selenium Web Driver.

There are various third party libs are available to handle excel operations, popular ones are POI and JXL.

Writing an Excel File Using JXL: 

Before you start using JXL, you need to download the latest version of jxl.jar and attach it to Java Build Path of your project.

ixl can be downloaded from http://www.quicklyjava.com/jexcel-jar-download/

This is sample code to write a 2 D Array in an excel sheet.


Few Points to remember while writing an excel sheet:

1. Always use sheet.addCell(string) method to write the contents in excel sheet.
2. Always remember to close the workbook after writing.
3. Always use Exception Handling and use these book.write(); book.close(); in Finally block so that even if there is any exception and code exception is broken then at least the previous data till exception is written in excel sheet otherwise there won't be any data in excel sheet.





Reading an Excel File Using JXL: 

Sample code to read an existing excel sheet:






Sunday, January 19, 2014

Various Useful Functions Required While Automation:


I'll be posting few important and frequently used functions during implementing Automation:

1. Reading Excel Sheet.

2. Writing Excel Sheet.

3. Working with Result Set.

4. Connecting to MS SQL / MySQL Database.

5. Using Configuration (Config) file.

Friday, December 6, 2013

Test Automation Using Selenium !!

Hello everyone !! 


Recently Me and my colleague Mr. Vinod Krishnan realised the need of a platform where all real time problems can be discussed which intern help our testers in solving the problems as well as enhancing their knowledge. 

This forum is going to be beneficial for guys who are involved in software testing. I'll be posting topics which may be very useful not only for automation guys but also for manual testers !! You may throw your problems here and we'll try to find solution for them. I'll try to publish maximum information or at least the revenant URLs. Our main focus will be on real time problems which we face during our automation implementation.


Prerequisite for Automation:

1. Before going into any kind of automation in terms of testing, few points to remember:
  • Do you actually need any kind of automation.
  • If yes then where you are going to use it.
  • What kind of tool you'll be using like freeware, licensed etc.. 
  • if freeware, then which tool you require, always analyse the language capability of the tester. 
  • How frequently the automated scripts will be used.
  • How dynamic are the changes being thrown into test application.  

2. After you conclude that you can not avoid test automation and you have to use some tool, then understand automation.

3. Test Automation can be achieved by some simple code written in Python, VB Script, JAVA or Java Script, Batch files or may be some macro like iMacro ( for Browser level automation ) etc… so before you opt for any automation tool, always see if any of the above can serve your purpose.

4. Once you are through to all the above analysis and you've decided to go for some tool and if that is Selenium, then we'll plan each step right from the installation to write the first test. Most common language of writing code in Selenium is Core JAVA, so before you jump onto Selenium, refresh your Core Java and OOPS knowledge. Its simple and interesting to learn.

Here is the link which has basic tutorial for beginners, please take a look at it.

http://www.javatutorialhub.com/java-tutorial.html

5. Lets talk little about Selenium. Selenium supports these languages - Java, Python, Ruby, C#, PHP, Perl and these Browsers - Mozilla Firefox (inbuilt support), Internet Explorer, Google Chrome, Safari etc. Selenium has three components -
  • Selenium IDE - IDE is a plugin supported by only Mozilla Firefox. Using this plugin, you can record your actions and play them back. See the below URL for detailed installation and use of IDE. This part of Selenium is not used or maybe used by 1 % in IT Industry because of its limitation in features like - lack of data driven testing by using some excel sheets, mouse clicks, etc...
http://www.guru99.com/install-selenuim-ide.html
  • Selenium WebDriver - This component is an improved version of Selenium Remote Control or RC. Selenium RC is depreciated now because of a third party involvement between Browser and  automated scripts. Selenium WebDriver interacts Browser directly eliminating any intermediates.  We'll be discussing Selenium WebDriver primarily. 
  • Selenium Grid - Selenium Grid allows the Selenium WebDriver code to run simultaneously into various machines at the same time. Mainly Selenium Grid is useful in Browser Compatibility Testing which very common and frequent now a days. 
6. Selenium doesn't have any UI so you can't record your action and play them back. You've to write code in Core Java like a developer. To achieve this you need an Integrated Development Environment where you can write your code and run your automation script. Eclipse Juno is a popular and easily available tool or IDE.

7. Here is the URL which has the detailed information along with screenshots to install Eclipse and configure Selenium WebDriver into it. Remember Selenium WebDriver is a collection of Java - Jar files which you need to add in your project, see the detailed description at this URL -

http://www.guru99.com/installing-selenium-webdriver.html  


Baby Steps For Automation:

Any code irrespective of development or testing should be reusable. There should be minimum effort to be applied to maintain the code. To achieve this, we develop Framework. There are lot of framework available in market with lot of annotations which can be directly used in your test code. Some of widely used frameworks are - TestNG, JUNIT, Robitium etc.

We'll be discussing more about TestNG framework, its an improved version of JUNIT framework.

Steps:

1. Test Data:
  • First thing to see if test will be data driven and if yes then how the data will be stored or used for implementation.
  • Microsoft Spreadsheet is widely used for maintaining the data.

2. Coding:
  • Utilise the code or break the code into small functions so that the code can be utilised wherever required.

3. Reporting:
  • How the results will be reported to end user may be some client. For sharing results, we'll be using ReportNG framework, which will be explained little later.