Wednesday, October 13, 2010

DataProvider in TestNG


There are many functions provided by TestNG and you can use them in different ways one of them I will mention in this blog.

@DataProvider
A DataProvider provide data to the function which depends on it. And whenever we define a DataProvider it should always return a double object array “Object[][]”. The function which calls dataprovider will be executed based on no. of array returned from the DataProvider. For ex.
@Test(dataProvider="data")
public void printMethod(String s){
  System.out.println(s);
 }

@DataProvider(name="data")
public Object[][] dataProviderTest(){
return new Object[][]{{"Test Data 1"},{"Test Data 2"},{"Test Data 3"}};
}

The Output will be:
Test Data 1
Test Data 2
Test Data 3

As you can see that the Test method “printMethod ” gets called 3 times depending upon the data that was provided by the DataProvider.
The DataProvider can be used for getting data from some file or database according to test requirements.

Following I will mention two ways to use DataProvider:
For ex.
You need to get data from a file and print each line to the console. For doing that you had written some File Processing API that will return a List of the data read from file.
You can iterate on the List at the DataProvider level as well as at the test method level. Both I am mentioning below.
1.
@DataProvider(name = "data")
 public Object[][] init1() {
  List list = fileObject.getData();
   Object[][] result=new Object[list.size()][];
   int i=0;
   for(String s:list){
    result[i]=new Object[]{new String(s)};
    i++;
   }
 return result;
 }
@Test(dataProvider="data")
public void runTest1(String s){
  System.out.println("Data "+s);
 }
In this Implementation we are iterating over the List at the DataProvider level and storing it to another Object[][] result and returning the result.
This implementation will call the test method depending upon the List size.

2.
@DataProvider(name = "data")
public Object[][] init() {
  List list = fileObject.getData();
   
 return new Object[][]{{list}};
 }


@Test(dataProvider="data")
public void runTest(List list){
  for(String s:list){
   System.out.println(“Data” + s);
  }
 }
In this Implementation we are returning the List itself to the test method and method will iterate over the List data. Both implementation can be used based upon test requirements.

Output of both the implementation shown above remains the same. The only thing that changes is the way you return the data and Iterate.


Thursday, June 17, 2010

Generating a Junit Report for TestNG execution

Now a days everyone is using TestNG in place of Junit and as part of Selenium execution.

TestNg provides a lot of added features. One of the good thing it provides is test execution results in the form of XML. We can use this XML file for other type of report format generation. One of them is Junit reporting.


In this blog I will mention how to generate a Junit report for a TestNG execution.
Below ant target will generate the Junit report for the TestNG execution results.




        
        
            
                
           
            
        


In the above ant target you need to specify the path to the TestNG results xml file in the "dir" attribute under the "fileset" tag.

You need to mention the path where you want to generate the Junit report in the "todir" attribute under the "report" tag.

Also you can mention whether you want the Junit report with frames or without frames in the "format" attribute under the "report" tag.

Thursday, May 13, 2010

Generating selenium reports using TestNG-xslt through Ant

TestNG-xslt generates user friendly reports using the TestNG results output (testng-results.xml). Its uses the pure XSL for report generation and Saxon as an XSL2.0 implementation.

Most of the material is taken from the original site.
 http://code.google.com/p/testng-xslt/


Alternative link to download. Please open the said link and download it by going to File -> Download option.

I will tell in this blog how to implement this report for your project. This implementation will tell you how to generate the testng-xslt report using ant. If your current project does not use ant build then you can use ant only for the report generation purpose.

If you dont know ant please check the Apache ant website http://ant.apache.org/.

For generating testng-xslt report for your project do the following:
1. Download the testng-xslt
2. Unzip and copy the testng-results.xsl from the testng-xslt folder(testng-xslt-1.1\src\main\resources) to your own project folder.
3. Now copy the saxon library from (testng-xslt-1.1\lib\saxon-8.7.jar)to your project lib folder.
4. Modify your build.xml of ant and add the following target to it.


