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
3,238 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
• 28,140 points

Related Questions In Selenium

+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, 2020 in Selenium by Sirajul
• 59,230 points
1,806 views
+2 votes
3 answers

How can we handle authentication popup in Selenium WebDriver using Java

1) By passing user credentials in URL. String ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
28,410 views
0 votes
1 answer

How can I travel forward and back in a browser using selenium?

You can use the Navigate interface to ...READ MORE

answered Dec 31, 2018 in Selenium by Nabarupa
11,916 views
0 votes
2 answers

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,500 points
12,718 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,612 views
0 votes
2 answers

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

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

answered Sep 4, 2020 in Selenium by Sri
• 3,190 points
2,515 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,910 points
6,685 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 23, 2019 in Selenium by Abha
• 28,140 points
998 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
• 28,140 points
17,195 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP