Saturday, October 3, 2009

DataProvider - Data Driven Testing with Selenium and TestNG

Data-Driven testing generally means executing a set of steps with multiple sets of data.
Selenium does not provide any out-of-the box solution for data driven testing but leaves it up to the user to implement this on his own. People who are familiar with QuickTest Professional or QTP would know Datatables (Global & Action) that allows the scripter to link a action or a function with multiple rows of data.

TestNG is a framework that makes data-driven testing possible in selenium. TestNG is a testing framework created in line with Junit but with added features that makes it suitable for use in regression test automation projects. DataProvider is one such feature in testng; it allows a test method to be executed with multiple sets of data.

A DataProvider is data feeder method defined in your class that supplies a test method with data. You may hook up any test method with a DataProvider and make the test method execute once for every row of your test data.

@DataProvider(name = "DP1")
    public Object[][] createData() {
        Object[][] retObjArr={{"001","Jack","London"},
                            {"002","John","New York"},
                            {"003","Mary","Miami"},
{"004","George","california"}};
        return(retObjArr);
    }



@Test (dataProvider = "DP1")
    public void testEmployeeData(String empid, String empName, String city){
selenium.type("id", empid);
selenium.type("name", empName);
selenium.click("submit_button");
selenium.waitForPageToLoad("30000");
assertTrue(selenium.isTextPresent(city));

}


In the example above createData() is the DataProvider function that is sending out test data in the form of array of array of objects (object[][]). The test method testEmployeeData() hooks onto the DataProvider by declaring that its data should be supplied by the DataProvider named "DP1". On execution testEmployeeData() will be executed 4 times, once with each row of object[][]. Note that the dimension of the array returned by the DataProvider must match the parameter type of the test method. This means if your test method takes 3 parameters then array returned by the DataProvider must have its second dimension equal to 3. Try to visualize the array of array as a table where each row constitutes one test case.

In the example above the test data is defined withing the DataProvider function. But ideally you want to keep your test data in spreadsheet like media and not in the test script. To achieve this instead of declaring the test data array within the DataProvider function we should call a function that fetches the data from an excel sheet and returns an array of array object to the DataProvider.
I will share with you my way of storing data in XL sheets. I store test data in the form of tables within an excel sheet. There could be any number of tables within an excel sheet. Each table is marked by an startTag and an endTag. The startTag and endTag is the Name of the table. The startTag is placed one cell diagonally above the cell from where the first row of table data begins. And the endTag is placed one cell diagonally below the cell from where last row of table data ends. A table always begins with a column header row although this row is just for our understanding and is ignored in the computation. Below is the image of a sample test data excel sheet. Click on the image to see a bigger version of it. Also below the image you can see the google doc with the test data I will use in an example later in this post.




Below is the function that fetches the table from the excel sheet and returns it as an array of array of String type. It uses Java Excel API to fetch data from excel sheet.
It takes 3 parameters
1. xlFilePath - the path of XL file/workbook containing the data, the path is relative to java project
2. sheetName- name of the xl sheet that contains the table
3. tableName- Name of the table that you wish to fetch
The function returns a String type array of array.

public String[][] getTableArray(String xlFilePath, String sheetName, String tableName){
        String[][] tabArray=null;
        try{
            Workbook workbook = Workbook.getWorkbook(new File(xlFilePath));
            Sheet sheet = workbook.getSheet(sheetName);
            int startRow,startCol, endRow, endCol,ci,cj;
            Cell tableStart=sheet.findCell(tableName);
            startRow=tableStart.getRow();
            startCol=tableStart.getColumn();

            Cell tableEnd= sheet.findCell(tableName, startCol+1,startRow+1, 100, 64000,  false);                               

            endRow=tableEnd.getRow();
            endCol=tableEnd.getColumn();
            System.out.println("startRow="+startRow+", endRow="+endRow+", " +
                    "startCol="+startCol+", endCol="+endCol);
            tabArray=new String[endRow-startRow-1][endCol-startCol-1];
            ci=0;

            for (int i=startRow+1;i<endRow;i++,ci++){
                cj=0;
                for (int j=startCol+1;j<endCol;j++,cj++){
                    tabArray[ci][cj]=sheet.getCell(j,i).getContents();
                }
            }
        }
        catch (Exception e)    {
            System.out.println("error in getTableArray()");
        }

        return(tabArray);
    }


Now we will put all of this together in an example. We will keep the test data in excel sheets and use the above function to fetch from it.
Note:
1. testng jar should be in the class path. You may download the latest testng jar file from here.
2. testng eclipse plugin must be installed. Get it from the same location as the testng jar file mentioned above.
3. jxl jar should be in the class path Java Excel API. You can get this from here. Download the jexcelapi.zip, unzip to get the jxl.jar
4. Selenium-server and selenium-java-client-driver and junit jar (selenium classes need junit) files must in class path.
5. The file data1.xls is kept at test\\Resources\\Data\\data1.xls
I have attached this file to the blog as a google doc, please copy paste its contents to a excel file. Rename the excel-sheet to DataPool and the save the excel file as data.xls. The path mentioned is relative to the project.

The test method testDataProviderExample() below navigates to www.imdb.com and performs search for movie titles. On the movie details page it verifies the presence of director name, movie plot and the name of the lead actor. This routine is repeated for all the rows of the test-data table.

import com.thoughtworks.selenium.*;

import org.junit.AfterClass;
import org.openqa.selenium.server.SeleniumServer;
import org.testng.annotations.*;

import java.io.File;
import jxl.*; 


public class DataProviderExample extends SeleneseTestCase{
    
    @BeforeClass
    public void setUp() throws Exception {
        SeleniumServer seleniumserver=new SeleniumServer();
        seleniumserver.boot();
        seleniumserver.start();
        setUp("http://www.imdb.com/", "*firefox");
        selenium.open("/");
        selenium.windowMaximize();
        selenium.windowFocus();
    }

    
    @DataProvider(name = "DP1")
    public Object[][] createData1() throws Exception{
        Object[][] retObjArr=getTableArray("test\\Resources\\Data\\data1.xls",
                "DataPool", "imdbTestData1");
        return(retObjArr);
    }
    
    @Test (dataProvider = "DP1")
    public void testDataProviderExample(String movieTitle, 
            String directorName, String moviePlot, String actorName) throws Exception {    
        //enter the movie title 
        selenium.type("q", movieTitle);
        //they keep switching the go button to keep the bots away
        if (selenium.isElementPresent("nb15go_image"))
            selenium.click("nb15go_image");
        else
        selenium.click("xpath=/descendant::button[@type='submit']");
        
        selenium.waitForPageToLoad("30000");
        //click on the movie title in the search result page
        selenium.click("xpath=/descendant::a[text()='"+movieTitle+"']");
        selenium.waitForPageToLoad("30000");
        //verify director name is present in the movie details page 
        verifyTrue(selenium.isTextPresent(directorName));
        //verify movie plot is present in the movie details page
        verifyTrue(selenium.isTextPresent(moviePlot));
        //verify movie actor name is present in the movie details page
        verifyTrue(selenium.isTextPresent(actorName));
    }
    
    @AfterClass
    public void tearDown(){
        selenium.close();
        selenium.stop();
    } 
    
    public String[][] getTableArray(String xlFilePath, String sheetName, String tableName) throws Exception{
        String[][] tabArray=null;
        
            Workbook workbook = Workbook.getWorkbook(new File(xlFilePath));
            Sheet sheet = workbook.getSheet(sheetName); 
            int startRow,startCol, endRow, endCol,ci,cj;
            Cell tableStart=sheet.findCell(tableName);
            startRow=tableStart.getRow();
            startCol=tableStart.getColumn();

            Cell tableEnd= sheet.findCell(tableName, startCol+1,startRow+1, 100, 64000,  false);                

            endRow=tableEnd.getRow();
            endCol=tableEnd.getColumn();
            System.out.println("startRow="+startRow+", endRow="+endRow+", " +
                    "startCol="+startCol+", endCol="+endCol);
            tabArray=new String[endRow-startRow-1][endCol-startCol-1];
            ci=0;

            for (int i=startRow+1;i<endRow;i++,ci++){
                cj=0;
                for (int j=startCol+1;j<endCol;j++,cj++){
                    tabArray[ci][cj]=sheet.getCell(j,i).getContents();
                }
            }
        

        return(tabArray);
    }
    
    
}//end of class


Just copy paste the above in a java file, reference the necessary jars in the build path, put the test-data excel file in the correct location and it should work just fine. To run right click the java file in eclipse and select Run As-->TestNG Test.

Watch video of how to create a data driven test script from scratch step by step

Part 1



Part 2



Part 3



Part 4



Feel free to post queries here.

edit on 10 july 2010: removed try/catch from getTableArray(), it's easier to debug spreadsheet file name/sheet name mismatch this way.

312 Comments:

Cedric said...

That's a great article, I added a link to it to the TestNG documentation:

http://testng.org/doc/misc.html

Thanks, Mahesh!

--
Cedric

Mahesh Narayanan said...

Thanks Cedric, I am honored to be mentioned in the TestNG documentation.

Prasad said...

Very Useful Information Mahesh.

Thanks very much
Prasad

Unknown said...

thank you for this tutorial :)

Sakthivelu said...

Thank you so much...This is a great post...Truely.

-Sakthi.

M. Mathew said...

Cell tableEnd= sheet.findCell(tableName, startCol+1, startRow+1, 100, 64000, false);

Shows the following error:

The method findCell(String) in the type Sheet is not applicable for the arguments (String, int, int, int, int, boolean).
How do I fix this. Please help. Thanks

Mahesh Narayanan said...

Mathew, findcell() is a overloaded function. You need to select the findCell function that has 6 parameters. This should not have been a problem if you were using an IDE like eclipse.

M.Mathew said...

I got it solved, there was old jxl.jar was in jre. But now when i run the test in Eclipse I get this error:
"
java.lang.NullPointerException
at org.testng.internal.MethodHelper.invokeDataProvider(MethodHelper.java:661)
at org.testng.internal.Parameters.handleParameters(Parameters.java:350)
at org.testng.internal.Invoker.handleParameters(Invoker.java:1060)
at org.testng.internal.Invoker.createParameters(Invoker.java:841)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:923)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:110)
at org.testng.TestRunner.runWorkers(TestRunner.java:759)
at org.testng.TestRunner.privateRun(TestRunner.java:592)
at org.testng.TestRunner.run(TestRunner.java:486)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:332)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:327)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:299)
at org.testng.SuiteRunner.run(SuiteRunner.java:204)
at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:877)
at org.testng.TestNG.runSuitesLocally(TestNG.java:842)
at org.testng.TestNG.run(TestNG.java:751)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:73)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:124)
"

