Want to insert data in a dynamic table from excel file.

0 votes


Msg from Msg To Per Msg  
1 10 0.36 +

While click on + sign it will add a new row & take value from excel file. Can you plz tell me how can i do this with TestNG DataProvide.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

1 Answer

answered by (327 points)
selected by
0 votes
Best answer

For fatching data from TestNG DataProvider you can use below code.


you may use ReadCSV file to read data and utilize it in your @DataProvider.


To utilize it in @DataProvider see the code below.

    public Object[][] myDataProvider(){
        ReadCSV csv = new ReadCSV("CSVFile.csv");
        return MiscellaneousFunctions.listHashMapToObject(csv.run());
    public void myDPTest(Hashtable<String, String> data){
        System.out.println(data.get("Msg from"));
        System.out.println(data.get("Msg To"));

Hope I am clear.

commented by
Thanks mayur,

But I am using a excel file for this.
And ny code is @Test(dataProvider="AddMnpFeesData")
    public void AddMnpFeesTest(String PlatformHub,   
            String Country,
            String MinimumCommitment,
            String BaseType,
            String MonthlyFee,
            String Currency,
            String EffectiveDate,           
            String MsgFrom,
            String MsgTo,
            String PerMsg,
            String MoreData,
            String ExpectedResult) throws IOException, InterruptedException
        //If found DataToRun = "N" for data set then execution will be skipped for that data set.
            //If DataToRun = "N", Set Testskip=true.
            SuiteUtility.WriteResultUtility(FilePath, SheetName, "Pass/Fail/Skip", TestCaseName, "SKIP");
            throw new SkipException("DataToRun for row number "+DataSet+" Is No Or Blank. So Skipping Its Execution.");

    public Object[][] AddMnpFeesData(){
        //To retrieve data from Data 1 Column,Data 2 Column and Expected Result column of AddMnpFees data Sheet.
        //Last two columns (DataToRun and Pass/Fail/Skip) are Ignored programatically when reading test data.
        return SuiteUtility.GetTestDataUtility(FilePath, TestCaseName);

From this i am able to read data but for the second row (after clicking on +sign) i am not able to do this.
commented by (327 points)
reshown by
Getting data from TestNG does not work that way. For that scenario #of rows in excel sheet = # of test execution. So you will have to fetch all the data at once and pass it via data provider.

Hope I am clear.
commented by (327 points)
reshown by
You will have to change the way you read data from Excel file.
commented by
Ok thank you I will try it