0

I want to provide data in my dataProvider using json file which has Array in one parameter.

For single ID it works fine

But

ex. JsonFile

    {
  "dataSet": [
    {
      "testCase": "Verify the limit of IDListwith 11 IDList",
      "IDList": ["1000394","1000418","1000438","1000463","1000464","1000491","1000519","1000525","1000526","1000537","1000549"]

    },
    {
      "testCase": "Verify the limit of ksnList with  ksn",
      "ksnList":[ "1234" ]    

    }
  ]
}

Testng Dataprovider:

// Multiple Ids

@DataProvider
public static Object[][] getDataMul() throws FileNotFoundException, Exception {
    String path = System.getProperty("user.dir") + "\\input\\MultipleID_ValidJson.json";
       JsonElement jsonData = new JsonParser().parse(new FileReader(path));
        JsonElement dataSet = jsonData.getAsJsonObject().get("dataset");

        List<TestData_Json> testData = new Gson().fromJson(dataSet, new TypeToken<List<TestData_Json>>() {
        }.getType());
        Object[][] returnValue = new Object[testData.size()][1];
        int index = 0;
        for (Object[] each : returnValue) {
            each[0] = testData.get(index++);
        }
        return returnValue;
}
Brank Victoria
  • 1,447
  • 10
  • 17
  • 2
    And your question is...? – CrazySabbath Oct 01 '18 at 11:28
  • you can refer [working code](https://github.com/qmetry/qaf/blob/a87661031fc90f710cd41cb5969dc22d07909f27/src/com/qmetry/qaf/automation/util/JSONUtil.java#L143) used in [qaf](https://github.com/cbeust/testng/wiki/3rd-party-extensions#frameworks). – user861594 Oct 03 '18 at 01:43

0 Answers0