Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @DataProvider
- public Object[][] JSONBODY()
- {
- String test_data = "json_data";
- int row = ExcelUtils.getRowNum(test_data, col_num);
- int total_col = ExcelUtils.getLastColumnNumber(row);
- Map<Integer, ArrayList<String>> map = ExcelUtils.getTableArray(spreadsheet_location,test_data,total_col);
- return new Object[][] { { map } };
- }
- public static Map<Integer, ArrayList<String>> getTableArray(String FilePath, String testdata, int total_Col) throws Exception {
- Map<Integer, ArrayList<String>> map = new HashMap<Integer, ArrayList<String>>();
- ArrayList<Integer> iTestCaseRow = null;
- try
- {
- FileInputStream ExcelFile = new FileInputStream(FilePath);
- ExcelWBook = new XSSFWorkbook(ExcelFile);
- ExcelWSheet = ExcelWBook.getSheet(SheetName);
- int startCol = 1;
- iTestCaseRow = ExcelUtils.getRowContains(testdata ,col_num); // getRowContains returns list of row numbers for value in testdata.
- int totalRows = iTestCaseRow.size();
- int totalCols = total_Col;
- for(int i=0; i<totalRows;i++)
- {
- ArrayList<String> str = new ArrayList<String>();
- for (int j=startCol;j<=totalCols;j++)
- {
- str.add (ExcelUtils.getCellData(iTestCaseRow.get(i),j));
- }
- map.put(iTestCaseRow.get(i), str);
- }
- return map;
- }
- }
- @Test(dataProvider = "JSONBODY")
- public void TestMethod(Map<Integer, ArrayList<String>> map) throws Exception {
- try
- {
- Log.startTestCase("Start executing Test Case");
- Set<Integer> key = map.keySet();
- for(Integer row: key)
- {
- SamplePojo pojo = new SamplePojo();
- ArrayList<String> data = map.get(row);
- pojo.setFirstName(data.get(0));
- pojo.setLastName(data.get(1));
- pojo.setEmail(data.get(2));
- pojo.setPhone(data.get(3));
- Response res = RestAssured.given().contentType(ContentType).body(pojo).when().post(POST_URL);
- Log.info(res.asString());
- Assert.assertTrue(res.getStatusCode() == 200 , "Test Case failed");
- }
- }
- }
- Values = [Sample1, Name1, sample1.name1@gmail.com, (000) 111-1111]
- Values = [Sample2, Name2, sample2.name2@gmail.com, (000) 111-1112]
- Values = [Sample3, Name3, sample3.name3@gmail.com, (000) 111-1113]
- ===============================================
- Default Suite
- Total tests run: 3, Failures: 0, Skips: 0
- ===============================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement