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

Solved 1 Answers 97 Views Programming
0 1

 

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.

1 Answer

0
Best answer
0

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

https://github.com/selenium-webdriver-software-testing/kspl-selenium-helper/tree/master/src/main/java/com/kagrana/util

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

 

To utilize it in @DataProvider see the code below.

@DataProvider(name="dataProvider")
    public Object[][] myDataProvider(){
        ReadCSV csv = new ReadCSV("CSVFile.csv");
        return MiscellaneousFunctions.listHashMapToObject(csv.run());
    }
    @Test(dataProvider="dataProvider")
    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.

answered by (327 points)
selected by
4Comments
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
    {
        DataSet++;
        //If found DataToRun = "N" for data set then execution will be skipped for that data set.
        if(!TestDataToRun[DataSet].equalsIgnoreCase("Y")){   
            //If DataToRun = "N", Set Testskip=true.
            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.");
        }

@DataProvider
    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

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.
...