How to enter data from json array file when multiple array present in json file using java -


i reading input data json file. json file structure

`{  "testloginpage":[                     {                     "username":"hellotest",                     "password":"password1234",                     },                           ],  "emailtest":[                         {                         "fromemailaddress":"noreply@test.com",                         "testemailserver":"111.11.11.1",                         "testusername":"test",                         "testpassword":"test",                         },                         {                         "fromemailaddress":"aaaa@test.com",                         "testemailserver":"22.22.22.2",                         "testusername":"aaaa",                         "testpassword":"aaaa",                         },      ],  }` 

i able loop thru , able read data using following code:

public static void readfromjson() {          jsonparser parser = new jsonparser();         try{             filereader reader = new filereader ("<--filepath--><filenale>.json.txt");             jsonparser jsonparser = new jsonparser();             jsonobject jsonobject = (jsonobject) jsonparser.parse(reader);             jsonarray login = (jsonarray) jsonobject.get("testloginpage");             (int = 0; i<login.size();i++){                 jsonobject jsonobjectrow = (jsonobject) login.get(i);                 username = (string) jsonobjectrow.get("username");                 password = (string) jsonobjectrow.get("password");                 }             jsonarray emailtestfields = (jsonarray) jsonobject.get("emailtest");                     ( = 0; i<emailtestfields.size();i++)                     {                         system.out.println("the "+i+" elements in email test are" +emailtestfields.get(i));                     }                     iterator = emailtestfields.iterator();                     while (i.hasnext()){                         jsonobject innerobj = (jsonobject) i.next();                         system.out.println("from email address "+innerobj.get("fromemailaddress"));                         fromemailaddressemailsettings = (string) innerobj.get("fromemailaddress");                         system.out.println("test email server  "+innerobj.get("testemailserver"));                         emailserveremailsettings = (string) innerobj.get("testemailserver");                         system.out.println("user name "+innerobj.get("testusername"));                         testusernameemailsettings = (string) innerobj.get("testusername");                         system.out.println("test user password "+innerobj.get("testuserpassword"));                         testpasswordemailsettings = (string) innerobj.get("testpassword");                     }         }catch (exception e) {             system.out.println("error: "+e);         } } 

i have testng class m creating test script. script entering second set of data form , saving it. scenario trying achieve have read json how many set of records emailtest available (in eg 2) , in testng class have first take first set of emailtest data , enter , save , take second set , enter in web app , save. have created generic function enter data textbox working good. dont know how can carry loop count testng test script , first enter first data set , save , take second set, enter , save.

just save both jsonobject in list , pass data entering method eg

list<jsonobject> lst = new arraylist.. while (i.hasnext()){ jsonobject innerobj = (jsonobject) i.next(); lst.add(innerobj); }  (jsonobject : lst) {   putindata(a); }  public void putindata(jsonobject a) {    //sendkeys(a.getstring("fromemailaddress");    //... } 

Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -