Monday, 26 February 2018

Implicit Wait Vs. Explicit Wait Vs. Fluent Wait

When we do automation in selenium then waits for element is most important part in automation.

Why We Need Wait In Selenium?

When any page is load then different elements take different time to load or visible on page. So, if we do not handle wait in automation then "ElementNotVisibleException" exception will be thrown.

So, we have to handle waits in automation framework to overcome synchronization problem.

We can handle wait in three ways.
  1. Implicit Wait
  2. Explicit Wait
  3. Fluent Wait

Implicit Wait :

This wait will tell web driver to wait certain amoutn of time before thrown "ElementNotVisibleException" exception.

Syntax:

1
driver.manage().timeouts().implicitlyWait(TimeOut, TimeUnit.SECONDS);

Example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
public class Test 
{
 
 public WebDriver driver;

 @Test
 public void TestWait() throws InterruptedException 
 {
 System.setProperty ("webdriver.chrome.driver",".\\chromedriver.exe" );
 driver = new ChromeDriver(); 
 driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS) ;

 driver.findElement(By.id("txtUserId")).sendKeys(vUsername);   
 driver.findElement(By.id("txtPassword")).sendKeys(vPassword);
 driver.findElement(By.id("btnSignIn")).click();

 }

}

In above example, you can see timeout is for 10 seconds. So web driver will wait for 10 seconds if any element is not visible on page and after 10 seconds it will throw "ElementNotVisibleException" exception.


Explicit Wait :

This wait will tell web driver to wait till certain condition (Expected Condition) or maximum amount of time before throwing an "ElementNotVisibleException" exception.

Explicit wait is smart type of wait but it can only be applied specific elements. Once we declared explicit wait then we have to declare "Expected Condition" till which we want to wait.

Syntax:


1
WebDriverWait wait = new WebDriverWait(WebDriver,TimeOut);

Example:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
public class Test 
{
 
 public WebDriver driver;

 @Test
 public void TestExplicitWait() throws InterruptedException 
 {
 System.setProperty ("webdriver.chrome.driver",".\\chromedriver.exe" );
 driver = new ChromeDriver(); 
 
 WebDriverWait wait = new WebDriverWait(driver, 15);

 driver.findElement(By.id("txtUserId")).sendKeys(vUsername);   
 driver.findElement(By.id("txtPassword")).sendKeys(vPassword);

 WebElement SignIn = wait.until(ExpectedConditions.elementToBeClickable(By.id("btnSignIn")));

 SignIn.click(); 

 }
}

In above example, you can see first we set webdriverwait for 15 seconds. It means it will wait maximum 15 seconds then we set expected condition "elementToBeClickable" for SignIn element.

There are many expected conditions. We can use any of them as per our requirement.


Fluent Wait :

The fluent wait will tell the web driver to wait for a condition, as well as the frequency with which we want to check the condition before throwing an "ElementNotVisibleException" exception.

Frequency: it is repeat cycle with the time to verify the condition at the regular interval of time.

you can also specify Exception which you want to ignore to throw when webdriver is checking for particular element.

Syntax:


1
2
3
4
Wait wait = new FluentWait(WebDriver reference)
.withTimeout(timeout, SECONDS)
.pollingEvery(timeout, SECONDS)
.ignoring(Exception.class);

Example:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
public class Test 
{
 
 public WebDriver driver;

 @Test
 public void TestFluentWait() throws InterruptedException 
 {
 System.setProperty ("webdriver.chrome.driver",".\\chromedriver.exe" );
 driver = new ChromeDriver(); 
 
 Wait wait = new FluentWait(driver)
   .withTimeout(20, TimeUnit.SECONDS)    
   .pollingEvery(3, TimeUnit.SECONDS)    
   .ignoring(NoSuchElementException.class);

 driver.findElement(By.id("txtUserId")).sendKeys(vUsername);   
 driver.findElement(By.id("txtPassword")).sendKeys(vPassword);

 WebElement SignIn = wait.until(new Function() {
 
        public WebElement apply(WebDriver driver) {
 
        return driver.findElement(By.id("btnSignIn"));
 
        }
 
       });

 SignIn.click(); 

 }
}


In above example, you can see maximum timeout is set for 20 seconds.
Frequency is set for every 3 seconds by ignoring "NoSuchElementExecption".

Driver Setup with selenium wrapper automation

Driver setup is very important and necessary in any selenium automation.

We can setup driver with direclty write below line.

WebDriver vDriver = new FirefoxDriver();

