0

Can someone help me on how to fix the error and run the script?

public class ExcelCapture {

public WebDriver driver;

String filePath = "E:\\Study\\workspace\\OCM25_26_OCE_19\\OCM25_26_OCE_19\\BlackDogFrameWork\\TestData\\Test_Data.xlsx";

@BeforeClass
public String excelFunction(String sheetName, int rowNum, int colNum) throws EncryptedDocumentException, InvalidFormatException, IOException  { 

    FileInputStream fis = new FileInputStream(filePath);
    Workbook wb = WorkbookFactory.create(fis);
    Sheet sh = wb.getSheet(sheetName);
    Row row = sh.getRow(rowNum);
    String data = row.getCell(colNum).getStringCellValue();
    return data;        
}

@Test
public void login() throws EncryptedDocumentException, InvalidFormatException, IOException 
{       driver = new FirefoxDriver();
    driver.get("http://www.gmail.com");
    String userName1 = excelFunction("datad", 1, 2);
    String passWord1 = excelFunction("datad", 1, 3);

    driver.findElement(By.id("Email")).sendKeys(userName1);
    driver.findElement(By.id("Email")).sendKeys(passWord1);     
}

Console is throwing the below error:

FAILED CONFIGURATION: @BeforeClass excelFunction org.testng.TestNGException: Method excelFunction requires 3 parameters but 0 were supplied in the @Configuration annotation.

1

The error is because excelFunction has 3 parameters and has @BerforeClass annotation, when you have parameters for function with annotation then you have to pass the parameters before annotation tags as follow.

 @Parameters({ "sheetname", "row-number", "colBNum" })
 @BeforeClass
    public String excelFunction(String sheetName, int rowNum, int colNum) throws EncryptedDocumentException, InvalidFormatException, IOException  { 

        FileInputStream fis = new FileInputStream(filePath);
        Workbook wb = WorkbookFactory.create(fis);
        Sheet sh = wb.getSheet(sheetName);

and pass parameter values from testng.xml as shown below

<suite name="Test Suite">
    <test name="Testing">
    <parameter name="sheetname" value="Your SheetName"/>
    <parameter name="row-number" value="your row number"/>
    <parameter name="colBNum" value="Your Column number"/>
        <classes>
            <class name="com.parameterization.TestParameters" />
        </classes>
    </test>
</suite>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.