<project name="test" basedir=".">
    <property name="LIB" value="${basedir}/libs" />
    <property name="BIN" value="${basedir}/bin" />
    <path id="master-classpath">
        <pathelement location="${BIN}" />
        <fileset dir="${LIB}">
            <include name="**/*.jar" />
        </fileset>
    </path>
    
    <target name="testng-xslt-report">
        <delete dir="${basedir}/testng-xslt">
        </delete>
        <mkdir dir="${basedir}/testng-xslt">
        </mkdir>
        <xslt in="${basedir}/test-output/testng-results.xml" style="${basedir}/testng-results.xsl" out="${basedir}/testng-xslt/index.html">
            <param expression="${basedir}/testng-xslt/" name="testNgXslt.outputDir" />

            <param expression="true" name="testNgXslt.sortTestCaseLinks" />

            <param expression="FAIL,SKIP,PASS,CONF,BY_CLASS" name="testNgXslt.testDetailsFilter" />

            <param expression="true" name="testNgXslt.showRuntimeTotals" />

            <classpath refid="master-classpath">
            </classpath>
        </xslt>
    </target>
</project>


The XSL transformation can be configured using the parameters described below.

  • testNgXslt.outputDir - Sets the target output directory for the HTML content. This is mandatory and must be an absolute path. If you are using the Maven plugin this is set automatically so you don't have to provide it.
  • testNgXslt.cssFile - Specifies and alternative style sheet file overriding the default settings. This parameter is not required.
  • testNgXslt.showRuntimeTotals - Boolean flag indicating if the report should display the aggregated information about the methods durations. The information is displayed for each test case and aggregated for the whole suite. Non-mandatory parameter, defaults to false.
  • testNgXslt.reportTitle - Use this setting to specify a title for your HTML reports. This is not a mandatory parameter and defaults to "TestNG Results".
  • testNgXslt.sortTestCaseLinks - Indicates whether the test case links (buttons) in the left frame should be sorted alphabetically. By default they are rendered in the order they are generated by TestNG so you should set this to true to change this behavior.
  • testNgXslt.chartScaleFactor - A scale factor for the SVG pie chart in case you want it larger or smaller. Defaults to 1.
  • testNgXslt.testDetailsFilter - Specified the default settings for the checkbox filters at the top of the test details page. Can be any combination (comma-separated) of: FAIL,PASS,SKIP,CONF,BY_CLASS
You need to provide the testng-xslt stylesheet the TestNG results xml(testng-results.xml) , the path to the style sheet testng-results.xsl and the output index.html path.

Also dont forget to add the saxon library to your target classpath else you will get an error. In my case it is the master-classpath.