Mahesh Narayanan said...

Mathew, do you have junit, testng (ver 5.9 or greater) and jxl jars in class path along with selenium-server and selenium-java-client-driver jars? I just reran the test with only these jars in the classpath and it ran without any issues. Make sure you have right version of the testng jar i.e ver 5.9 or greater.

Mahesh Narayanan said...

Mathew try it out please post your status here.

aventre said...
This comment has been removed by the author.
Mahesh Narayanan said...

Mahesh, this is exactly what I have been looking for! Thanks for posting this!

Unfortunately I got stuck at "5. The file data1.xls is kept at test\\Resources\\Data\\data1.xls"

I am not sure how to make this specific to my set up. You mentioned that "The path mentioned is relative to the project."

Any help is appreciated.

Posted by aventre

Mahesh Narayanan said...

Hi aventre, Inside your project make a folder 'test', within 'test' make a project 'Resource' and within 'Resource' make a folder 'Data'. Now within the folder 'Data' save the excel file. Please let me know if you have queries.

Anonymous said...

Hi, is it possible to get data with utf-8 encoding from excel using this example. I tried changing excel encoding but it didn't help.

Shivayogi said...

Hi Mahesh,

I am Shivayogi Kumbar from Bangalore; it's great to see this useful data driven testing methodology in selenium. I would like to discuss with you the problem what I am facing while executing this script, have tried all the possible ways what u have suggested M.Mathew, then also I am unable to resolve this issue, please help me out.

java.lang.NullPointerException
... Removed 19 stack frames at org.testng.internal.MethodHelper.invokeDataProvider(MethodHelper.java:661)
at org.testng.internal.Parameters.handleParameters(Parameters.java:350)
at org.testng.internal.Invoker.handleParameters(Invoker.java:1060)
at org.testng.internal.Invoker.createParameters(Invoker.java:841)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:923)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:110)
at org.testng.TestRunner.runWorkers(TestRunner.java:759)
at org.testng.TestRunner.privateRun(TestRunner.java:592)
at org.testng.TestRunner.run(TestRunner.java:486)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:332)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:327)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:299)
at org.testng.SuiteRunner.run(SuiteRunner.java:204)
at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:877)
at org.testng.TestNG.runSuitesLocally(TestNG.java:842)
at org.testng.TestNG.run(TestNG.java:751)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:73)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:124)

Mahesh Narayanan said...

Hi Shivayogi,
after reading your comment I tried my code with a fresh workspace. I created a project, added the jars, added the dataproviderExample script and then I added the xls file. It works perfectly. I just followed the instructions given in my post blindly. So I suggest that you do the same.

Also try with a static array as the datasource in the dataprovider function to rule out any excel read issues. I have that as an example in the beginning of the post. In the meanwhile I will try to create a video of this entire exercise and post this on youtube and then put a link to the video here, if time permits.
Best of luck

Shivayogi said...

Hi Mahesh,
Thanks for giving your valuable time to explain me to resolve this problem, yesterday I had tried for the first script which u have posted it ,in my environment selenium.type is not getting the object to what the dataprovider is giving, it's throwing the null pointer exception. My assumption is the selenium is unable to recognize the object, I have commented the selenium portion of the function testEmployeeData function and executed it works fine but when it reaches the selenium.type, throws NPE.


import com.thoughtworks.selenium.*;

import org.junit.AfterClass;
import org.openqa.selenium.server.SeleniumServer;
import org.testng.annotations.*;

import java.io.File;
import jxl.*;
public class Dataprovider extends SeleneseTestCase{
@DataProvider(name = "DP1")
public Object[][] createData() {
Object[][] retObjArr={{"001","Jack","London"},
{"002","John","New York"},
{"003","Mary","Miami"},
{"004","George","california"}};
return(retObjArr);
}



@Test (dataProvider = "DP1")
public void testEmployeeData(String empid, String empName, String city){


/*selenium.type("id", empid);
selenium.type("name", empName);
selenium.click("submit_button");
selenium.waitForPageToLoad("30000");
assertTrue(selenium.isTextPresent(city));*/
}
}

Mahesh Narayanan said...

shivyogi,
The selenium part in the first script is just an example, it is not supposed to work. Obviously their has to be a web application with fields that have id equal to 'id' and id equal to 'name' for this script to work. You should try the script that takes the data from excel. This is the one that works on www.imdb.com. Try that one.

Unknown said...

Hi Mahesh

Im new to java and selenium. I am trying to run multiple test methods in a test class but always get a failure after the first method with Test annotation completes can u help me.

ive put down an example of what im trying to achieve

package test.gumtree;

import org.testng.annotations.*;
import com.thoughtworks.selenium.*;
//import java.util.regex.Pattern;

public class Test1 extends SeleneseTestCase {
@BeforeClass
public void setUp() throws Exception {
setUp("http://www.gumtree.com/", "*chrome");
selenium.windowMaximize();
selenium.windowFocus();
}
@Test
public void testUntitled() throws Exception {
selenium.open("/");
selenium.click("link=Offered");
selenium.waitForPageToLoad("30000");
selenium.click("link=1 bedroom flats/houses");
selenium.waitForPageToLoad("30000");
selenium.type("search_terms1", "kilburn");
selenium.type("min_price1", "250");
selenium.type("max_price1", "280");
selenium.click("house_type_11");
selenium.click("search_button1");
selenium.waitForPageToLoad("30000");
selenium.click("//div[@id='postings_wrapper']/ul/li[2]/div/div/div[4]/div[1]/h5/a");
selenium.waitForPageToLoad("30000");
selenium.goBack();
selenium.captureScreenshot("C:/My Documents/Test/screenshot.png");
}

@Test
public void testUntitled1() throws Exception {
selenium.open("http://google.co.uk");
selenium.type("q", "selenium rc");
selenium.click("btnG");
verifyTrue(selenium.isTextPresent("Selenium Remote Control (RC) is a test tool that allows you to write "));
selenium.click("//ol[@id='rso']/li[3]/h3/a/em[2]");
selenium.waitForPageToLoad("30000");
verifyTrue(selenium.isTextPresent("Selenium RC (aka SRC) is a server that allows you to launch"));
selenium.click("//div[@id='PageContent']/table[2]/tbody/tr[2]/td/table/tbody/tr/td/div[1]/p[15]/span/a");
selenium.waitForPageToLoad("30000");
selenium.click("link=Selenium Basics");
selenium.waitForPageToLoad("30000");
}

@AfterClass
public void tearDown() {
selenium.stop();
}
}

Shivayogi said...

Hi Mahesh

I am able to execute the script using the http://www.imdb.com for the first piece of code what u have provided,thanks for your guidlines.
Still I am unable to run using the excel file,I will try it and do let you know about it.

Thanks
Shivayogi

Mahesh Narayanan said...

Guys, please watch the video I posted on youtube. The video explains this whole exercise from scratch. Most of your queries will be solved if you follow the instructions given in the video.
Thanks

Mahesh Narayanan said...

shiva, were you able to make this work?

Shivayogi said...

Hi Mahesh,

Extremely sorry for not replying to your comment due to some problem I was out of station. Today I am very happy to share this, now I am able drive the data from excel, thanks my friend for giving your valuable time and a million worth code to the people. I am very much glad by executing this script. Now I will keep mailing you.
My mail id is shivayogiks@gmail.com, don't mind I don’t like to ask your valuable mail ID, Please shoot a test mail, I wish to be in contact with you through mails.

Thanks
Shivayogi

Mahesh Narayanan said...

Hi shiva, I am glad you could make it work.

Guys, some feedback on the video would be helpful. I plan to create more such video tutorials on selenium related topics soon so your feedback will be very valuable to me.

thanks

Anonymous said...

Mahesh

Excellent videos. Easy to follow and understand. Yes, post more videos please. What about showing how to run a suite of classes and a dashboard to show the results when the suite is running and at the end of the run. Or updating the spreadsheet with a pass or fail.

Steven said...

Hi,
Thanks for the great tutorial. I am having an issue tho..

When I run the test I get the following error:

"error in getTableArray()
FAILED: testDataProviderExample
java.lang.NullPointerException"


I followed your tutorial exactly except for the Test folder name because my workspace was already created. Any help you could give me would be much appreciated. Thanks, ST

Unknown said...

Mahesh,

First of all thanks for valuable information, I was goggling since few days to get some useful information about selenium, at last I got it.
I am new to selenium and java; currently I am doing R&d on Test management tool called Bromine which supports Selenium RC.
Selenium is wonderful tool I thought to implement selenium frame work in our organization.

Unknown said...

Mahesh,

I have followed all steps and configured the setup using eclipse IDE,however while running the .java file as NGTest following error is occuring:


"java.lang.UnsupportedClassVersionError: Bad version number in .class file"


I get to know that this is because of version difference i done all necessary changes in eclipse,still i am not able to solve this issue,can any one help me on above issue.

Mahesh Narayanan said...

strifu,

make appropriate change to the line
Object[][] retObjArr=getTableArray("test\\Resources\\Data\\data1.xls", "DataPool","imdbTestData1");

Insert the path that is relevant to your setup.

Shivayogi said...

Hi Mahesh,

I have one more query related to the script which you have provided,I am using the same script to test my application by doing some changes to the code i.e. the column name movietitle(parameter) I am passing it wherver I require,according to me the movititle should fetch the values one after the next,but as and when the script executes the first row values of the excel login and user name values are properly inserted in theapplication but as and when it navigates in the application it's not inserting the values of the second row instead of it is provide the first row values only, please do let me know your feed back,what exactly the changes need to be done in your cript.Please have a look into this script.

public void setUp() throws Exception {
// SeleniumServer seleniumserver=new SeleniumServer();
//seleniumserver.boot();
// seleniumserver.start();
setUp("http://qamain1.gtnexus.local/", "*firefox");
//selenium.open("/");
selenium.open("/login.jsp");
selenium.waitForPageToLoad("30000");
selenium.windowMaximize();
selenium.windowFocus();
}