but if we want to driver for other browser then we have to change code and call driver for that browser. It is not good approach that every time we change code as epr browser requirement.

SO, rather change code every time we can create method for setup driver and pass browser name as parameter for whcih browser we want. It is right approach to setup driver in any selenium automation framework.


I have created one call call 'SetupDriver' and create two methods in it. One for simple driver and second is for remote driver.

You can use this call directly and your automation framework. Whenever you want to setup driver then simple create object of 'SetupDriver' class and call method as per your requirement.


  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
public class SetupDriver 
{

 public WebDriver vDriver = null;
 public Proxy ZAPproxy;

 // Returs the webdriver. Input parameters are 
 // 1)vBrowser - Browser Type like
 // 2)vProxy - True / False
 public WebDriver mGetRemoteDriver(String vBrowser, boolean vProxy) 
 {

  // browser - chrome
  if (vBrowser.equalsIgnoreCase("chrome")) {
   DesiredCapabilities capability = DesiredCapabilities.chrome();

   if (vProxy) 
   {
    ProxyServer BrowserMobproxyServer;
    BrowserMobproxyServer = new ProxyServer(9090);
    try {
     BrowserMobproxyServer.start();
    } catch (Exception e1) {
     System.out.println("Exception during start of BrowserMobProxy");
     e1.printStackTrace();
    }
    Proxy BrowserMobproxy;
    BrowserMobproxy = new Proxy();
    BrowserMobproxy.setHttpProxy("localhost:8080");
    BrowserMobproxy.setSslProxy("localhost:8080");
    capability.setCapability(CapabilityType.PROXY, BrowserMobproxy);
   }
   ChromeOptions options = new ChromeOptions();   
   options.addArguments(Arrays.asList("--start-maximized", "allow-running-insecure-content", "ignore-certificate-errors"));
   capability.setCapability(ChromeOptions.CAPABILITY, options);
   capability.setBrowserName("chrome");
   
   try 
   {
    vDriver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
   }
   catch (UnreachableBrowserException E)
   {    
    System.out.println("Unreachable browser exception in class GetDriver for chrome browser");    
   }
   catch (MalformedURLException E)
   {    
    System.out.println("Malformed URL exception in class GetDriver for chrome browser");    
   }
  }

  // browser - firefox
  if (vBrowser.equalsIgnoreCase("firefox")) {
   DesiredCapabilities capability = DesiredCapabilities.firefox();
   capability.setBrowserName("firefox");

   if (vProxy) 
   {
    ZAPproxy = new Proxy();
    ZAPproxy.setAutodetect(false);
    ZAPproxy.setProxyType(ProxyType.MANUAL);
    ZAPproxy.setHttpProxy("localhost:8080");
    ZAPproxy.setSslProxy("localhost:8080");
    capability.setCapability(CapabilityType.PROXY, ZAPproxy);
   }
   
   FirefoxProfile fxProfile = new FirefoxProfile();

   fxProfile.setPreference("browser.download.folderList", 2);
   fxProfile.setPreference("browser.download.manager.showWhenStarting", false);
   fxProfile.setPreference("browser.download.dir", "c:\\mydownloads");
   fxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk",
     "application/pdf,text/csv,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/ms-excel");
   fxProfile.setPreference("browser.helperApps.alwaysAsk.force", false);
   // Disables PDF preview
   fxProfile.setPreference("pdfjs.disabled", true);
   fxProfile.setPreference("plugin.scan.plid.all", false);
   fxProfile.setPreference("plugin.scan.Acrobat", "99.0");

   capability.setCapability(FirefoxDriver.PROFILE, fxProfile);

   try 
   {
    vDriver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
   }
   catch (MalformedURLException E)
   {
    System.out.println("Malformed URL exception in class GetDriver for firefox browser");    
   }
   catch (UnreachableBrowserException E) {
    System.out.println("Unreachable browser exception in class GetDriver for firefox browser");    
   }
  }  

  // browser - internet explorer
  if (vBrowser.equalsIgnoreCase("internet explorer")) 
  {
   DesiredCapabilities capability = DesiredCapabilities.internetExplorer();
   capability.setBrowserName("internet explorer");
   try 
   {
    vDriver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
   } 
   catch (MalformedURLException E)
   {
    System.out.println("Malformed URL exception in class GetDriver for internet explorer browser");    
   }
   catch (UnreachableBrowserException E)
   {
    System.out.println("Unreachable browser exception in class GetDriver for internet explorer browser");    
   }
  }

