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 in Selenium by anonymous
38 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 by Abha
• 24,740 points

Related Questions In Selenium

+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,650 points
7,553 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,090 points
762 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,650 points
301 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,130 points
1,004 views
0 votes
2 answers
0 votes
1 answer