@Test (dataProvider = "DP1")
public void testDataProviderExample(String movieTitle, String directorName) throws Exception {
//enter the movie title
//selenium.type("q", movieTitle);
selenium.type("//input[@name='login']",movieTitle);
selenium.type("password", directorName);
selenium.click("//input[@type='image']");
selenium.waitForPageToLoad("30000");
selenium.select("gotolink", "label=Contracts");
selenium.click("//input[@value='Go']");
selenium.waitForPageToLoad("30000");
selenium.click("link=Enter Contract");
selenium.waitForPageToLoad("30000");
selenium.click("link=Ocean Contract");
selenium.waitForPageToLoad("30000");
selenium.type("//input[@name='orgname']", movieTitle);
selenium.click("link=Validate");
selenium.waitForPopUp("popwindow", "30000");
selenium.type("refnum", directorName);
selenium.click("//input[@value='Continue']");

Mahesh Narayanan said...

shiva,
Please post the code of the @DataProvider createData() function.

Anonymous said...

Hi Mahesh
Due to my accident I was on leave sorry,the same script I have used whatever u have given for function @DataProvider createData

Shivayogi said...

Hi Mahesh
Due to my accident I was on leave sorry,the same script I have used whatever u have given for function @DataProvider createData

Shivayogi said...

Hi Mahesh is it possible to use any other Testng annotation to resolve this issue.
like @Parameters instead of the @dataprovider.

Mahesh Narayanan said...

If everything is same then it should work without any problem. Check the start and end table markers in the excel sheet.

Shivayogi said...

Hi Mahesh,
I am facing the problem as follows,
It's retrieving all the data from excel, I want first row excel values should be put in the first page of the application and second row values should be on the next page so on. It’s not happening like this.once the first row values r put again the same values are added in to the second page.
Please suggest me.

Thanks
Shivayogi

Mahesh Narayanan said...

shiva,
your understanding of the data-driven concept is incorrect. The data is not structured page wise but it is structured test case wise or iteration wise. Hence one row is equal to one test case or one iteration. One test case may deal with one or many pages depending on the logic of the test case.

Sri4QA said...

Hi Mahesh,

I have gone through many blogs and sites and felt your example is one of the much need and advanced one.

I have simulated exactly all the DataProviderExample with jar files as u described in this blog, But I am facing UnsupportedclassVersionNumber:BadVersionNumber Error.

JDK:1.5
Eclipse:Galileo(3.5)
TestNG:5.9
Ant:apache-ant-1.7.1
Actually much experienced in QTP but not in selenium
Please, Let me know the solution or u r suggestion for which i need to correct.
[srihari9876@gmail.com]

srikanth said...

[Parser] [WARN] Unknown value of attribute 'parallel' at suite level: ''.
[Parser] Running:
D:\Test Selenium\temp-testng-customsuite.xml

17:48:34.222 INFO - Java: Sun Microsystems Inc. 10.0-b19
17:48:34.222 INFO - OS: Windows XP 5.1 x86
17:48:34.253 INFO - v1.0.1 [2696], with Core v@VERSION@ [@REVISION@]
17:48:34.394 INFO - Version Jetty/5.1.x
17:48:34.394 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
17:48:34.394 INFO - Started HttpContext[/selenium-server,/selenium-server]
17:48:34.394 INFO - Started HttpContext[/,/]
17:48:34.410 INFO - Started SocketListener on 0.0.0.0:4444
17:48:34.410 INFO - Started org.mortbay.jetty.Server@eb017e
17:48:34.738 INFO - Checking Resource aliases
17:48:34.738 INFO - Command request: getNewBrowserSession[*iexplore, https://mobilebankingq4.chase.com/, ] on session null
17:48:34.738 INFO - creating new remote session
17:48:35.472 INFO - Allocated session c5dc2c2b0b0d4e83ab1b8baaa8091a40 for https://mobilebankingq4.chase.com/, launching...
17:48:35.894 INFO - Launching Embedded Internet Explorer...
17:48:37.003 INFO - Launching Internet Explorer HTA...
17:49:03.128 INFO - Got result: OK,c5dc2c2b0b0d4e83ab1b8baaa8091a40 on session c5dc2c2b0b0d4e83ab1b8baaa8091a40
17:49:03.160 INFO - Command request: open[/Public/Home/LogOn, ] on session c5dc2c2b0b0d4e83ab1b8baaa8091a40
17:49:27.035 INFO - Got result: OK on session c5dc2c2b0b0d4e83ab1b8baaa8091a40
17:49:27.066 INFO - Command request: windowMaximize[, ] on session c5dc2c2b0b0d4e83ab1b8baaa8091a40
17:49:27.144 INFO - Got result: OK on session c5dc2c2b0b0d4e83ab1b8baaa8091a40
17:49:27.144 INFO - Command request: windowFocus[, ] on session c5dc2c2b0b0d4e83ab1b8baaa8091a40
17:49:27.191 INFO - Got result: OK on session c5dc2c2b0b0d4e83ab1b8baaa8091a40
error in getTableArray()
FAILED: testDataProviderExample on instance null(dataProviderExample)

===============================================
dataProviderExample
Tests run: 1, Failures: 1, Skips: 0
===============================================


===============================================
Test Selenium
Total tests run: 1, Failures: 1, Skips: 0
===============================================

[org.testng.internal.PoolService] Shutting down poolservice org.testng.internal.PoolService@1d256fa terminated:false
17:49:27.441 INFO - Shutting down...
17:49:27.441 INFO - Stopping Acceptor ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=4444]
17:49:27.441 INFO - Shutting down...


Hi Mahesh i am getting the following error message please chk it and let me knw the solution.

srikanth said...

Code used is:-

@DataProvider(name = "DP1")
public Object[][] createData1() {
Object[][] retObjArr=getTableArray("D:\\Srikanth\\data1.xls","DataPool","TestData1");
return(retObjArr);


}

Mahesh Narayanan said...

srikant,
check the name of the table in xl sheet. make sure the start and end markers are placed correctly.

sunny said...

hii mahesh

when i am trying to run as .....i couldnt see the test ng option der
..it shows only run as junit....
could you please let me know where i made mistake

Mahesh Narayanan said...

sunny,
you did not install the testng eclipse pluggin.

sunny said...

Hi mahesh

yeah that problem i have solved.Thanks

But now i want to Write a generic java api for converting the table into datastructure and call the generic api from regular java testcase.

Could u please guide me in this problem.how to do it?

Vignesh said...

Mahesh,

Awesome Job and a Great Article !! Videos were very useful ! Do keep adding more posts on Selenium !!


Srikanth,

For the DPE Example, for your Error, have you Renamed your Excel Sheet (From Sheet1 to DataPool) ?

public Object[][] createData1() {
Object[][] retObjArr=getTableArray("test\\Resources\\Data\\data1.xls",
"DataPool", "imdbTestData1");
return(retObjArr);
}

Try renaming the Excel sheet (Sheet1) as per Video 3 Posted by Mahesh.

-Vignesh

srikanth said...

HI Mhesh the mistke in mine was that i renamed the Excel file and it got saved as .xls .xls. hence the issue. any ways tks for ur solution. its working fine

sam said...

Mahesh,

After the all the rows in the data pool is run i want to do some save action...where do i insert the save command is in script..

Unknown said...

Mahesh thanks a lot.
This example helped a lot.

Nemo said...

Hi Mahesh,

Thanks for the blog and a great video presentation about selenium.

Facing the following problem ! My eclipse console log says that the attribute 'Parallel' is missing.

************************************************************

[Parser] [WARN] Unknown value of attribute 'parallel' at suite level: ''.
[Parser] Running:
E:\Automation\GUI_Automation\temp-testng-customsuite.xml


===============================================
Test.Example
Tests run: 0, Failures: 0, Skips: 0
===============================================


===============================================
GUI_Automation
Total tests run: 0, Failures: 0, Skips: 0
===============================================

[org.testng.internal.PoolService] Shutting down poolservice org.testng.internal.PoolService@8965fb terminated:false

******************************************************************


Please let me know if there is a way out -

Thanks,
Vijay

Mahesh Narayanan said...

Nemo, check the temp-testng-customsuite.xml in your project (see the project tree on the left in eclipse) and remove any thing that says parallel=something


The xml (for this example) should be look something like










Sam, there is no provision to save values back in the xl sheet. I mean that is outside the scope of this topic. However you shoudl look up the jxl documentation to see how that can be done, i'm sure it is posssible.

Amit Chaudhary said...

Hi Mahesh,

This example is excellent and best suited for Data Driven. Just for enhancement, i want to update the status for each row as pass or fail in the same excel fine. Can u help me on this........or u can suggest me something else so that i can update the results in Quality Center as per the status for each row. Thanking you in advance for your help.

arulPrakash said...

Hi Mahesh,
Excellent tutorial.One thing I want to do is here u do the iteration in sequence ,whether the parallel iteration is possible.I have done parallel execution by specifying the port no when I executed testcase(html script) using the '-port' option .How can I achieve this in a java program like yours and all the rows(testcase data)in excel must be executed parallel.The no of rows will not be more than 4(for now).Pls help on this..

Thanks,
Arul

Mahesh Narayanan said...

atul,

iteration wise parallel execution is not possible. However you can call this test method in five different wrapper test methods and run with parallel=test setting.

arulPrakash said...

thanks for your response.But I can't get you completely.Do you mean like I should have the same method repeated(5 times for 5 rows).If that is the case how the methods will take a unique row for execution?And also where can I set the attribute as 'parallel=test'.I also came through that the data provider can provide data parallely to the test method with the attribute 'parallel=true'. Thats why I was wondering if there is any option to specify the port(port no also taken from the excel sheet) no so that multiple instances of selenium servers can be run parallely.

Thanks,
Arul

Mahesh Narayanan said...

atul,
1)define the function once
2) call the function inside 4 different wrapper methods
3)In datasheet define 4 tables, each with one row
4)hook up the test methods with one table each
5)In testng.xml define parallel=test at suite level

arulPrakash said...

I got your solution.So it requires 4 data providers and 4 wrapper methods and 4 tables.But this solution is not scalable.Taking this issue my 1 testcase will run for 15 minutes .That is why I wanted to parallelize.So this becomes a big draw back in Selenium.Don't they have any generic solution for this kinda problems?Have you not faced this problem?Pls guide me if there is any alternative.This part is very critical in my project.

Thanks,
Arul

Mahesh Narayanan said...

atul,
parallelism or lack of it has got nothing to do with selenium. This is a feature provided by testng i.e the framework that is used for this example. Currently testng provides parallel execution at class and test levels. You can put in a request to the testng team (check out nabble forum for testng) for parallelism support at dataprovider iteration level. Or you could create a framework that does that for you. Also you don't need multiple instance of selenium server to support parallel execution, you need only of one instance. hope this helps.

Anonymous said...

Hi Mahesh,

Can you help me to run this setup using command prompt instead of eclipse IDE.

Anonymous said...

Hi Mahesh,
Thanks for your reply. But i see the link provided by you is using the Eclipse. I am looking for the situation where i have java and all required jars. In that case.how we can run this selenium testng setup.

One more thing, i am planning to run this set up on my mac does it need any special configuration or the given steps will do........looking for your resplonse. Thanks in advancce.

Mahesh Narayanan said...