  return vDriver;
 }
 
 public WebDriver mGetDriver(String vBrowser, boolean vProxy)
 {
  if (vBrowser.equalsIgnoreCase("chrome"))
  {
   try 
   {
    System.setProperty("webdriver.chrome.driver", "path of chrome driver");
    vDriver = new ChromeDriver();
   } 
   catch (UnreachableBrowserException E) 
   {    
    System.out.println("Unreachable browser exception in class GetDriver for chrome browser");    
   } 
   catch (Exception E) 
   {    
    System.out.println("Exception in class GetDriver for chrome browser");    
   }
  }
  else if (vBrowser.equalsIgnoreCase("firefox"))
  {
   try 
   {    
    vDriver = new FirefoxDriver();
   } 
   catch (UnreachableBrowserException E) 
   {    
    System.out.println("Unreachable browser exception in class GetDriver for firefox browser");    
   } 
   catch (Exception E) 
   {    
    System.out.println("Exception in class GetDriver for firefox browser");    
   }
  }
  else if (vBrowser.equalsIgnoreCase("internet explorer"))
  {
   try 
   {
    System.setProperty("webdriver.ie.driver", "path of ie driver");
    vDriver = new InternetExplorerDriver();
   } 
   catch (UnreachableBrowserException E) 
   {    
    System.out.println("Unreachable browser exception in class GetDriver for IE browser");    
   } 
   catch (Exception E) 
   {    
    System.out.println("Exception in class GetDriver for IE browser");    
   }
  }
    
  return vDriver;
 }
}

You can also read below other article on selenium wrapper automation.

How to handle drop down using selenium wrapper automation

Selenium Wrapper Automaton



Friday, 23 February 2018

Selenium Wrapper Automation

Selenium Wrapper automation is not any automation technique or framework it is just strategy which used in creation of automation framework.

Lets understand selenium wrapper automation with example.

when we are going to click any element using automation then we have to first check weather that element is present on page or visible or not. Once element is visible on page then after we can click on that element.
'Click on Element' event is common event in any automation.

Now assume that you have a scenario for automation and in that scenario you have to perform 5 or more time use 'Click on element' event. So, every time you have to first check weather element is present or not otherwise selenium will throw 'Element Not Found' exception.

So, rather than checking every time element present or not and wait till element visible we can create one function which perform both the thing on once go.
1. Check Element visible or not and if not then wait till some specific time
2. Click on element once it is visible

Thats called selenium wrapper automation.

It is so easy!! right?

you can also do same thing for many automation events which is common like drop down events, element visible or not etc.

You can use below function for click event into your automation framework.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
public boolean clickOnElement(WebDriver driver, WebElement vElement)
    {
     boolean bClickOnElement = true;

        final int WAIT_TIME = 3;  // this is in seconds
        final int MAX_RETRIES = 5;
        
        //WebDriverWait by default calls the ExpectedCondition every 500 milliseconds until it returns 

successfully. 
        // The max wait time is 15 seconds(3 seconds with 5 retries)
        
        WebDriverWait wait = new WebDriverWait(driver, WAIT_TIME);
        int retry = 0;
        while (true)
        {
            try
            {
             wait.until(ExpectedConditions.visibilityOf(vElement)).click();
                return bClickOnElement;
            }
            catch (Exception e)
            {
                if (retry < MAX_RETRIES)
                {                 
                    retry++;
                    continue;
                }
                else
                {                 
                 bClickOnElement = false;
                 throw new ElementNotVisibleException("Click on Element failed");
                 
                }
                
            }
        }
    }


If you want to do selenium wrapper automation for drop down then please click in below link

Drop down using Selenium Wrapper

Driver Wrapper Automation

Database Operations



How to handle drop down using selenium wrapper automation

Drop down is very common element in automation and there is many to handle drop down.

Selenium wrapper automation is very good approach to handle drop down in automation.

We can perform below actions on drop down.

  • Select option using text
  • Select option using index
  • Select option using value
  • Get all options

I have created one class 'DropDownFunction' and which contains all the above methods. You can use all methods with object of that class.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
public class DropDownFunction 
{ 
 public void mSelectByText(WebDriver driver, WebElement wDropdown, String vText)
 {  
  try
  {
   Select Dropdown = new Select(wDropdown);
   Dropdown.selectByVisibleText(vText);
  }
  catch (Exception E) 
  {
   System.out.println("Error in selecting dropdown option by visible text.");
  }  
 }
 
