Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
399 views
in Programming by
recategorized by

 

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 like 0 dislike
by The go-to Tester (327 points)
selected by
 
Best answer

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.

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.
by The go-to Tester (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.
by The go-to Tester (327 points)
reshown by
You will have to change the way you read data from Excel file.
by
Ok thank you I will try it


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...