0
 public void UserConsentCreate(String TestNumber,String email,String lastName,String firstName,String deviceCode, String appVersion,String phone,String countryCode,String loginPassword,String dob,String baseUrl, String contactViaEmail, String contactViaSMS,String address1, String address2, String city, String postcode, String ukResidentConfirmation, String notificationConsent, String locationConsent
            ,String hasMedicalCondition, String hasAwaitingDiagnosis) throws IOException {
int version  = MaintreeVersion(TestNumber);
        System.out.println(version);
        JSONObject body =new JSONObject();
        body.put("personReference",dataReader.PERSONREFERENCE_PROPERTY_READER(TestNumber));
        body.put("contactViaEmail",contactViaEmail);
        body.put("contactViaSMS",contactViaSMS);
        body.put("mainTreeVersion",version);

        JSONObject auidtbody =new JSONObject();
        auidtbody.put("localTime", dtf.format(now));
        auidtbody.put("GMTTime", dtf.format(now));
        auidtbody.put("appRequestedTime", dtf.format(now));
        auidtbody.put("agentId", "1");
        auidtbody.put("agentName", "App");
        auidtbody.put("channel", "APP");
        auidtbody.put("deviceCode","1234567890");

        body.put("audit",auidtbody);

}

I used a CSV file to get data data provider code

 @DataProvider(name = "customer" )
        public static Object[][] getUserData()  throws IOException, CsvValidationException {
            **String xlFilePath = System.getProperty("user.dir") + "/src/TestData/User.csv";
            String[] line;
            List<String[]> arrlist = new ArrayList<String[]>();
            CSVReader reader = new CSVReader(new FileReader(xlFilePath));
            while ((line = reader.readNext()) != null) {
                arrlist.add(line);
            }
            int index = 0;
            arrlist.remove(index);
            int rowCount = arrlist.size();
            int columnCount = arrlist.get(0).length;
            String customerData[][] = new String [rowCount][columnCount];
            for(int i = 0 ; i < rowCount ; i++) {
                String[] eachRow = arrlist.get(i);
                for(int j = 0 ; j < columnCount ; j++) {
                    customerData[i][j] = eachRow[j];
                }
            }
            return customerData;
        }

Is there any other way to declare the parameters for the test method? One parameter change I want to change every method.How to slove this problem. I try to String args[] way it is working. i want to know is there any other solution?

  • 1
    Very similar question: https://stackoverflow.com/q/65662946/7804477 – Gautham M Nov 13 '21 at 10:19
  • Thank you @GauthamM. i have a problem with how to change the data provider method to using setters data – lahiru dilruwan Nov 16 '21 at 04:31
  • What do you mean by "using setters data"? – Gautham M Nov 16 '21 at 05:20
  • in this question-answer https://stackoverflow.com/q/65662946/7804477 This part : CellData with the relevant values of each row and instead of returning String[][] return CellData[]... – lahiru dilruwan Nov 16 '21 at 08:23
  • Once you have created a class like `CellData` with relevant fields and their setter methods, you could create a new `CellData` object for each row and then set values like `cellData.setTestNumber(eachRow[0]); cellData.setEmail(eachRow[1]);`.... – Gautham M Nov 16 '21 at 09:00

1 Answers1

0

The best way here is to make a class of data.
In the above case, I see there is user data and some data regarding the medical condition. So, either you can split into two classes User and UserMedicalData or use one class, based on your requirement.

Instead of creating an array of strings, create object of a class. Next time a new value comes, you can simply add to your class and dataprovider setter and use the same signature for all your methods.

niharika_neo
  • 8,441
  • 1
  • 19
  • 31