0

I am keeping my data in excel file and read the data from there, because of avoid hard code..

Page

public void fielding(String field,String dist,String velo,String diff) {
  enterFielding.sendKeys(field);
  saveButton.click();
  textDistance.sendKeys(dist);
  dropDown.click();
  driver.findElement(By.name(velo)).click();
  textDifficulty.sendKeys(diff);
  buttonUpdate.click();
}

public void popOuttop2(String field,String dist,String velo,String diff) {
 //BH
 buttonB.click();
 buttonH.click();
 popOutButton.click();
 fielding(field,dist,velo,diff);
 buttonUpdate.click();
}

Steps

public class BaseBallEventSteps {

    WebDriver driver;
    BaseBallOutEvents baseOut;
    public BaseBallEventSteps() {
        baseOut = new BaseBallOutEvents(driver);
        baseOut=  PageFactory.initElements(DriverManager.driver, BaseBallOutEvents.class);
    }

    public void firstInningTopOut1(String field,String dist,String velo,String diff) throws InterruptedException 
    {
        baseOut.strikeOuttop1();
        baseOut.popOuttop2(field, dist, velo, diff);
        baseOut.strikeOutTop3();
    }
}

Main method

public static void main(String[] args) throws InterruptedException, IOException {


 DriverManager manager=new DriverManager();

 BaseBallEventSteps bs=new BaseBallEventSteps();

 File f= new File("Player_names.xlsx");
 FileInputStream fs= new FileInputStream(f);
 XSSFWorkbook wb= new XSSFWorkbook(fs); 
 XSSFSheet bb_players=  wb.getSheet("Sheet2");
 int rowcount= bb_players.getLastRowNum();

 String field =  bb_players.getRow(1).getCell(1).getStringCellValue();
 String dist= bb_players.getRow(1).getCell(2).getStringCellValue();
 String velo=bb_players.getRow(1).getCell(3).getStringCellValue();
 String diff=bb_players.getRow(1).getCell(4).getStringCellValue();

 bs.firstInningTopOut1(field,dist,velo,diff);
}

enter image description here

I want to know that I am doing correct or not ? My data from excel is not reading in the main class... Error :

Exception in thread "main" java.lang.IllegalStateException: Cannot get a text value from a numeric cell

every time that i need to write the same String field = bb_players.getRow(1).getCell(1).toString(); to read the value from each cell.. but the length of the code should be more and is that every one following ?

Anybody please review my code , that i am doing correct or not, i can go further ?

1
  • For what it's worth, this is one reason I keep my locators inside the page object classes themselves - they are the only classes that need to know the locators, why add another layer of complexity in having to read in tables from other files? Commented Jun 7, 2018 at 14:54

1 Answer 1

3

For me the problem seems to be in the type of the values you are trying to use. The cell probably contains a number type and you are expecting a String in your code. I would suggest one of the following:

  • change the excel cell's type to text
  • instead of getStringCellValue() try getIntegerCellValue() or a similar method
  • use the toString() method
2
  • thanks for the support, that toString works fine for me... but let me know that I am doing correct or not..any changes should I need for my code improvement or i can go further ?
    – user32519
    Commented Jun 8, 2018 at 4:46
  • 1
    you're welcome :) you know, code improvement depends on the size and duration of the project. If this is just a random homework or a two weeks project, nobody cares so much about the code quality. But if you'll working on this for 2 years, I suggest to be as modular as you can, to separate many things in wrapping classes. Good luck, man!
    – MMMM
    Commented Jun 8, 2018 at 6:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.