 public void mSelectByIndex(WebDriver driver, WebElement wDropdown, int vIndex)
 {  
  try
  {
   Select Dropdown = new Select(wDropdown);
   Dropdown.selectByIndex(vIndex);
  }
  catch (Exception E) 
  {
   System.out.println("Error in selecting dropdown option by index.");
  }  
 }
 
 public void mSelectByValue(WebDriver driver, WebElement wDropdown, String vValue)
 {  
  try
  {
   Select Dropdown = new Select(wDropdown);
   Dropdown.selectByValue(vValue);
  }
  catch (Exception E) 
  {
   System.out.println("Error in selecting dropdown option by value.");
  }  
 }
 
 public List<String> mGetAllOptions(WebDriver driver, WebElement wDropdown)
 {   
  List<String> Option = new ArrayList<String>(); 
  
  try
  {
   Select Dropdown = new Select(wDropdown);
   
   List<WebElement> temp = Dropdown.getOptions();
   
   for(int i=0;i<temp.size(); i++)
   {
    Option.add(temp.get(i).getText());
   }
   
  }
  catch(Exception E)
  {
   System.out.println("Error in getting options from dropdown");   
  }  
  return Option;
 } 
}

Thursday, 22 February 2018

Take Screenshot in Selenium

Take screenshot in selenium is very important for test result and bug verification.

It is very simple to take screen shot at particular moment like error page, defect etc.

First of all you have import below packages into your code.

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;

Now you have to create below function for take screen shot.

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;


public class TakeScreenshot
{
 public static void mTakeScreenShot(WebDriver driver, String vFileName)
 {
  try
  {
   TakesScreenshot screenShot = ((TakesScreenshot)driver);
   File srcFile = screenShot.getScreenshotAs(OutputType.FILE);
   FileUtils.copyFile(srcFile, new File("lib\\TestResult\\" + vFileName + ".png"));
   
  }
  catch(Exception E)
  {
   System.out.println("Error in take screen shot");
  }
 }

}

For highlighted part, you have to specify path to where you want to save screenshot.

Please share your inputs for this post.

How to write data into Text file in Selenium

Write data to any external source in selenium is very important when we are working with framework.
Data can be write in any format like excel, csv, text etc.


first of all you have to import below packages for apache poi.

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

Now you need to create separate function for write data into text. If file is not there at specific path then code will create first file the write data into it.



public void mWriteDataInText(String vFilePath, String[][] vData, Boolean append)

 {
  try

  {

   File file = new File(vFilePath);
  
   if(!file.exists())
   {

    file.createNewFile();

   }
   
   FileWriter fw = new FileWriter(file.getAbsolutePath(), append);

   BufferedWriter bw = new BufferedWriter(fw);

   bw.newLine();   

   for(int i=0;i<vData.length;i++)
   {

    bw.newLine();

    for(int j=0;j<vData[0].length; j++)

    {     

     bw.write(vData[i][j]);

     bw.write(" : ");     

    }       

   }

   bw.close();   

  }

  catch(Exception E)

  {

   System.out.println("Error in write data into text file.");

  }

 }
Please add comment if you have any question regarding this post.

Wednesday, 21 February 2018

How to write data into Excel in Selenium

Write data to any external source in selenium is very important when we are working with framework.
Data can be write in any format like excel, csv, text etc.

There are many methods for write data into excel files. easiest way to read data from excel file is using apache poi.

first of all you have to import below packages for apache poi.

import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

Now you need to create separate function for write data into excel. I have created below two functions for writing data into excel file.
First function is use for write whole table (two dimensional array) into excel.
Second function is use for write single row into excel.

Both functions can be used for write data into excel at the end of file. If file is not there at specific path then code will create first file the write data into it.

First function : 