No there is no eclipse, the workspace folder is called 'MyEclipseWorkspace' because this is coming from the previous example. Eclipse is not needed at all to run this from command line. If you don't want to use eclipse even for developing this script then just create the appropriate folder structure in your local drive and put the java, xls and and jar files in them respectively. You can get the folder structure from the dataprovider example (video). Now if you don't want to follow the folder structure and want to use your own folder structure then you would have to make appropriate changes to the path mentioned in the bat file. And yes this should run in MAC just fine. You just need to install the JRE, JDK and excel for mac in your case.
Try this and let me know if you face any problems at all.
Cheers.

Anonymous said...

Hey Mahesh,

Thanks for your so quick response. Being from testing background, i do not have very much knowledge of java. I will be thankful, if u can post the commands for me i need to run on command prompt to execute this set up. Can we integate these test results in QC also or can we run this script through QTP?

About MAC i will update you soon.

Thanks
Amit Chaudhary

Mahesh Narayanan said...

Amit, you can execute the command prompt one step at a time by copy pasting it and pressing .

Anonymous said...

Hi Mahesh,

I am looking for the commands which i need to execute.

Thanks
Amit Chaudhary

Mahesh Narayanan said...

sorry, I meant http://functionaltestautomation.blogspot.com/2010/02/running-testng-tests-from-command-line.html

Yogendra said...

Hi Mahesh,

I am about to give up if i dont get any help from you for running this script.

What problem I am facing is, I followed all the steps you have mentioned, but,In eclipse when I right click and select Run as>Testng, nothing happens.I mean eclipse is not running the script and is failed to identify the testng class.
Either this could be the problem in setting up testng or in eclipse.
I never faced such problem when I run junit test cases.
Please suggest me if you have any idea.
Also, i want to know whether I need to add the testng class path in windows environment variables? If so let me know the steps how and what I needs to do.
Ur help will be deeply appreciated.

Thanks,
Yogendra.Joshi

Mahesh Narayanan said...

Yogendra, you don't need to set any environment variables. Are you sure you have the testng plugin installed. This step is not mentioned in the video but is mentioned in the post. Also ensure that you have the @Test annotation before your test method.

Yogendra said...

Hi Mahesh,
Thanks a lot for your trouble.
I tried with all the steps you have mentioned in the blog, but I still could not resolve the problem.One last help I need from you.
Could you please specify the detailed versions of apps you are using, like
jdk,java,junit,ecclipse and testng.

Once you give me the details, I will try with new setup and hopefully my problems would get resolved.
Please give me the details.

Thanks,
Yogendra.Joshi

Mahesh Narayanan said...

use the latest version of all the libraries.

Yogendra said...

Hi Mahesh,
Thanks a lot for you reply.
I am finally able to run the scripts.
And as you said I installed all the latest versions of softwares and thus I could able to run test scripts without any issue.
I am very thankful to your help.I will visit your blog for ever for new updates.

Thanks,
Yogendra.Joshi

Anonymous said...

Hi Mahesh
Can I use Selenium IDE insted of Eclipse IDE for this practise.
Pls tell me

Mahesh Narayanan said...

Actually you don't need any IDE. See http://functionaltestautomation.blogspot.com/2010/02/running-testng-tests-from-command-line.html

Selenium IDE (options-->Format-->Java TestNG) can just be used for compilation and not for execution.

Doug said...

I am very new to this so I watched your video and I have everything set up correctly as far as I can see using the exact setup from the video. For some reason I can not get the browser to start up. I keep getting: Failed to start new browser session: java.lang.RuntimeException: Firefox 3 could not be found in the path!
Please add the directory containing ''firefox.exe'' to your PATH environment
variable, or explicitly specify a path to Firefox 3 like this:
*firefox3c:\blah\firefox.exe on session null
error in getTableArray()

I have the path to firefox set in the setUp: setUp("http://www.imdb.com/", "*firefox C:/Program Files/Firefox3/firefox.exe");

What am I doing wrong?

Mahesh Narayanan said...

I tried installing firfox in g: instead of c: an it worked perfectly.
setUp("http://www.imdb.com/", "*firefox G:/Program Files/Mozilla Firefox/firefox.exe");

I have firefox 3.0.6. Try using that version on the default installation.

Anonymous said...

Hi Mahesh!

Your blog is very useful and I could successfully do it from scratch.

I am having issue with running multiple tests.
Only first test executes and the remaining tests fail.

But when I copy the content of the second test in to first test, it works fine!

Can you please suggest?

Unknown said...

Hi Mahesh or anyone,

setUp command in your example is launching FireFox. I tried to launch IE using command like

setUp("http://www.imdb.com", "*iehta")


But its not launching. Any suggestions as to how I can do the testing using IE ?

Mahesh Narayanan said...

hi shanmukha,

I tried with setUp("http://www.imdb.com/", "*iehta");

and it worked. I have IE 7 installed.
Please try with this version.

Unknown said...

Thanks a lot Mahesh. When I try to launch firefox and goto a particular website it shows me that digital certficate webpage and asks me to click i understand the risks add exception. how do i get around with it so that it doesnt ask me this everytime?

hemangi said...
This comment has been removed by the author.
hemangi said...

Hi Mahesh,
Thanks for such a gr8 guidelines.
I am not sure is it a correct place to put my problem.
My problem is below
----------------
we are using ScreenshotOnFailureListener to capture the screen shots
on failure
but it created the screenshot with complete path name & data supplied for the data driven testcases.
The problem is when file name exceeds more than 255 characters we are
getting error that unable to create Name.png file.
Ex. if data for if the testcase is in class OQT_1491_class & testcase
is OQT_1491_testcase & if we pass
data1 ,data2 ,data3 ,data5 ,data5 &data6 as input data we get image file with name

com.CompanyName.testCases.Administration.OQT_1491_class.OQT_1491_testcase.d­ata1.data2.data3.data4.data5.data6.png

---------------------
we are using listeners="org.fest.swing.testng.ScreenshotOnFailureListener,org.uncommons.­reportng.HTMLReporter in build.xml
---------------------
Is there any solution for this?

FYI....
I have also placed my problem at
http://groups.google.com/group/testng-users/browse_thread/thread/9652bdf892a1c27c
March 26, 2010 9:18 PM

harish said...

Hi Mahesh,

Thanks for the great tutorial! That was indeed a great article for users like me who are new to Selenium and Java.

I followed all the instructions shown in the video, but when I run the script I'm getting the following error. Please do help me out with the error.


junit.framework.AssertionFailedError: No tests found in script.dataProviderExample
at junit.framework.Assert.fail(Assert.java:47)
at junit.framework.TestSuite$1.runTest(TestSuite.java:263)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)


Thanks,
Harish

Unknown said...

Friends,

Need help, I followed all the instructions as given by Mahesh, but i cant see Run As-->TestNG Test option under Eclipse (version 3.1).

A quick help will be highly appreciated.

Kind Regards,
Rattan

Mahesh Narayanan said...

Ratan,
You have to install the testng pluggin for eclipse. Follow the instructions given on http://testng.org/doc/download.html to install the pluggin.

Unknown said...

Cheers Mahesh,

There was an error in the link from my side, which lead to failure of Testng plugin installation.
Now I'm suck with a weird problem. I did the following:
1) Installed the required plugins
2) Restarted the Eclipse (v 3.1)
3) Selected the DataProviderExample code > Right click > Run As > TestNg

Result: - Nothing happens!
Not sure what am missing now.

Unknown said...

Friends,

I'm still stuck. After installing the eclipse (v3.1) plugins using the link -- http://beust.com/eclipse1, i could see the Testng option when i try to Run --dataProviderExample code. But nothing happens after that. Neither any window pops up nor the code executes.

Is this some kind of eclipse bug?
Help will be highly appreciated.

Rattan

Mahesh Narayanan said...

Rattan,
1.try running some simple junit tests.
2.remove eclipse, reinstall it again and then install the testng pluggin.

Yogendra said...

@Ratan,

Install Eclipse Galileo version.
It must Work.

Thanks,
Yogendra.Joshi

Unknown said...

Hi

My Program was working good till now but today i added anothr column in the Data sheet giving number as the input. However the programme is throwing Number exception error.
I used find cell ( string string...) method
I input it as a string value still i am unable to get wats the issue

Mahesh Narayanan said...

Bhavneet,
1.In excel select all cells of the table
2.right click select format cells-->Under category select General. click OK

This should solve this problem. If it does not solve the problem post back here.

YoGuess said...

Hi Mahesh,

Much helpful tutorial so far....
I have a little confusion as i'm new to this automation. Just in case if i want to perform negative testing say text or image doesn't exists or reference of movie has been removed from IMDB...
Also what should be delivered to the client???
Few weeks i've started automation and don't mind if the questions seems to be stupid...

Thanks,
Yogesh

Mahesh Narayanan said...

Hi yogesh,
although negative testing has nothing to do with this article but i can tell you that you cn test fr something that is not there(not true=false) by using verifyFalse or assertFalse.

You can deliver the scripts as it is (.JAVA files) or you can send them after converting them into JAR or an EXE.

Mahesh Narayanan said...

Hi yogesh,
although negative testing has nothing to do with this article but i can tell you that you cn test fr something that is not there(not true=false) by using verifyFalse or assertFalse.

You can deliver the scripts as it is (.JAVA files) or you can send them after converting them into JAR or an EXE.

Ramesh kumar said...

Thanks mahesh this is very useful ..

Zener said...

Hello Mahesh,

Thank you for this helpful tutorial.

I've palyed with your code a little bit and found that one thing in your code is obscure for me.
You are using VerifyTrue method from SeleneseTestCase class, right? But this method doesn't fail test when running 'As TestNg'. I mean in the TestNg report all tests are always passed even if the text is not actually present on the page.

Could you explain this?

Mahesh Narayanan said...

Hi Zener,
you are right I have used the verify method from Selenium class instead of testng class (verify method does not exist in testng, although it can easily be created). As a result the fail checkpoint does not appear in testng report. I wrote the tutorial to demonstrate the @dataprovider functionality of testng more than anything hence did not care too much about checkpoints.

Zener said...

Hi again,

Could you give some hints how to make verify methods from SeleneseTestCase class working with TestNg?

Thanks.

Mahesh Narayanan said...

Zener,
The solution to your problem lays here http://seleniumexamples.com/blog/guide/using-soft-assertions-in-testng/

Now you must do the following
1) Add TestBase.java, TestListenerAdapter.java, CustomTestListener.java in your java project
2) Next you will now be using the verifyTrue given in the TestBase in place of the method given in SeleneseTestCase. So do the modification in your tests.
3) You need to add the CustomTestListener class as a listener. You have 2 ways of doing this a) add it a s listener in the testng xml or b) create a template xml and add it in eclipse->window->Preferences->testng->template xml file
4) update the testng pluggin to 5.12 or higher, there is a bug in the older version pluggin that ignores custom listener.
5)Thank Dave of seleniumexamples.com for creating a great solution for this problem.

