Not able to call method to write data in excel sheet

15 views
Skip to first unread message

Anshita Sen

unread,
Jun 8, 2018, 1:10:47 PM6/8/18
to Selenium Users
 I have two file  1. util.java  where im writing my methods and another is car.java where im calling the method. I have written the code to write data in excel but im not able to call the method in car file and write the data

public class Utils {

public static Workbook wb;
public static Sheet sh;
public static Row rw;
public static Cell cl;

public List<String> getExcelFile(String path, String sheetName, int TestCase, String sheetName1) throws Exception {

List<String> records = new ArrayList<String>();
String str = null;
FileInputStream ExcelFile = new FileInputStream(path);
wb = new HSSFWorkbook(ExcelFile);
sh = wb.getSheet(sheetName);

for (int i = 0; i < 16; i++) {
sh.getRow(TestCase).getCell(i).getCellType();

if (sh.getRow(TestCase).getCell(i).getCellType() != 1) {
sh.getRow(TestCase).getCell(i).setCellType(Cell.CELL_TYPE_STRING);
}

str = sh.getRow(TestCase).getCell(i).getStringCellValue();
records.add(str);

}
System.out.println("Data Values present in Excelsheet: " + records);
return records;

// System.out.println("Data Values present in Excelsheet: " + records);

}

public static List<String> setCellData(String path, String sheetName1, String ManfacturingYear, String Make,
String Model, String Variant, String Newcar, String Regyear, String Regcity, String UAEDriveExp, int RowNum,
int ColNum) throws Exception {

try {
FileInputStream writeExcel = new FileInputStream(path);

HSSFWorkbook wb = new HSSFWorkbook(writeExcel);
HSSFSheet sh1 = wb.getSheetAt(0);

int Rownum = sh.getLastRowNum();
// int colmun = -1;

for (ColNum = 0; ColNum < Rownum; ColNum++)
;
{
sh.getRow(0).createCell(0).setCellValue(1);
sh.getRow(0).createCell(0).setCellValue(2);
sh.getRow(0).createCell(0).setCellValue(3);
sh.getRow(0).createCell(0).setCellValue(4);
sh.getRow(0).createCell(0).setCellValue(5);
sh.getRow(0).createCell(0).setCellValue(6);
sh.getRow(0).createCell(0).setCellValue(7);
sh.getRow(0).createCell(0).setCellValue(8);

}

FileOutputStream fileout = new FileOutputStream(path);

wb.write(fileout);
System.out.println("Writing on Excel file Finished ...");
}

catch (Exception e) {
throw (e);
}
return null;

}

}


car.Java

public class Car {
//public WebDriver driver;
CarInsurers carInsurer = new CarInsurers();
Utils utils = new Utils();
List<String> ExcelData = new ArrayList<String>();
@Test(priority = 1)
public void TestCase001() throws Exception {
ExcelData = utils.getExcelFile("Test.xls", "Sheet1", 1, null);
String TestData = String.join(",", ExcelData);
String manfYear = TestData.split(",")[0];
String make = TestData.split(",")[1];
String model = TestData.split(",")[2];
String variant = TestData.split(",")[3];
String carNew = TestData.split(",")[4];
String regYear = TestData.split(",")[5];
String regCity = TestData.split(",")[6];
String uaeDrvExp = TestData.split(",")[7];
String intDrvExp = TestData.split(",")[8];
String lastYrClaim = TestData.split(",")[9];
String claimCert = TestData.split(",")[10];
String nationality = TestData.split(",")[11];
String name = TestData.split(",")[12];
String email = TestData.split(",")[13];
String mobile = TestData.split(",")[14];
String dob = TestData.split(",")[15];
System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
carInsurer.selectPreQuotes(driver, manfYear, make, model, variant, carNew, regYear, regCity, uaeDrvExp, intDrvExp, lastYrClaim, claimCert, nationality, name, email, mobile, dob);
carInsurer.clickGetQuotes(driver);
Thread.sleep(4000);
carInsurer.getQuotesPageDetails(driver);
driver.close();
}
}
Reply all
Reply to author
Forward
0 new messages