public void mWriteDataInExcel(String vXlPath, String vSheetName, String[][] vData)
 {    
  try
  {
   File XLfile = new File(vXlPath);
   
   if(!XLfile.exists())
   {
    XLfile.createNewFile();
    FileOutputStream vOutputStream = new FileOutputStream(XLfile);
    XSSFWorkbook vWb = new XSSFWorkbook();
    XSSFSheet vSheet = vWb.createSheet(vSheetName);   
    vWb.write(vOutputStream);
    vOutputStream.close();
   }
   
   FileInputStream vInputStream = new FileInputStream(XLfile);   
   XSSFWorkbook vWorkbook = new XSSFWorkbook(vInputStream);
      
   XSSFSheet vSheet = vWorkbook.getSheetAt(0);
   Boolean bSheet = false;
      
   if(vWorkbook.getNumberOfSheets() != 0)
   {
    for(int i=0; i<vWorkbook.getNumberOfSheets(); i++)
    {
     if(vWorkbook.getSheetName(i).equals(vSheetName))
     {
      System.out.println(vSheetName + " is exists. No need to create sheet.");
      bSheet = true;      
     }     
    }
    
    if(bSheet)
    {
     vSheet = vWorkbook.getSheet(vSheetName);
    }
    else
    {
     vSheet = vWorkbook.createSheet(vSheetName);
    }
   }
   else
   {
    vSheet = vWorkbook.createSheet(vSheetName);
   }
      
   // Get the current count of rows in excel file   
   int vRowCount = 0;      
   
   if(vSheet.getLastRowNum()==0)
   {
    vRowCount = vSheet.getLastRowNum();
    System.out.println("Before add Row Number : "+vSheet.getLastRowNum());
   }
   else
   {
    vRowCount = vSheet.getLastRowNum()+1;
    System.out.println("After add Row Count : "+vRowCount);
   }
   
   for(int i=0;i<vData.length;i++)
   {       
    // Create a new row and append it at last of sheet
    Row vNewRow = vSheet.createRow(vRowCount++);
    for(int j=0;j<vData[0].length;j++)
    {
     Cell vCell2 = vNewRow.createCell(j);
     vCell2.setCellValue(vData[i][j]);
     System.out.println(vCell2);
    }    
   }   
   System.out.println("After add Row Count : "+(vSheet.getLastRowNum() + 1));
   
   vInputStream.close();
   
   FileOutputStream vOutputStream = new FileOutputStream(XLfile);   
   vWorkbook.write(vOutputStream);   
   vOutputStream.close();     
   
  }
  catch(Exception E)
  {
   System.out.println("Error in write data into excel file.");
   System.out.println(E.getMessage());
  }
     
 }



Second Function :

public void mWriteDataInExcel(String vXlPath, String vSheetName, String[] vData)
 {  
  try
  {
   File XLfile = new File(vXlPath);
   
   if(!XLfile.exists())
   {
    XLfile.createNewFile();
    FileOutputStream vOutputStream = new FileOutputStream(XLfile);
    XSSFWorkbook vWb = new XSSFWorkbook();
    XSSFSheet vSheet = vWb.createSheet(vSheetName);   
    vWb.write(vOutputStream);
    vOutputStream.close();
   }
   
   FileInputStream vInputStream = new FileInputStream(XLfile);   
   XSSFWorkbook vWorkbook = new XSSFWorkbook(vInputStream);
      
   XSSFSheet vSheet = vWorkbook.getSheetAt(0);
   Boolean bSheet = false;
      
   if(vWorkbook.getNumberOfSheets() != 0)
   {
    for(int i=0; i<vWorkbook.getNumberOfSheets(); i++)
    {
     if(vWorkbook.getSheetName(i).equals(vSheetName))
     {
      System.out.println(vSheetName + " is exists. No need to create sheet.");
      bSheet = true;      
     }     
    }
    
    if(bSheet)
    {
     vSheet = vWorkbook.getSheet(vSheetName);
    }
    else
    {
     System.out.println(vSheetName + " is not exists. So need to first create sheet.");
     vSheet = vWorkbook.createSheet(vSheetName);
    }
   }
   else
   {
    System.out.println(vSheetName + " is not exists. So need to first create sheet.");
    vSheet = vWorkbook.createSheet(vSheetName);
   }
   
   // Get the current count of rows in excel file   
   int vRowCount = 0;   
   
   if(vSheet.getLastRowNum()==0)
   {
    vRowCount = vSheet.getLastRowNum();
    System.out.println("Before add Row Count : "+vSheet.getLastRowNum());
   }
   else
   {
    vRowCount = vSheet.getLastRowNum()+1;
    System.out.println("Before add Row Count : "+vRowCount);
   }   
   
   Row vNewRow = vSheet.createRow(vRowCount);
   
   for(int i=0;i<vData.length;i++)
   {    
    Cell vCell2 = vNewRow.createCell(i);
    vCell2.setCellValue(vData[i]);
    System.out.println(vCell2);    
   }   
   System.out.println("After add Row Count : "+(vSheet.getLastRowNum() + 1));
   
   vInputStream.close();
   
   FileOutputStream vOutputStream = new FileOutputStream(XLfile);   
   vWorkbook.write(vOutputStream);   
   vOutputStream.close();     
   
  }
  catch(Exception E)
  {
   System.out.println("Error in write data into excel file.");
   System.out.println(E.getMessage());
  }
 }


Please add comment if you have any question regarding this post.

Popular