ketakiandrajat said...

Mahesh, Your video is extremely useful for getting setup with data driven tests using Excel and Selenium. Unfortunately, while executing with TestNG, I am hitting a java.lang.NullPointerException (and a stack of 19 testng) exceptions. I believe this is the same issue Shivayogi was facing. Unfortunately, I couldn't find a documented solution to this. Do you (or Shivayogi) have any ideas on how this can be resolved? I have followed your video to a tee :).
Thanks,
Raj

agentsmith said...

Mahesh, Wonderful work!! great effort!!

I followed all the instructions as per the video, but i cant see Run As-->TestNG Test option under Eclipse (version 3.6)

have done the same steps you ask to perform to Rattan,
Could you please help me on this...

Best Regards,
Smith

Mahesh Narayanan said...

Rajat, Please check the table name and the spreadsheet name.

agentsmith, Please add the eclipse testng pluggin.

ketakiandrajat said...

Thanks Mahesh. Unfortunately, I don't think that's the issue. I am using Office 2010. Are you aware of any compatibility issues? Also, an explicit DataProvider in the form of an array works....so you are right that problem lies in locating/opening the excel file. Any other thoughts?

agentsmith said...

Hi Mahesh,
I have tried with the eclipse Galileo version + with all the mentioned plugins there in http://testng.org/doc/index.html
have installed the plug-in, restart Eclipse and select the menu Window / Show View / Other... and I am unable to see the TestNG view listed in the Java category, like JUnit is there.

Could you please help me.

Best Regards,

Mahesh Narayanan said...

Rajat, try saving the xls as Microsoft Excel 97-Excel 2003 (from save as type). I am not sure of any issues with the 2010 but who knows.

agentsmith, try eclipse->Help->About Eclipse Platform->plug-in Details and see if it lists TestNG.did you allow eclipse to install testNg automatically (help->software updates)or did you install the plugin manually?

Unknown said...
This comment has been removed by the author.
agentsmith said...

thanks Mahesh for you quick attention.And its done finally, issue with the plugin version and the .jer file.sorted out.

Thank you once again. Would like to see more tutorials on TestNG frame work.

Brilliant Work!!

ketakiandrajat said...

Mahesh, your recommendation worked. Thanks! I saved the Excel file as a 2003 version, and the script picked it up. This was frustrating me for a better part of 2 days!

Thanks again...
PS>> Do you have any resources/tutorials for testing Flash using Selenium?

YoGuess said...

Hi Mahesh,
I'm facing one more trouble that I'm unable to create the executable jar file. the problem here is that the MANIFEST.MF file is not including the class file. Itried it by entering it manually but it dint work. JAR file is created but JVM throws an error when i try to run that file.
i have my source file in /src/script/test.java
Thanks

Sowmya said...

Hi Mahesh,
This is very good article, in the above example you have passed the parameters to your testMethod, when i did the same Driver throwing error like "No test found in the given class", if i removed the parameters it is able to recognize testMethod and execute. If then how to achieve what you have provided in the example.

Manu said...

Hi Mahesh,

I am new to Selenium and I am trying to do data driven testing.I followed all your instructions and still getting "java.lang.NullPointerException"
I checked every possible thing but still no luck. Could you please help. Following is the error message:
java.lang.NullPointerException
at org.testng.internal.MethodHelper.invokeDataProvider(MethodHelper.java:697)
at org.testng.internal.Parameters.handleParameters(Parameters.java:383)
at org.testng.internal.Invoker.handleParameters(Invoker.java:1161)
at org.testng.internal.Invoker.createParameters(Invoker.java:895)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:978)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:137)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:121)
at org.testng.TestRunner.runWorkers(TestRunner.java:953)
at org.testng.TestRunner.privateRun(TestRunner.java:633)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:316)
at org.testng.SuiteRunner.run(SuiteRunner.java:195)
at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:903)
at org.testng.TestNG.runSuitesLocally(TestNG.java:872)
at org.testng.TestNG.run(TestNG.java:780)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:75)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:127)

Unknown said...

For all those who got

Null Pointer exception,

here is the solution. You must hae given wrong sheet name, file name or foder name where the excel file is stored.
Please check if the sheet name you gave is exactly "DataPool" including the case of characters

Piyush SHarma said...

Hi Mahesh
I am very new to Selenium i am facing some test failure so please help me to get out of it. Blelow i am attaching the failure log.

[Parser] Running:
C:\Documents and Settings\piyushs\Local Settings\Temp\testng-eclipse\testng-customsuite.xml

startRow=5, endRow=11, startCol=2, endCol=7
FAILED: testDataProviderExample on instance null(script.dataProviderExample)("The Silence of the Lambs", "Jonathan Demme", "Dr. Hannibal Lecter. Brilliant. Cunning. Psychotic. In his mind lies the clue to a ruthless killer. - Clarice Starling, FBI. Brilliant. Vulnerable. Alone. She must trust him to stop the killer.", "Anthony Hopkins")
java.lang.NullPointerException
at script.dataProviderExample.testDataProviderExample(dataProviderExample.java:39)
... Removed 22 stack frames
FAILED: testDataProviderExample on instance null(script.dataProviderExample)("The Birds", "Alfred Hitchcock", "A wealthy San Francisco playgirl pursues a potential boyfriend to a small Northern California town that slowly takes a turn for the bizarre when birds of all kinds suddenly begin to attack people there in increasing numbers and with increasing viciousness", "Rod Taylor")
java.lang.NullPointerException
at script.dataProviderExample.testDataProviderExample(dataProviderExample.java:39)
... Removed 22 stack frames
FAILED: testDataProviderExample on instance null(script.dataProviderExample)("Hannibal", "Ridley Scott", "Hannibal returns to America and attempts to make contact with disgraced Agent Starling and survive a vengeful victim's plan.", "Anthony Hopkins")
java.lang.NullPointerException
at script.dataProviderExample.testDataProviderExample(dataProviderExample.java:39)
... Removed 22 stack frames
FAILED: testDataProviderExample on instance null(script.dataProviderExample)("The Bourne Ultimatum", "Paul Greengrass", "Bourne dodges new, superior assassins as he searches for his unknown past while a government agent tries to track him down.", "Matt Damon")
java.lang.NullPointerException
at script.dataProviderExample.testDataProviderExample(dataProviderExample.java:39)
... Removed 22 stack frames
FAILED: testDataProviderExample on instance null(script.dataProviderExample)("Point Break", "Kathryn Bigelow", "An FBI agent goes undercover to catch a gang of bank robbers who may be surfers.", "Patrick Swayze")
java.lang.NullPointerException
at script.dataProviderExample.testDataProviderExample(dataProviderExample.java:39)
... Removed 22 stack frames

===============================================
script.dataProviderExample
Tests run: 5, Failures: 5, Skips: 0
===============================================


===============================================
dataDrivenTestProject
Total tests run: 5, Failures: 5, Skips: 0
===============================================

[org.testng.internal.PoolService] Shutting down poolservice org.testng.internal.PoolService@14a55f2 terminated:false

Adi said...

Most amazing and wonderful description. Thanks a lot Mahesh.

Ashish said...

Thanks so much Mahesh. I am new to Selenium and trying to learn it. Your blog has helped to immensely. Thanks buddy!!

cheers
Ashish

Pradeep said...

Hi Mahesh,

How to handle java script alert.Selenium IDE is not recording these alert.In may application on save shows one message"record saved successfully" and need to click on OK.How to handle this.Please give ur suggestions.
Thanks&Regards
Pradeep

sai krishna said...

Hi Mahesh,

I'm Krishna...

I went through ur post .. extremly helpfull .. i tried to excute the above code.. im getting the below Error .. please help me ..

TestNG] Running:
C:\Documents and Settings\saik\Local Settings\Temp\testng-eclipse\testng-customsuite.xml

