How can we read Numeric and String and date format in Excelsheet by using single program

0 votes

HI in this i just created ExcelLibrary and featched this in TestScript1  

but i am unable to fetch numbers and date format   i want the same type of code to fetch all the dat numbers,String values and date formats please help me out 

public class ExcelLibrary

{

public static int readData(String sheetName,int rowNum,int cellNum) 

{

try

{

String path = "E:\\WorkSpace\\GoogleFrameWork\\data\\Inputdata.xlsx";

FileInputStream fis = new FileInputStream(path);

Workbook w1 = WorkbookFactory.create(fis);

int data = (int)w1.getSheet(sheetName).getRow(rowNum).getCell(cellNum).getNumericCellValue();

return data;

}

catch(Exception rv)

{

return 0;

}

}

public static void writeData(int sheetName,int rowNum,int cellNum,String data)

{

try

{

String path = "E:\\WorkSpace\\GoogleFrameWork\\data\\Inputdata.xlsx";

FileInputStream fis = new FileInputStream(path);

Workbook w1 = WorkbookFactory.create(fis);

w1.getSheetAt(sheetName).getRow(rowNum).createCell(cellNum).setCellValue(data);

}

catch(Exception rv)

{

}

}

}

---------------------------------------------------------------------------------------------------------------------------------------------------

package com.Google.common_library;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.ie.InternetExplorerDriver;

import org.testng.annotations.AfterMethod;

import org.testng.annotations.BeforeMethod;

import com.Google.common_library.ExcelLibrary;

public class SuperTestScript 

{

public static WebDriver driver = null;

@BeforeMethod

public void preConfig()

{

        //WebDriver driver= new FirefoxDriver();

//driver.get("https://accounts.google.com/");

String browser = ExcelLibrary.readData("config", 1, 0);

String buildUrl = ExcelLibrary.readData("config", 1, 1);

//fetching the browser from Excel

if(browser.equals("FF"))

{

driver = new FirefoxDriver();

}

else if(browser.equals("GC"))

{

driver = new ChromeDriver();

}

else

{

driver = new InternetExplorerDriver();

}

driver.get(buildUrl);

driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

}

@AfterMethod

public void postConfig()

{

driver.close();

}

}

------=====================================================--------------------------

package com.actitime.project_and_tasks_test_scripts;

import org.testng.annotations.Test;

import com.actitime.common_library.ExcelLibrary;

import com.actitime.common_library.SuperTestScript;

import com.Google.webpages.LoginPage;

public class TestScript1 extends SuperTestScript

{

@Test

public void testLogin()

{

String un = ExcelLibrary.readData("ValidData", 1, 0);

String pwd = ExcelLibrary.readData("ValidData", 1, 1);

LoginPage lp = new LoginPage();

lp.enterUsername(un);

lp.enterPassword(pwd);

lp.clickOnLogin();

}

}

Sep 6, 2019 in Selenium by anonymous
93 views

1 answer to this question.

0 votes

Hey, I have gone through your code. So while reading the data from excel sheet, instead of creating your own library, its better to use Apache POI. Apache POI provides different methods for different type of data fetching while reading an excel workbook.

If you want to fetch String data, you can use getStringCellValue() method and for numeric data you can use getNumericCellValue() method.

answered Sep 6, 2019 by Abha
• 27,800 points

Related Questions In Selenium

0 votes
1 answer
+3 votes
1 answer

How to read excel file numeric data of all rows and column in selenium? I have 10 rows and 5 column but I read Only String value not a Numeric value?

Hey, @Mahendra, check this thread https://www.edureka.co/community/52170/read-numeric-data-from-excel-sheet-using-selenium-webdriver It deals with ...READ MORE

answered Jan 27 in Selenium by Sirajul
• 50,480 points
199 views
+2 votes
1 answer

How can we handle authentication popup in Selenium WebDriver using Java

The Alert Method, authenticateUsing() lets us skip ...READ MORE

answered Apr 18, 2018 in Selenium by king_kenny
• 3,710 points
13,142 views
0 votes
1 answer
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,510 points
2,207 views
0 votes
1 answer
0 votes
1 answer

What is the role of TestNG & JUnit frameworks in Selenium?

Well TestNG and JUnit are test frameworks ...READ MORE

answered Apr 18, 2018 in Selenium by king_kenny
• 3,710 points
569 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,870 points
1,820 views
0 votes
2 answers

How can we take screenshots of tests in Selenium 2 using C#

Hey, try using following code command to ...READ MORE

answered Aug 22, 2019 in Selenium by Abha
• 27,800 points
246 views
0 votes
1 answer

How can we read data from an excel sheet in Selenium webdriver?

Hi Tarun, to read data from an ...READ MORE

answered May 8, 2019 in Selenium by Abha
• 27,800 points
6,968 views