Noe run the ant target for report generation (in my case "testng-xslt-report
") and check the ouput folder configured by you for testng-xslt report.

Friday, May 7, 2010

Using TestNG for parallel execution on Selenium Grid

Following I will mention how to integrate TestNG with Selenium-Grid code and use it for parallel execution of test cases.
For this you create a Base class where you define the following two functions.


protected
void startSession(String seleniumHost, int seleniumPort, String browser, String webSite)
throws Exception {


startSeleniumSession(seleniumHost, seleniumPort, browser, webSite);

session().setTimeout(TIMEOUT);

}

protected void closeSession() throws Exception {

closeSeleniumSession();

}

The above two functions are for the starting and closing the session in Selenium Grid. The references of it can be found in my earlier posts.

Now import the testng annotation class “org.testng.annotations.*” onto the Base Class.

Add @BeforeClass before the “startSession” method and @AfterClass before the “closeSession” method.

Now write your test cases in a way that all dependent test cases are in one class.


So whenever you execute the testNG it will call the “startSession” and “closeSession” before and after each test class execution. The “startSession” will create a Selenium session for test execution and return it to the test class. Where as the “closeSession” will close the session.

For parallel execution define inside the testng.xml file the attributes “suite” tag as “parallel="classes" thread-count="2" ”.
This will tell TestNG that parallel execution needs to be done for classes and max. Thread count for it is “2”.

Define 2 different test classes both extending the Base Class which defines the “startSession” and “closeSession” methods. Start a Selenium Grid Hub and register two Selenium remote control to the Hub. Now try running the package containing these classes using the TestNG.

You will see 2 different tests running in parallel in Selenium Grid each for Selenium Remote Control registered to the Hub.
The “startSeleniumSession” inside the “startSession” method create a unique selenium session for each of the test class and use that session for test class execution. Creating a session,registering the session with a Remote control and maintaining the session is done by Selenium Grid where as using TestNG framework we define how many sessions we need to create and how the test execution should be. So using the features of both TestNG and Selenium Grid we achieve Parallel execution of our automation testcases.

Currently here I had suggested to use @Before/AfterClass annotations in Base Class. You can use any of the other available @Before/After annotations available in TestNG depending upon your tests.

Saturday, April 17, 2010

Integrate Selenium-RC to Selenium Grid

Most of us develop our cases in Selenium RC and test it . If we want to run our cases in parallel we need to use Selenium Grid. Selenium Grid gives us the advantage of running the cases in parallel and in different environments.

I will tell in this blog what you need to do for setting up Selenium Grid For Parallel Execution or for changing your existing code to be able to be used with Selenium Grid.First you need to get the “selenium-grid-tools-standalone-1.0.4.jar” from the lib folder under the Selenium Grid folder that you had downloaded. Import this jar to the reference Libraries under you selenium RC code.

For java you need to change the way you create the selenium object. Most of us extends the SeleneseTestCase class or create the object using "new DefaultSelenium", for Grid we need to change that with following methods.


First import the following classes into your code.


import static com.thoughtworks.selenium.grid.tools.ThreadSafeSeleniumSessionStorage.closeSeleniumSession;

import static com.thoughtworks.selenium.grid.tools.ThreadSafeSeleniumSessionStorage.session;

import static com.thoughtworks.selenium.grid.tools.ThreadSafeSeleniumSessionStorage.startSeleniumSession;


This will import the Selenium Grid class.

Then you need to define methods as mentioned below.


protected void startSession(String seleniumHost, int seleniumPort, String browser, String webSite) throws Exception {

startSeleniumSession(seleniumHost, seleniumPort, browser, webSite);

session().setTimeout(TIMEOUT);

}


protected void closeSession() throws Exception {

closeSeleniumSession();

}


The method “startSession” will create a session using the “seleniumHost”, “seleniumPort” & “browser” value onto the Selenium remote control using the Selenium Grid.

This session object is to be used for executing your selenium commands.

Following is an example on how to use the “session()” for test execution in Selenium Grid.


public void login() {

session().open("/webpage/");

session().type("txtUserName", "admin");

session().type("txtPassword", "admin");

session().click("Submit");

}

A simplest way to use the “session()” can be,by assigning it to a Selenium object and using the selenium object in your test execution. For ex.


Selenium selenium = session();


This way you don't have to replace the “selenium” object in your Selenium RC code with “session()” as mentioned in the “login()” method example.


Also for parallel execution you need to integrate TestNG with your Selenium Code. TestNG supports multi-threaded execution. I will be writing about how to use TestNG with Selenium in my coming blogs.

Sunday, April 4, 2010

What is TestNG? And whats the difference between Junit and TestNG

TestNG is a testing framework inspired from JUnit and NUnit but introducing some new functionalities that make it more powerful and easier to use, such as:

  • Annotations.

  • Flexible test configuration.

  • Support for data-driven testing (with @DataProvider).

  • Support for parameters.

  • Allows distribution of tests on slave machines.

  • Powerful execution model (no more TestSuite).

  • Supported by a variety of tools and plug-ins (Eclipse, IDEA, Maven, etc...).

  • Dependent methods for application server testing.

If you want to learn TestNG you can download it and see its documentation at “http://testng.org/doc/index.html”.

TestNG is extensively used in Selenium automation and Code testing instead of Junit due to its advantages over it.


Using TestNG Selenium automation becomes simplified and also the Parallel execution using Selenium Grid becomes easy.


TestNG have a lot of features in it and hence I wont be covering every thing in my blog. But will only talk about advantages of TestNG over Junit. I will be discussing about different ways of using TestNg functions in my coming blogs.


Advantages of TestNG over Junit

  1. In Junit we have to declare @BeforeClass and @AfterClass which is a constraint where as in TestNG there is no constraint like this.

  2. Additional Levels of setUp/tearDown level are available in TestNG like @Before/AfterSuite,@Before/AfterTest and @Before/AfterGroup

  3. No Need to extend any class in TestNG.

  4. There is no method name constraint in TestNG as in Junit. You can give any name to the test methods in TestNG

  5. In TestNG we can tell the test that one method is dependent on another method where as in Junit this is not possible. In Junit each test is independent of another test.

  6. Grouping of testcases is available in TestNG where as the same is not available in Junit.

  7. Execution can be done based on Groups. For ex. If you have defined many cases and segregated them by defining 2 groups as Sanity and Regression. Then if you only want to execute the “Sanity” cases then just tell TestNG to execute the “Sanity” and TestNG will automatically execute the cases belonging to the “Sanity” group.

  8. Also using TestNG your selenium testcase execution can be done in parallel.


Saturday, March 20, 2010

Ant script for generating a Junit report for Selenium Test execution

We know the advantages of using Selenium RC. But Selenium RC by default does not provide us with any reports for the test execution done through it. We need to explicitly implement a reporting framework for test reporting in RC. For implementing a Reporting framework you can write your own custom code or can use an already existing reporting framework available.

There are mainly two reporting framework available for Selenium RC they are Junit and Test-NG. There are two more frameworks Report-NG and testng-xslt but they are implemented over the Test-NG framework.

In this blog I will mention about generating a Junit Report for your Selenium RC test execution using Ant script. I had written a “build.xml” for Ant for executing Selenium cases and generating a Junit report for the said selenium execution. I will be discussing about the same in this blog. If someone doesn’t have an idea about Ant can follow my steps and can generate a Junit report for Selenium Execution.


Explaining the “build.xml”

  1. In Build.xml I am mainly defining 5 properties

o RELEASE_ROOT this has been set to the Java Project folder.

o SRC which defines the source folder of the project

o LIB which defines the lib folder of the project

o BIN which defines the binary folder where the classes needs to be pasted after compiling

o REPORT folder which defines the report folder where the test execution reports will be generated.

  1. There are 4 targets or tasks of ant inside the build.xml

o “init’ which deletes the binary folder and creates it again.

o “compile” which depends upon the “init” task and which compiles the java files under the source folder and paste the classes onto the binary folder.

o “run-single-test” which depends on “compile” and runs only a single Selenium Junit test mentioned in it. This task also generates a Junit html report under the report/html folder of Java project after Selenium Test execution is done.

o “run-batch-test” which depends on “compile” and runs multiple Selenium Junit test mentioned in it. This task also generates a Junit html report under the report/html folder of Java project after Selenium Test execution is done.

  1. In each of the compile, run-single-test and run-batch-test I am setting the classpath of the binary folder, the library folder and the source folder in case of “run-batch-test”.
  2. In targets “run-single-test” and “run-batch-test” I am using the “junit” task of test execution. This task provides two types of execution

o Single class execution which I had used in “run-single-test” target. There is a subtask “test” of “junit” that can used for single test class execution. It is written as follows:


<test name="test.TestClass" haltonfailure="no" todir="${REPORT}/xml" outfile="TEST-result">

<formatter type="xml" />

</test>


Here “name” is the test class name. “todir” is the directory where initial xml report needs to be generated. “outfile” is the xml file name for initial result xml file. “formatter” is the initial file format type.


o Batch test class execution which I had used in “run-batch-test” target. There is a subtask “batchtest” of “junit” that can used for single test class execution. It is written as follows:


<formatter type="xml" usefile="true" />

<batchtest fork="yes" todir="${REPORT}/xml">

<fileset dir="${SRC}">

<include name="**/Test*.java" />

</fileset>

</batchtest>


Here I am telling the “batchtest” what all test classes to include using the “fileset” and “include” task. Along with this if you want you can use the “exclude” task to exclude particular type of classes. In the following example the Junit will include all the test class starting from “Test” and exclude all the test class having “Base” word in their name.


<formatter type="xml" usefile="true" />

<batchtest fork="yes" todir="${REPORT}/xml">

<fileset dir="${SRC}">

<include name="**/Test*.java" />

<exclude name="**/*Base*.java" />

</fileset>

</batchtest>


5. For generating the test report I am using the “junitreport” task of ant. It takes all the xml file from the “report/xml” and generates an html report at “report/html”.


Setting up a Java Project for test execution using Ant.


In this I am just telling how to setup a basic java project for using the build.xml file attached with this blog and running the selenium test using Ant.


Preconditions:

1. Install Ant from apache.

2. Install Java JDK (not JRE) and add its bin folder to your “PATH” environment variable of your system. For checking JDK is mapped check whether "javac" is recognized in your system by typing "javac" in your command prompt.

3. Download the Selenium RC.

4. Test cases are already converted to Selenium Junit cases.


Steps:

  1. Create a Java project in your Java IDE. I am using Eclipse so I will refer to it.
  2. By default there will be the “src” folder inside your Java Project. Right click on the “src” folder and create a new package under it say”test”.
  3. Now copy your Selenium Junit classes to this new “test” package.
  4. Create a new folder called “lib” under your Java Project.
  5. Copy selenium-java-client-driver.jar, junit-4.5.jar(if you have another version of Junit 4 you can use that) and ant-junit.jar(can be found under the “lib” folder of your ant installation) to your “lib” folder of Java Project.
  6. Now create a folder called “build” under your Java Project and copy the “build.xml” file attached with this blog to the build folder you created.
  7. Now open the build.xml file for edit.
  8. Search for “run-single-test” in build.xml. Go to the “<test” under the “run-single-test” target .Replace the values for “name=” variable with your Selenium Junit class name. For ex if your class name is TestSelenium.java and it is under package “test” under “src” then replace the value with “test.TestSelenium” then save the build.xml file.
  9. Now start the Selenium RC server.
  10. Now go to the build folder of the Java Project using command prompt and run the command “ant run-single-test”
  11. It should execute your Selenium cases on selenium server and generate an html report onto the “report/html” folder of your Java project.


Similarly you can modify the “run-batch-test” target of build.xml and execute multiple Selenium Tests together.

Download build.xml from Here

Thursday, March 11, 2010

Defining your own Environment and Using it in Selenium Grid


If you want to use an environment something like “Firefox on Windows” or “Firefox on Linux”.
You can use that by starting the Remote control with the said environment name. This will register the Remote control to the hub with the said environment name.
For ex. Start the hub normally but while starting the Remote control replace the -Denvironment value with your own particular name.

ant -Dport=5555 -Dhost=192.168.1.0 -DhubURL=http://192.168.1.2:4444 -Denvironment=”Firefox on Linux” launch-remote-control


If you check the Hub console it will look something like


Also if you want to use such an environment for executing your Test you need to pass the environment name to the selenium object in your code.
For Java you need to use the following function while creating the selenium object.


new DefaultSelenium("localhost", 4444, “Firefox on Windows”, 'http://google.com');

Now if you go through the above things you will think about how to use the above function and define the selenium object since it is already been declared and defined when you get it from selenium IDE.
This happens because when you copy the code from the Selenium Ide, the class that is defined in the code extends the “SeleneseTestCase” class where this “selenium ” object has already been defined.


For using the custom Environment with the Selenium Grid do the following thing:

1.Remove the “SeleneseTestCase” class which is extended by the Test class.

2.Define your own Selenese object as shown below

Selenium selenium;
selenium =new DefaultSelenium("localhost", 4444, " ", "http://www.google.com");


3.Start the selenium using the below command.

selenium.start();

This will start your selenium session. Then using this selenium object you run your test cases.

4.After your test is done use the following command to stop the selenium.


selenium.stop();

When you call the selenium grid by giving some particular Environment name. The Selenium Hub will make sure to provide the test with a remote control that registered with this specific Hub environment.

Friday, March 5, 2010

Setting up Selenium-Grid on your System

In this blog I will tell you how to set-up Selenium Grid on your system.


  1. Check that Java is installed in your system by using the command “java -version”. If Java is installed it will give the output about Java Version that is installed in your system. Else download the Java from Java website (http://www.java.com/en/download/index.jsp).

  2. Check ANT is installed in your system by using the command “ant -version”.If Ant is installed it will give the output about Ant Version that is installed in your system. Else download the Apache Ant from Apache website (http://ant.apache.org/).

  3. Download Selenium Grid from Selenium Grid website(http://selenium-grid.seleniumhq.org/download.html) and unpack it.

  4. Go to the Unpacked directory of the Selenium grid using command prompt and type the command “ant launch-hub”. This will launch the Selenium Grid Hub on a default port “4444” to check whether the selenium grid is running. Type the URL “http://localhost:4444/console ” on your browser and check that you are able to see the selenium hub console on the browser.

  5. Now go to the same Selenium Grid directory using command prompt and type the command “ant launch-remote-control”. This will start the Selenium Grid Remote control on default port “5555” and environment “*firefox” and register it to the Hub which you had earlier started.

  6. Now after starting the selenium remote control we will test the example provided with Selenium Grid for sequence testing in single machine. For this go to the Selnium grid folder from command prompt and type the command “ant run-in-demo-sequence”. This will execute the test example provided with selenium grid to be executed in sequence.


Now you may had noticed in the setting up steps that I am running the test in sequence. You may think in your mind that, what's special in that? The same things can be achieved when we use a Selenium RC.Then here comes the important part of Selenium Grid.


Setting up Parallel execution on a single machine

  1. Start the hub and one remote control in the same way as in the earlier setting up steps.

  2. Now go to the Selenium Grid folder using command prompt and type the command

“ant -Dport =5556 launch-remote-control”

This will start another remote control on port “5556” and register it to the local hub. If you want to register more remote control to the Hub. You can do that by starting multiple remote control but with different ports.

  1. To know the no. of registered remote control onto a hub go to the URL “http://localhost:4444/console”. It will give you a view as follows:


  1. Now to run the test in parallel. Go to the selenium grid directory using command prompt and type the command “ant run-demo-in-parallel”. This will run the example tests given with selenium grid in parallel.


Setting up parallel execution for different machines and different environments

In this case start the Hub normally as you do in any of the system.

For starting the remote control use the following command.


ant -Dport=<port> -Dhost=<hostname> -DhubURL=<hub> -Denvironment=<environment> launch-remote-control


Here

“-Dport” should be used to set the port of the remote control.

“-Dhost” should be used to set the host(where the remote control has been started) IP. This is the IP which the hub will use to talk to the remote control.

“-DhubURL” should be used to set the Hub Url where the current remote control will register itself.

“-Denvironment” should be used to set an environment name that remote control represents to the hub.

Now start 4 different remote controls from 2 different machines and register them to the hub.

After this check the Hub console. It will look similar to the table as shown below depending upon the remote control that are registered to the Hub.


Then to verify your set-up go to the Selenium Grid folder from the command prompt and type the command “ant run-demo-in-parallel”


This will run an example test accompanied with the Selenium Grid to run in parallel.


Advantages of Selenium Grid

  1. Remote Execution of the selenium tests can be done using Selenium Grid without actually copying your test code to to remote system.

  2. Selenium Grid can be used to save time by executing independent testcases in parallel.

  3. Load Testing can be done if we register a lot of remote control to a single hub and execute testcase in parallel to simulate multiple transactions at a single timeperiod.

Monday, March 1, 2010

Useful Functions and Notes while writing cases in Selenium RC

Useful Functions of Selenium

You have a huge list of selenium functions that we can use for writing test cases. Some of the main functions are:

isElementPresent(location) – Returns true or false based on whether “location” of the element passed is present on the page or not. Verifies that the specified element is somewhere on the page. This function can be used while you are working on an Ajax based system or in a system where you need to identify whether the element is present before we execute any action on the said "location". It is good to check if the location is present or not if your test case include clicking on some link or page refresh and then taking some action.

getValue(location)- Returns the data stored in the said “location” of the element that is passed to the function. Gets the (whitespace-trimmed) value of an input field (or anything else with a value parameter). For checkbox/radio elements, the value will be "on" or "off" depending on whether the element is checked or not.This function is useful when you need to get some data from some field or a particular location and need to use it in you program or testcase.

isTextPresent(text)- Returns true or false based on the specified text pattern appears somewhere on the rendered page shown to the user.Used to verify the whether a text present on the page or not.

click(location) - Clicks on a link, button, checkbox or radio button. If the click action causes a new page to load (like a link usually does), call "waitForPageToLoad" function.

waitForPageToLoad(timeout) - Waits for a new page to load. Selenium constantly keeps track of new pages loading, and sets a "newPageLoaded" flag when it first notices a page load. Running any other Selenium command after turns the flag to false. Hence, if you want to wait for a page to load, you must wait immediately after a Selenium command that caused a page-load.

type(locator,value) - Sets the value of an input field, as though you typed it in.

select(locator,option locator) - Select an option from a drop-down using an option locator. Using to select values from combo boxes.


Useful things while writing cases in Selenium

  1. While testing any Ajax based application use “waitForElementPresent” or “isElementPresent” before trying to do any action over the element.

  2. While writing your own case always remember to extend the “SeleneseTestCase” class.This create a “selenium” object and stores the browser session onto the created object.

  3. To set the browser on which you need to do execution of your test case add the following function to your test case class

public void setUp() throws Exception {

setUp(URL,browser name);

}

List of browsers that can used is “*firefox” -for firefox, “*iexplore” -for IE, “*safari” - for Safari, “*opera” - For Opera.This need to be placed in place of "browser name" while calling the "setUp" function.

  1. If you are internally going to call another function from your test case and going to execute some actions under it. Don't forget to pass the “selenium” object to the function otherwise your test case will fail. This happens because when you are executing a case ,the browser session details is stored with the “selenium” object and if you call a function without passing the selenium object to the function it wont be having any session details with it and hence the case will Fail.


Wednesday, February 24, 2010

Import Selenium cases from Selenium IDE to Selenium RC in Java

In this blog I will talk about how to import selenium cases from Selenium IDE to Selenium RC in Java
Before proceeding you need to do following things:
  1. Download Selenium Ide for firefox and add it to firefox.
  2. Download the Selenium RC distribution zip.
  3. Download Junit-4.5.jar
  4. Basic knowledge of Java is necessary.

Now I will start step by step on how to start writing selenium cases.
  1. Open Firefox . Start the selenium IDE by going to Tools → Selenium IDE.
  2. By default the recording feature of selenium IDE will be started. This can be identified by checking the Red circular icon on the right hand side of the window. If not clicking on the icon will start the recording.
  3. Now record your test by opening a web page and doing some action over it. For ex.
    1. Type “Selenium” in the search page.
    2. Click on “Search” button.
    3. Now click on the “Selenium Web application testing system”.
  1. Now go to the Selenium IDE window and stop the recording by clicking on the Red circular icon on the Right side of the window.
  2. Now your test is recorded. To verify your test you can re-run your recorded test by clicking onto the Play icon on the selenium window.
  3. Once your recording is verified. Click on Options → Format → Java(JUnit)-SeleniumRC. This will convert your recorded test into the Java -Junit format.
  4. Now install any Java IDE you want to use and create a new Java Project. I used Eclipse for developing my cases.
  5. After creation of new project , create a new Java class under the project. Now copy the Java-JUnit code from the Selenium IDE and paste it to this new Java class.
  6. Change the class name from the Selenium Ide to the Java Class file name that you created inside your project.
  7. Now add to the build path of the Java Project in Eclipse IDE "selenium-java-client-driver.jar" from the Selenium-java-client-driver folder under the Selenium RC distribution that you had downloaded. Also add "Junit-4.5.jar" to the build path.
  8. To Verify your Selenium RC set-up in Eclipse IDE you have to start the Selenium RC server first. This you can do by going to the Selenium-server folder under the Selenium RC distribution that you had downloaded using the command prompt and running the command “java -jar selenium-server.jar”
  9. Once the server is started Verify your test case by going to the Eclipse IDE and running the test-case as a Junit case.
  10. Once your test case is executed properly your Selenium-RC setup is ready.
  11. You can write your custom code over it and do whatever actions you want to do.
  12. In the similar way you record your Test-cases through Selenium IDE and bring it to Selenium RC for modifications.

Friday, February 19, 2010

Whats Selenium?

As we all know everything is automated nowadays you name it and you get it. Similar is the way we do testing of applications. We have got many softwares that can do the automation work for you. Just Record it and Play it and your automation of a use case is done.
One of the famous automation tool in industry is Selenium. Its an Open Source Functional Testing tool.
Selenium provides mainly three types of tools that you can use for automation.
1.
Selenium IDE - is a Firefox add-on that records clicks, typing, and other actions to make a test, which you can play back in the browser.
2.
Selenium RC - runs your tests in multiple browsers and platforms. Tweak your tests in your preferred language.
3.
Selenium Grid - extends Selenium RC to distribute your tests across multiple servers, saving your time by running tests in parallel.

Selenium IDE
It is an integrated development environment for Selenium tests. It is implemented as a Firefox extension, and allows you to record, edit, and debug tests. Selenium IDE includes the entire Selenium Core, allowing you to easily and quickly record and play back tests in the actual environment that they will run.
Selenium IDE is not only recording tool: it is a complete IDE. You can choose to use its recording capability, or you may edit your scripts by hand. With autocomplete support and the ability to move commands around quickly, Selenium IDE is the ideal environment for creating Selenium tests no matter what style of tests you prefer.

Selenium RC
It is a test tool that allows you to write automated web application UI tests in any programming language against any HTTP website using any mainstream JavaScript-enabled browser.
Selenium RC comes in two parts.
1.A server which automatically launches and kills browsers, and acts as a HTTP proxy for web requests from them.
2.Client libraries for your favorite computer language.
The RC server also bundles Selenium Core, and automatically loads it into the browser.
Selenium Remote Control is great for testing complex AJAX-based web user interfaces under a Continuous Integration system. It is also an ideal solution for users of Selenium Core or Selenium IDE who want to write tests in a more expressive programming language.

Selenium Grid
Selenium RC can only execute your programs in a single type of environment and limited to a single machine. Selenium Grid gives you the power to execute multiple tests in parallel and also onto some remote machines hence saving the time for the test execution.

In my coming posts I will describe in detail how to use Selenium for automation.

Monday, February 1, 2010

The First One

Hi this is my first Blog and in this I would like to tell you about me.

My Name is Varun Menon and currently I am a Senior QA Engineer in the company. I currently hold around 4+ years of experience in software industry. I have expertise in both Manual as well as Automation testing.

Worked mainly on Mobile based application Testing and Web-based application testing.

In this blog I will mainly write about technical things. The things I had worked upon and my ideas.

Hope you like it.

Also feel free to comment or suggest.