NexGenration

Selenium LEX 5

Dec 4th, 2021
2,906
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.test;
  2. import java.io.FileInputStream;
  3. import java.io.FileOutputStream;
  4. import java.io.IOException;
  5. import org.apache.poi.ss.usermodel.Cell;
  6. import org.apache.poi.ss.usermodel.Row;
  7. import org.apache.poi.xssf.usermodel.XSSFSheet;
  8. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  9. public class Demo11_ExcelWriting {
  10.     WebDriver driver;
  11.     String url = "http://localhost:8080/PackAndGo_v2/index.html";
  12.     @Before
  13.     public void setUp() {
  14.         //Set the key/value property according to the browser you are using.
  15.         //Open browser instance
  16.         //Open the AUT     
  17.         //Declare an implicit wait which is bounded to WebDriver instance
  18.     }
  19.     @Test
  20.     public void test() throws InterruptedException, IOException {
  21.         String filePath = System.getProperty("user.dir") + "\\Cred.xlsx";
  22.        
  23.         //FileInputStream
  24.         //Access the workbook
  25.         //Access the sheet
  26.         for (int i = 1; i <= rowCount; i++) {
  27.                 //Login and fetch the welcome message  
  28.    
  29.                 //Get the current row where the data has to be written
  30.             Row newRow = getSheet.getRow(i);
  31.            
  32.             //Create a new cell with reference to the row
  33.             Cell cell = newRow.createCell(2);
  34.            
  35.             //Set the value in the cell
  36.             cell.setCellValue(DashboardMessage);
  37.            
  38.             //Logout from the application.
  39.         }
  40.        
  41.         //Create an output stream with the location where the file has to be created
  42.         FileOutputStream fileOutputStream = new FileOutputStream(filePath);
  43.        
  44.         //Write the workbook
  45.         workbook.write(fileOutputStream);
  46.        
  47.         //Close the workbook
  48.         workbook.close();
  49.     }
  50.     @After
  51.     public void tearDown() {
  52.         //Close the browser.
  53.     }
  54. }
  55.  
RAW Paste Data