Advertisement
Guest User

Untitled

a guest
Sep 17th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. @DataProvider
  2. public Object[][] JSONBODY()
  3. {
  4. String test_data = "json_data";
  5. int row = ExcelUtils.getRowNum(test_data, col_num);
  6. int total_col = ExcelUtils.getLastColumnNumber(row);
  7. Map<Integer, ArrayList<String>> map = ExcelUtils.getTableArray(spreadsheet_location,test_data,total_col);
  8. return new Object[][] { { map } };
  9. }
  10.  
  11. public static Map<Integer, ArrayList<String>> getTableArray(String FilePath, String testdata, int total_Col) throws Exception {
  12. Map<Integer, ArrayList<String>> map = new HashMap<Integer, ArrayList<String>>();
  13. ArrayList<Integer> iTestCaseRow = null;
  14. try
  15. {
  16. FileInputStream ExcelFile = new FileInputStream(FilePath);
  17. ExcelWBook = new XSSFWorkbook(ExcelFile);
  18. ExcelWSheet = ExcelWBook.getSheet(SheetName);
  19. int startCol = 1;
  20. iTestCaseRow = ExcelUtils.getRowContains(testdata ,col_num); // getRowContains returns list of row numbers for value in testdata.
  21. int totalRows = iTestCaseRow.size();
  22. int totalCols = total_Col;
  23. for(int i=0; i<totalRows;i++)
  24. {
  25. ArrayList<String> str = new ArrayList<String>();
  26. for (int j=startCol;j<=totalCols;j++)
  27. {
  28. str.add (ExcelUtils.getCellData(iTestCaseRow.get(i),j));
  29. }
  30. map.put(iTestCaseRow.get(i), str);
  31. }
  32. return map;
  33. }
  34. }
  35.  
  36. @Test(dataProvider = "JSONBODY")
  37. public void TestMethod(Map<Integer, ArrayList<String>> map) throws Exception {
  38. try
  39. {
  40. Log.startTestCase("Start executing Test Case");
  41. Set<Integer> key = map.keySet();
  42. for(Integer row: key)
  43. {
  44. SamplePojo pojo = new SamplePojo();
  45. ArrayList<String> data = map.get(row);
  46. pojo.setFirstName(data.get(0));
  47. pojo.setLastName(data.get(1));
  48. pojo.setEmail(data.get(2));
  49. pojo.setPhone(data.get(3));
  50. Response res = RestAssured.given().contentType(ContentType).body(pojo).when().post(POST_URL);
  51. Log.info(res.asString());
  52. Assert.assertTrue(res.getStatusCode() == 200 , "Test Case failed");
  53. }
  54. }
  55. }
  56.  
  57. Values = [Sample1, Name1, sample1.name1@gmail.com, (000) 111-1111]
  58. Values = [Sample2, Name2, sample2.name2@gmail.com, (000) 111-1112]
  59. Values = [Sample3, Name3, sample3.name3@gmail.com, (000) 111-1113]
  60.  
  61. ===============================================
  62. Default Suite
  63. Total tests run: 3, Failures: 0, Skips: 0
  64. ===============================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement