Selenium Beginner- passing data from one class to another


Here is my objective.
Fetch the data from an excel sheet and pass the value to another class.
I have successfully created one class to fetch the values from excel sheet, below is the code and it is working fine.
import org.apache.poi.hssf.usermodel.*;
public class ReadExce{
 public static void main(String[] args) {
 try {
  FileInputStream file = new FileInputStream(new File(“C:\\Users\\USER\\workspace\\Test1\\src\\testdata.xls”));
  HSSFWorkbook workbook = new HSSFWorkbook(file);
  HSSFSheet sheet = workbook.getSheetAt(0);
  String heading = sheet.getRow(0).getCell(0).getStringCellValue();
  String username = sheet.getRow(1).getCell(0).getStringCellValue();
  String password = sheet.getRow(2).getCell(0).getStringCellValue();
  System.out.println(“Heading is:” + heading);
  System.out.println(“username is:” + username);
  System.out.println(“password is:” + password);
 } catch (FileNotFoundException fnfe) {
 } catch (IOException ioe) {
I have created another class to open gmail. The user name and password should be returned from the class ReadExce. PFB the code
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import JavaPrograms.ReadExce;
public class openGoogle {
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver = new InternetExplorerDriver();
I am geting error message in username and password(underlined). can anyone please help me to resolve this. The user name and password are not coming to openGoogle even after importing ReadExce.
GB11 Default Asked on July 12, 2015 in Selenium WebDriver.
Add Comment
2 Answer(s)

openGoogle class doesn’t access to properties.
You should to declare they before main method with access level public like:

public class ReadExce{

public String heading;
public  String username;
public  String password;
 public static void main(String[] args) {

heading = sheet.getRow(0).getCell(0).getStringCellValue();
username = sheet.getRow(1).getCell(0).getStringCellValue();
password = sheet.getRow(2).getCell(0).getStringCellValue();


victor Reviewer Answered on July 13, 2015.
Add Comment

Thank  you!!

GB11 Default Answered on July 13, 2015.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.