jeudi 23 juillet 2020

How to rename the Existing Excel file with Current date and time using Selenium web Driver?

Filepath i am using but its not taking the current date and time

public static String FilePath="C:\\Users\\skumari1\\eclipse-workspace\\CoreLinkAutomation\\src\\main\\java\\com\\corelink\\testData\\PCPAutomation.xlsx"+ PrimaryCommonSetDataUTil.Validatedate();

For Current date and Time using this code

public static String Validatedate() {

        DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
        Date date = new Date();
        String date1= dateFormat.format(date);
        // System.out.println("Current date and time is " +date1);
         return date1;
    }

For writing data into Excel file using this code but i want to rename the Filepath

public static void write_test_result(String result, String sheet_name, String filePath,int row_num,int col_num) throws EncryptedDocumentException, FileNotFoundException, IOException
    {
        

        Workbook wb = WorkbookFactory.create(new FileInputStream(filePath));
        Sheet sh = wb.getSheet(sheet_name);
        
        sh.getRow(row_num).createCell(col_num).setCellValue(result);
        
        wb.write(new FileOutputStream(filePath));
        
            }

I want after every execution of Project the filepath should be renamed as Filepath+Current date and time, Please provide me help on this

Thank you

Aucun commentaire:

Enregistrer un commentaire