15:15:47.484 INFO - Java: Sun Microsystems Inc. 16.3-b01
15:15:47.484 INFO - OS: Windows XP 5.1 x86
15:15:47.500 INFO - v2.0 [a2], with Core v2.0 [a2]
15:15:47.656 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
15:15:47.656 INFO - Version Jetty/5.1.x
15:15:47.656 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
15:15:47.656 INFO - Started HttpContext[/selenium-server,/selenium-server]
15:15:47.656 INFO - Started HttpContext[/,/]
15:15:47.703 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@10e35d5
15:15:47.703 INFO - Started HttpContext[/wd,/wd]
15:15:47.703 INFO - Started SocketListener on 0.0.0.0:4444
15:15:47.703 INFO - Started org.openqa.jetty.jetty.Server@109de5b
15:15:47.796 INFO - Checking Resource aliases
15:15:47.796 INFO - Command request: getNewBrowserSession[*firefox, http://www.imdb.com/, ] on session null
15:15:47.796 INFO - creating new remote session
15:15:47.906 INFO - Allocated session 1dc874bd3d44424b8f20d8fd73987f72 for http://www.imdb.com/, launching...
15:15:48.015 INFO - Preparing Firefox profile...
15:15:50.265 INFO - Launching Firefox...
15:15:52.937 INFO - Got result: OK,1dc874bd3d44424b8f20d8fd73987f72 on session 1dc874bd3d44424b8f20d8fd73987f72
15:15:52.953 INFO - Command request: open[/, ] on session 1dc874bd3d44424b8f20d8fd73987f72
15:16:04.812 INFO - Got result: OK on session 1dc874bd3d44424b8f20d8fd73987f72
15:16:04.828 INFO - Command request: windowMaximize[, ] on session 1dc874bd3d44424b8f20d8fd73987f72
15:16:04.875 INFO - Got result: OK on session 1dc874bd3d44424b8f20d8fd73987f72
15:16:04.875 INFO - Command request: windowFocus[, ] on session 1dc874bd3d44424b8f20d8fd73987f72
15:16:04.906 INFO - Got result: OK on session 1dc874bd3d44424b8f20d8fd73987f72
FAILED: testdataProviderExample on instance null(script.dataProviderExample)
org.testng.TestNGException: java.lang.reflect.InvocationTargetException
... 18 more
Caused by: java.io.FileNotFoundException: test\Resources\Data\Data1.xls (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.(Unknown Source)
at jxl.Workbook.getWorkbook(Workbook.java:213)
at jxl.Workbook.getWorkbook(Workbook.java:198)
at script.dataProviderExample.getTableArray(dataProviderExample.java:66)
at script.dataProviderExample.createData1(dataProviderExample.java:29)
... 24 more
... Removed 26 stack frames

===============================================
script.dataProviderExample
Tests run: 1, Failures: 1, Skips: 0
===============================================


===============================================
dataDrivenTestProject
Total tests run: 1, Failures: 1, Skips: 0
===============================================

15:16:05.125 INFO - Shutting down...

sai krishna said...

After giving the Right path im still getting this mahesh.,...


FAILED: testdataProviderExample on instance null(script.dataProviderExample)
org.testng.TestNGException: java.lang.reflect.InvocationTargetException
... 18 more
Caused by: jxl.read.biff.BiffException: Unable to recognize OLE stream
at jxl.read.biff.CompoundFile.(CompoundFile.java:116)
at jxl.read.biff.File.(File.java:127)
at jxl.Workbook.getWorkbook(Workbook.java:221)
at jxl.Workbook.getWorkbook(Workbook.java:198)
at script.dataProviderExample.getTableArray(dataProviderExample.java:66)
at script.dataProviderExample.createData1(dataProviderExample.java:29)
... 24 more
... Removed 26 stack frames

===============================================
script.dataProviderExample
Tests run: 1, Failures: 1, Skips: 0
===============================================


===============================================
dataDrivenTestProject
Total tests run: 1, Failures: 1, Skips: 0
===============================================

15:48:59.781 INFO - Shutting down...

Archana said...

Hello Mahesh,
I truly appreciate the time and effort you have put in. Job well done. :)
I am just beginning to use Selenium and your blog helped me a LOT.
I was hoping you could help me with a problem I am facing.
Let us say, I have script1, script2, and script3. Script1 gets data from an Excel sheet. With each set of data, a dynamic ID gets generated. So if the Excel data sheet has 30 rows (30 test cases), 30 dynamic IDs are generated. I have to store these dynamic IDs that are inputs to script2. How can i write the outputs/dynamic IDs generated into an Excel sheet? Is this possible? Or do you have any other suggestion as to how i can setup my scripts.

Thanks,
Archana

Mahesh Narayanan said...

Hi Archana,
No need to store it back in excel, just store it in key value pair or array and pass it on to the next script. You can do this by declaring the array/dictionary variable in public/common space.

sonam said...

Hi, i saw the videos and i am trying to automate a test using selenium. But it is not starting the browser window and the following error is being reported on the window.
org.testng.TestNGException

:

Cannot establish connection: 127.0.0.1:1849

at org.testng.remote.strprotocol.StringMessageSenderHelper.connect(

StringMessageSenderHelper.java:94)

at org.testng.remote.RemoteTestNG.run(

RemoteTestNG.java:59)

at org.testng.remote.RemoteTestNG.main(

RemoteTestNG.java:127)

Caused by:

java.net.ConnectException: Connection refused: connect

at java.net.PlainSocketImpl.socketConnect(

Native Method)

at java.net.PlainSocketImpl.doConnect(Unknown Source)

at java.net.PlainSocketImpl.connectToAddress(Unknown Source)

at java.net.PlainSocketImpl.connect(Unknown Source)

at java.net.SocksSocketImpl.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

at java.net.Socket.(Unknown Source)

at java.net.Socket.(Unknown Source)

at org.testng.remote.strprotocol.StringMessageSenderHelper.connect(

StringMessageSenderHelper.java:56).


Could you please help.
Thanks,
Sonam

Anonymous said...

i am new to selenium. i tried login scenario with your example.I am able to run the script with multiple usernames&passwords.now,i would like to parameterize the browser info(firefox,iexplore etc) through other spreadsheet.so,i think i need a way to work in a way like nested for loop. (firefox-id1,pass1,id2,pass2; iexplore- id1,pass1,id2,passe). How can i get this? please suggest me.

eure said...

Greate tutorial Mahesh.. Thanks for your effort..

I m just starting to use it and manage to get it work.

Wanted to consult your expertise here.. I have a page contain 4 check box, and test case might have
1. Only tick on 1st check box
2. Only tick on 2nd check box
3..etc

I have excel workshet created with 4 columns being name as 'a', 'b', 'c', 'd'

for test case 1, i will place a value 1 at the first row and under column 'a'. For test case 2, i will palce value 1 at second row, under the column of 'b'. and so on..

following is my script;
public void testDataProviderExample(String a, String b, String c, String d) throws Exception {

if (a == "1")
{
selenium.click("//input[@name='selectedMovie' and @value='0.01']");
}
/*if (b == "1")
{
selenium.click("//input[@name='selectedMovie' and @value='0.02']");
}
if (c == "1")
{
selenium.click("//input[@name='selectedMovie' and @value='0.03']");
}
if (d == "1")
{
selenium.click("//input[@name='selectedMovie' and @value='0.04']");
}
}

however, above doesn't work for me, any idea how i could tick the checkbox based on test data prepared in excel?

eure said...

public void testDataProviderExample(String a, String b, String c, String d) throws Exception {

if (a == "1")
{
selenium.click("//input[@name='selectedMovie' and @value='0.01']");
}
if (b == "1")
{
selenium.click("//input[@name='selectedMovie' and @value='0.02']");
}
if (c == "1")
{
selenium.click("//input[@name='selectedMovie' and @value='0.03']");
}
if (d == "1")
{
selenium.click("//input[@name='selectedMovie' and @value='0.04']");
}
}

eure said...

Hi.. just ignore my post, i hv got my solution...the if statement will work fine if i have this;
if (a.equalsIgnoreCase("1"))
{
selenium.click("//input[@name='selectedMovie' and @value='0.01']");
}

Thank you :)

laxmi said...

Hi Mahesh,

I am getting the following error.
SKIPPED: testdataProviderExample on instance null(script.dataProviderExample)
I have given the same data which were given by you. I am using ubuntu. I have saved the spreadsheet in .xls format. Can you please help me

laxmi said...

Hi Mahesh,

It worked for me. In the file path I gave forward slash instead of backward slashes. it is like test/Resources/Data/Data1.xls

Vipul N Mehta said...

Hi Mahesh,


Thanks for the wonderful article.Looking forward for some more articles informative blogs too.

Thanks

Shilpa said...

Mahesh,

I need your help for doing data driven testing using SeleniumRC Testng framework.

I got stuck with first step itself.....i have added testng jar files in plug-in folder and restarted eclipse.

the testng is not reflected as Run As option.

Could you please help me out with this issue.

Thanks,
Shilpa

Mahesh Narayanan said...

Shilpa, you forgot to install the testng pluggin for eclipse. This is different from testng jar. Read my post carefully.

Shilpa said...

Thank you very much for quick reply Mahesh.
I am able to setup datadriven script as per your instructions.I am now stuck with one more issue...the script is working in Iexplore and not in firefox getting timedout exception.Below are the logs for that.Could you please help me out with this issue.

Setting connection parameters:127.0.0.1:2756

[TestNG] Running:

19:48:30.612 INFO - Command request: open[/, ] on session 02c926b4cf4647f4bec13abda33527b1

19:49:01.051 INFO - Got result: Timed out after 30000ms on session 02c926b4cf4647f4bec13abda33527b1

startRow=1, endRow=7, startCol=1, endCol=6

FAILED CONFIGURATION: @BeforeClass setUp

com.thoughtworks.selenium.SeleniumException: Timed out after 30000ms

at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:97)

at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:91)

at com.thoughtworks.selenium.DefaultSelenium.open(DefaultSelenium.java:335)

at DataProviderExample.setUp(DataProviderExample.java:20)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:74)

at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:521)

at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:198)

at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:126)

at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:183)

at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:115)

at org.testng.TestRunner.runWorkers(TestRunner.java:1119)

at org.testng.TestRunner.privateRun(TestRunner.java:744)

at org.testng.TestRunner.run(TestRunner.java:600)

at org.testng.SuiteRunner.runTest(SuiteRunner.java:315)

at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:310)

at org.testng.SuiteRunner.privateRun(SuiteRunner.java:272)

at org.testng.SuiteRunner.run(SuiteRunner.java:221)

at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)

at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)

at org.testng.TestNG.runSuitesSequentially(TestNG.java:952)

at org.testng.TestNG.runSuitesLocally(TestNG.java:889)

at org.testng.TestNG.run(TestNG.java:818)

at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:89)

at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:144)



SKIPPED: testDataProviderExample on instance null(DataProviderExample)("The Silence of the Lambs", "Jonathan Demme", "Dr. Hannibal Lecter. Brilliant. Cunning. Psychotic. In his mind lies the clue to a ruthless killer. - Clarice Starling, FBI. Brilliant. Vulnerable. Alone. She must trust him to stop the killer.", "Anthony Hopkins")

Thanks,
Shilpa

Shilpa said...

Mahesh,I went one step ahead and found issue....Application under test(AUT) works behind proxy.when when i select firefox,the selenium server is not able to access requested site because firefox proxy settings are automatically set to blank.When i launch manually new firfox window ,i could see proxy setting.This problem looks interesting.Also,it works fine when i run some other program in Junit.

I tried to resolve this issue by setting -avoidproxy and system.sethttphost,system.sethttpproxy..etc.,still it is not working.

Please help me if you have any solution.

Thanks,
Shilpa

Himadri said...

Hi Mahesh,

With the Other Applauds I am Joining mine "Great Article from an Indian".
I have a Specific Problem: I want to run a Data driven form Testing with Selenium-Testng, which Covers 1) Insering Personal details like Name, Phone number etc. 2)Next page: Addrres fillup with a Address lookup Function and Years os Stay drop down 3) Next Page: Choosing Username/password and Two related Dropdown menu Selection 4)Next Page: Some More radio button Selections and Drop Down Menu Selctions..

With yourexample with www.IMDB.com the Program fetches Data from excel and verifies with the Website. Now I want to emulate where it Fetches from excel and Populates Data into the Forms with different combinations of radio buttons and dropdown menu selections to see an END result.

Is this kind of Testing Possible with Current Scenario.Please Help me out as I am Out of Thoughts....and your Blog shows me as only Ray of HOPE...

-- Himadri

Mahesh Narayanan said...

Himadri, thanks for your appreciation. All of what you said is possible but remember that action 1, 2, 3 & 4 that you described will pick data from the same row in one pass if go by the my example.

1 row = 1 test case
1 test case = all 4 actions

Himadri said...

Mahesh, thanks for your reply!

I am 100% agreed with your comment 1 Test case = all 4 actions (Pages)

But my main Hurdle is Selection of the different combinations of radio buttons and Drop down Selection in all these pages, which gives a Certain Message (in the last page)that I have to Test (which is Manual now , and needs automation).

Can I request you to create another Landmark Example like this which will help the whole Selenium-TestNG Community and least me to feel blessed...

Himadri (tohimadri@gmail.com)

Himadri said...

This is a Request to other Forum Readers as well: Can we make an Example for a typical Forms Testing with Selenium-TestNG framework. To carry Forward the Good work of Mahesh to the 2nd LEVEL....

Unknown said...

Hi mahesh, I was showing your same example in my trainnig session. I was questioned by one of the person asking how will the script fails. Then i tried to edit the data in the excel file by changing the director names, you know what the script did not fail.It ran sucesfully.I was shcoked in the session.Can you tell the solution for this.

Mahesh Narayanan said...

Please see the reply given to zener in the post comments.

Unknown said...

Thanks Mahesh for the help.

Kunal said...

Hi Mahesh,

I need a help,while trying to run using eclipse Gannymade(3.4) in windows 7 OS.Firefox-3.6.8, its launching the imdb website but abruptly ending.throwing some TestNG exception.I am using testng-5.9-jdk15.jar and testng-eclipse-5.12.0.6 plugin.

Mahesh Narayanan said...

kunal this looks like a jdk compilation error. looks like you have compiled it with a different jdk and running it in a different jvm. Please start afresh.

Unknown said...

Hi Mahesh,

As per your responce i tried adding up the 3 java files to use Veriftrue of TestNG.So i have added TestBase.java, TestListenerAdapter.java, CustomTestListener.java in my java project.

There is an error on 'getCurrentTestResult()' method in TestBase.Java file. Can you please give me a solution to resolve this issue.

Thanks

Unknown said...

The error it shows me is "The method getCurrentTestResult() from the type Reporter is not visible".

Anonymous said...

Its a wonderful blog, worked like a charm!!!! Good work and keep blogging like this

fcohen said...

Thanks for the tutorial. It is very well written. Two things come to mind:

1) Have you looked at PushToTest TestMaker's Data Production Library (DPL) system? It automatically injects operational test data from csv, RDBMS, and data generating objects into Selenium scripts without any coding. It is entirely free under GPL open source license. Details at http://www.pushtotest.com

2) We're hiring a tech writer. Interested?

-Frank

Mahesh Narayanan said...

Hi Frank,
I have left you a message through pusttotest contact us.

Kunal said...

I am trying to implement Keyword driven Framework using testNg and Selenium.But while executing one scenario i am getting the below error;

com.thoughtworks.selenium.SeleniumException: Timed out after 30000ms
at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:97)
at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:91)
at com.thoughtworks.selenium.DefaultSelenium.waitForPageToLoad(DefaultSelenium.java:635)
at script.suiteDrive.keywordMaster(suiteDrive.java:96)
at script.suiteDrive.createData2(suiteDrive.java:62)
at script.suiteDrive.testDataProvider(suiteDrive.java:41)

Kunal said...

Please help me with this issue as i am stuck.Hope to receive a valuable answer from you.

Mahesh Narayanan said...

kunal, please post your questions in http://www.seleniumforum.com/

digvijay singh said...

Hi... i have tried with the help of your video. All things are going well but at the dataProviderExample function its throwing an exception (Null pointer exception)
It showing as:
(script.dataProviderExample:testDataProviderExample
java.lang.NullPointerException)

Query: How to fix this problem or where its being false.

Thanks
Digvijay

Abdullah said...

Hi Mahesh, I was able to run this example successfully. The kind of setup I have in my test class is that I modularized different logical parts of tests into a separate test in the same class file. For example, Login is first test then I get into customers account details page where I need to verify the details of customers login id, etc. Lets say Login is TestA and accounts details is TestB (this test has verification isntructions). Can I have a row of data read form the excel sheet and run TestA then TestB (in sequence_ before moving on the next row of data to run TestA and TestB again?
If not is there any tweaking I can do to get this functionality in my test project?

Mohan Kumar Ravilla said...

Hi Mahesh,
Thanks a lot, this helped me a lot.

Thanks,
Mohan.

Jason Brown said...

Hi Mahesh,

I really appreciate for this blog.
I did each step according to your videos. I dobn't know why I am getting this error.

-------
Unable to create view: org.eclipse.jface.viewers.TableViewerColumn

-----------
java.lang.NoClassDefFoundError: org.eclipse.jface.viewers.TableViewerColumn
at org.testng.eclipse.ui.summary.SummaryTab.createViewer(Unknown Source)
at org.testng.eclipse.ui.summary.SummaryTab.createTestViewer(Unknown Source)
at org.testng.eclipse.ui.summary.SummaryTab.createTabControl(Unknown Source)
at org.testng.eclipse.ui.TestRunnerViewPart.createTabControl(Unknown Source)
at org.testng.eclipse.ui.TestRunnerViewPart.loadTestRunTabs(Unknown Source)
at org.testng.eclipse.ui.TestRunnerViewPart.createTestRunTabs(Unknown Source)
at org.testng.eclipse.ui.TestRunnerViewPart.createPartControl(Unknown Source)
at org.eclipse.ui.internal.ViewReference.createPartHelper(Unknown Source)
at org.eclipse.ui.internal.ViewReference.createPart(Unknown Source)
at org.eclipse.ui.internal.WorkbenchPartReference.getPart(Unknown Source)
at org.eclipse.ui.internal.ViewReference.getView(Unknown Source)
at org.eclipse.ui.internal.WorkbenchPage.findView(Unknown Source)
at org.testng.eclipse.TestNGPlugin.findTestRunnerViewPartInActivePage(Unknown Source)
at org.testng.eclipse.TestNGPlugin.access$0(Unknown Source)
at org.testng.eclipse.TestNGPlugin$1.run(Unknown Source)
at org.eclipse.swt.widgets.RunnableLock.run(Unknown Source)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Unknown Source)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Unknown Source)
at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
at org.eclipse.ui.internal.Workbench.runEventLoop(Unknown Source)
at org.eclipse.ui.internal.Workbench.runUI(Unknown Source)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Unknown Source)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(Unknown Source)
at org.eclipse.ui.internal.ide.IDEApplication.run(Unknown Source)
at org.eclipse.core.internal.runtime.PlatformActivator$1.run(Unknown Source)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(Unknown Source)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(Unknown Source)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(Unknown Source)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.core.launcher.Main.invokeFramework(Unknown Source)
at org.eclipse.core.launcher.Main.basicRun(Unknown Source)
at org.eclipse.core.launcher.Main.run(Unknown Source)
at org.eclipse.core.launcher.Main.main(Unknown Source)
-------

I would appreciate if you get back to me.

Mahesh Narayanan said...

jason, this looks like an eclipse error. Please get a fresh copy of eclipse.

Anonymous said...

Hello Mahesh!
I'm Ross, from Lithuania.
Just few days ago, I found your blog and this useful video material. I tried this tutorial and it worked amazing.

After that, I tried to make my own test and had some trouble with selecting page components, like text fields.

For Example, I want to type into login textfield - loginForm[login]. So I wrote command:

selenium.type("loginForm[login]", "Admin" );

After that, when Selenium is compiling my test, it crashes and views error "Couldn't find such element". But I check it with firebug, the name is correct.

What could cause such problem?

Abdullah said...

Hi. No one has any responded for my query posted on February 3, 2011 12:29 PM on this page.
Seems like Mahesh has read it but left no comments pertaining to this.

Does any one has any solution/comments for what I am trying to accomplish in my test framework? what I want is, if my test scenario has 5 steps, and all these 5 steps run using a set of dataRow from DataProvider, and lets say verification in step 4 fails but the test can continue, I want all 5 test steps to run for all iterations or dataRows from DataProvider and at the end, show only step 4 failed for each dataRow. I thought I could make each of these steps as a seperate test (with @Test annotation) in the same class file. Does anyone have any working solution?

Jason Brown said...

Thanks Mahesh

Jason Brown said...

Thank you so much Mahesh.

Now, I took the latest version of eclipse and program is starts running but I am getting this error.

Please help me. Do I suppose to create any xml or source folder
------
Exception in thread "main" com.beust.jcommander.ParameterException: Unknown option: -sourcedir
at com.beust.jcommander.JCommander.parseValues(JCommander.java:497)
at com.beust.jcommander.JCommander.parse(JCommander.java:188)
at com.beust.jcommander.JCommander.(JCommander.java:155)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:139)
-----

[Parser] Running:
C:\Documents and Settings\jason\workspace\mbdb\temp-testng-customsuite.xml

[org.testng.internal.annotations.JDK14AnnotationFinder] [WARNING] Invalid source directory -d ignored
[TestRunner] Running the tests
---------

Jimmy said...

Hi Mahesh,

Thank you very much for this amazing tutorial.

I got it to work for the most part but I ran into a small issue.

It seems to be skipping the test method, this is the message I got:

SKIPPED: testDataProviderExample on instance null(script.dataProviderExample)

Do you or anyone know what might be the problem? It loads the site, but then skips this entirely.

Any feedback/solution is greatly appreciated.

Thanks

Jimmy

Best Stories said...

@Mahesh -

Same problem as Jimmy I am also facing , Script loading the URL but after that its skipping the entire script.

Kindly help us.
Abhishek
Mail me at chaurasiya.abhishek@gmail.com

Rachna said...

hi Mahesh,

I am trying to input username/password in a new dialog box which opens up when the page gets loaded. But unable to handle the dialog box...can u please advice ?

Aruna said...

Eclipse IDE warns SeleneseTestCase Deprecated gets displayed. Please do share if any solutions are available.

Cheers,
Aruna

Unknown said...
This comment has been removed by the author.
Unknown said...

Great Job Mahesh..

Aruna said...

Hi,

Great article!

How do i change the port from the default 4444?

Regards,
Aruna

Anurag Acharya said...

Hi Mahesh,

This is a great article !! Please let me know how can i get the xls file that you have described and used for test data.

Thanks,
Anurag

Anurag Acharya said...

Can you please email that to me at: anuragacharya@gmail.com Thanks,Anurag

Kamalay said...

Hi Mahesh,

Thank you. Could you please let me know how to install NG plugin?

Kamalay said...

Hi All,

Please help me if anyone knows how to install NG Plugin for eclipse

Kamalay said...

Hi All,

Please help me if anyone knows how to install NG Plugin for eclipse

Unknown said...

I could not make my .xls file available in the tree view of the resources/data folder even after saving the .xls file in the resources/data folder.
Could someone help me in this please.

Thanks in advance...

Younus Poonawala said...

****************************************************************

(continued)

Still I get the following error message::


testDataProviderExample
Test class: com.directi.testcases.registerPublisher

java.lang.NullPointerException
... Removed 22 stack frames

Click to hide stack frames

java.lang.NullPointerException
at org.testng.internal.MethodInvocationHelper.invokeDataProvider(MethodInvocationHelper.java:125)
at org.testng.internal.Parameters.handleParameters(Parameters.java:412)
at org.testng.internal.Invoker.handleParameters(Invoker.java:1315)
at org.testng.internal.Invoker.createParameters(Invoker.java:1022)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1122)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.runWorkers(TestRunner.java:1147)
at org.testng.TestRunner.privateRun(TestRunner.java:749)
at org.testng.TestRunner.run(TestRunner.java:600)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:317)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:312)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:274)
at org.testng.SuiteRunner.run(SuiteRunner.java:223)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1049)
at org.testng.TestNG.runSuitesLocally(TestNG.java:974)
at org.testng.TestNG.run(TestNG.java:905)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:203)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:174)

Younus Poonawala said...

****************************************************************

Still I get the following error message::


testDataProviderExample
Test class: com.directi.testcases.registerPublisher

java.lang.NullPointerException
... Removed 22 stack frames

Click to hide stack frames

java.lang.NullPointerException
at org.testng.internal.MethodInvocationHelper.invokeDataProvider(MethodInvocationHelper.java:125)
at org.testng.internal.Parameters.handleParameters(Parameters.java:412)
at org.testng.internal.Invoker.handleParameters(Invoker.java:1315)
at org.testng.internal.Invoker.createParameters(Invoker.java:1022)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1122)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.runWorkers(TestRunner.java:1147)
at org.testng.TestRunner.privateRun(TestRunner.java:749)
at org.testng.TestRunner.run(TestRunner.java:600)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:317)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:312)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:274)
at org.testng.SuiteRunner.run(SuiteRunner.java:223)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1049)
at org.testng.TestNG.runSuitesLocally(TestNG.java:974)
at org.testng.TestNG.run(TestNG.java:905)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:203)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:174)

Mahesh Narayanan said...

Younus, you cannot have a DataProvider and the DataProvider function by the same name.

Simranjeet Singh Randhir said...

Hi Mahesh,

Really found the video and your explanation indeed insightful and useful for beginners like me. I could able to run your explained Data driven test on my machine.

Now, i want to make a data driven framework based on my above learning. I want to have modularity in my framework where each test case is separate Java file. Now how can i have this using testng annotations? Kindly help me in this

Unknown said...

Hi ,

I want to run the same test in parallel along the dataProvider.

Each time the test is executed new url is hit , the data to form new url is got from data sheet .

I made the data provider as parallel as true .But still not able to do it . Can you please let me know how to go with it .

Mohammad said...

Mahesh,
You are one of the best video instructors out there! the narration along the video is simple and concise. Great Work.
Now I am taking your exmaple and modifying it to fit need of our web app testing reqs

Raj Singh said...

Mahesh,

Very intuitive, even for a beginner like me. I wish I had a tutor like you to teach me selenium in more detail.

Anonymous said...

Excellent article.
Managed to write code by reading your article.

Thanks a ton.

Pooja Agrawal said...

Hi Mahesh,

Really an excellent article on data driven. i want to go for this data driven but i ma stuck with the installation of TestNG and TestNG eclipse plugin.

It wud be gr8 if you cud please provide me the complete details of testng installation and what version to use in each of the setups.

your early response wud be very helpful to me.

Do feel free to contact me thru poojaagrawalbhilai@gmail.com.

Regards,
Pooja Agrawal

Pooja Agrawal said...

Hi Mahesh,

I follwed the same steps as you mentioned above and i got stuck with the following error message:

error in getTableArray()
SKIPPED: testDataProviderExample on instance null(DataProviderExample.

Any quick soultion to this will be appreciated.

Thanks,
Pooja Agrawal

Priyanka said...

Hi Mahesh,

Excellent work I must say. I was all confused about how to go about the tool, but this blog made it so easy. I followed all the steps exactly and it worked all well for me.

Please do post more such articles.

Thanks,
Priyanka

Priyanka said...
This comment has been removed by the author.
abhisekdblogger said...

Hi Mahesh,Could you publish a blog on how to generate Test Result/Report from TestNG? It will be very heloful if u can publish such article using real-life example and step-by-step procedure.

Santhosh said...

Hi Mahesh,
I have @BeforeClass in my testcase and I have started selenium in @BeforeClass but control is not at all going to setUp(),it is directly going to @Test.Could you please help me with this?
Thank you

Ramya said...

Hi Mahesh,

Thanks for the article.Its really helpful.I tried exactly they way yu showed in the video but when i run the class I see below errors can you please advise?
java.lang.NoClassDefFoundError: SeleneseTestCase
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.testng.internal.ClassHelper.forName(ClassHelper.java:95)
at org.testng.xml.XmlClass.loadClass(XmlClass.java:73)
at org.testng.xml.XmlClass.init(XmlClass.java:68)
at org.testng.xml.XmlClass.(XmlClass.java:54)
at org.testng.xml.TestNGContentHandler.startElement(TestNGContentHandler.java:518)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.emptyElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(Unknown Source)
at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:17)
at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:10)
at org.testng.xml.Parser.parse(Parser.java:170)
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:303)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:86)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:199)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:170)
Caused by: java.lang.ClassNotFoundException: SeleneseTestCase
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 38 more
RemoteTestNG finishing: 0 ms

H said...

Thank you...
It is very useful...

Minal Bhargava said...

Hello Mahesh,

I had a quick question, I am trying to write a testng script to test the application: translate.google.com; I am not sure how do i drive my code to verify which language to be selected to verify the translation: for example: after I go to the site, i need to test english to spanish; english to french translations.

POS Equipment said...

Very useful and informative post. Excellent stuff from your side. Thanks Mahesh for sharing!

Anonymous said...

not able to execute the code although followed all the steps properly ....
suggest me how can i get out of this problem.....

"The attribute dataProvider is undefined for the annotation type Test"
>>>>>
@Test (dataProvider = "DP1")
>>>>>>

thanks...

Anonymous said...

Awesome post. Understood thoroughly. Keep up the good work and thanks a ton.

Faisee said...

Hi mahesh

Firstly, Want to say thank for the great post.

I have Doubt. Hope you can answer.
I have two table in excel(say T1 and T2) both tables has 2 row of recordset,
And I have one script with two @Test, respectively using T1 and T2 as DP.

Now when I run my script will my script iterate twice and traverse both and tables.

Supriti said...

Thanks Mahesh, a relevant post indeed.
Just wanted to know whether we can generate the log files as well just like we have it for the test reports/results

hisham.nazir said...
This comment has been removed by the author.
hisham.nazir said...

Hi
I get a java.lang.NullPointerException when i created my own test following the steps. The example you have provided works perfectly. I followed the example and did not make any major changes except for in the @test body. I cannot understand what could be causing the error

Vee Eee Technologies said...

I have no words for this great post such a awe-some information i got gathered. Thanks to Author.

pooja said...

Hi Mahesh,

This is amazing post by you to begginer in Selecium data Driven method .
Following your instrcution I am able to set up the Project and automate the application used in my company
But it has many options like drop down and radio button

First Problem I am faccing is one first row gets executed , others rows are getting skipped

And second cinfiuration Set Up methond is shown as skipped in the console

Please help on this


FAILED CONFIGURATION: @BeforeMethod setUp
java.net.BindException: Selenium is already running on port 4444. Or some other service is.
at org.openqa.selenium.server.SeleniumServer.start(SeleniumServer.java:464)
at scripts.DataProviderExample.setUp(DataProviderExample.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)




SKIPPED: testDataProviderExample("EVCDatadriven2", "off", "1/8/2012", "Northeast (NE ) ", "second test case", "ETHERNET ADD 1 OF 2 NODE B EVC OOF", "ADD TRUNKING PSTN WITH ROUTING NE", "ETHERNET ADD 1 OF 2 NODE B EVC OOF CBT", "Backward", "1/5/12", "5679")
SKIPPED: testDataProviderExample("EVCDatadriven3", "off", "1/9/2012", "Southeast (SE)", "third test case ", "ETTC DUAL NODE B SINGLE SIAD", "ADD TRUNKING PSTN WITH ROUTING SE", "ETHERNET ADD 2 OF 2 NODE B EVC OOF HAWAIIAN TEL", "Forward", "1/6/12", "12344")
SKIPPED: testDataProviderExample("EVCDatadriven4", "off", "1/10/2012



I really want your help how to resolve this
my email id is guptapooja2006@gmail.com

If you wish you can mail me in my gmail id


I will be very oblidged Mahesh

Pooja

Anonymous said...

Hi mahesh,
I am trying to implement the same program given by you but it is giving error that
"getTableArray("data1.xls","DataPool","TestData1");" not found

--------java code-----
package test;
import org.junit.AfterClass;
import org.openqa.selenium.internal.seleniumemulation.*;
import org.openqa.selenium.server.SeleniumServer;
import org.testng.annotations.*;
import com.thoughtworks.selenium.*;
import java.io.File;
import jxl.*;
import org.testng.annotations.Test;

public class DataProviderExample extends SeleneseTestCase {


@DataProvider(name = "DP1")
public Object[][] createData1() throws Exception{
Object[][] retObjArr = getTableArray("test\\Resources\\Data\\data1.xls","DataPool","TestData1");
return(retObjArr);
}
@Test
public void f() {

}
}

Thank you very much for your help really appreciate it.
my email id is samjmohd@gmail.com

Anonymous said...

Hi mahesh,

sorry I got it. It was my silly mistake.

thanks a lot for sharing such a valuable information

regards
sam

Bittu said...

Hi Mahesh,

while executing the test getting below error:


[TestNG] Running:
C:\Users\Appu\AppData\Local\Temp\testng-eclipse-1231733570\testng-customsuite.xml

startRow=5, endRow=11, startCol=2, endCol=7
FAILED CONFIGURATION: @BeforeClass setUp
java.lang.Error: Unresolved compilation problems:
The method windowMaximize(String) in the type Selenium is not applicable for the arguments ()
The method windowFocus(String) in the type Selenium is not applicable for the arguments ()

at script.DataProviderExample.setUp(DataProviderExample.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
.........................................

Please help me out.

Unknown said...

Hi guys NPE is caused when using testNG is because you are using old version of testNG like 6.01 Download TestNg 6.3.x it will give you correct error.

Thank you

pooja said...

Hi Mahesh

I am using testng version 6.3, but still getting null point exception error, I have followed the same steps as you suggested, but don't know getting the same error.
Please help, my mail id is pooja.garg2008@yahoo.com.

royal said...

Hi,
I paste the above DataProvider Example in eclipse.I got error in this line : Cell tableEnd= sheet.findCell(tableName, startCol+1, startRow+1, 100, 64000, false);

Shows the following error:

The method findCell(String) in the type Sheet is not applicable for the arguments (String, int, int, int, int, boolean).
How do I fix this. Please help. Thanks