-1

Here is my Code:au

package Mypackage;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.apache.xmlbeans.impl.xb.xmlconfig.ConfigDocument.Config;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

@Test(dataProvider="Rahul")
public class jh{
    WebDriver driver;
    public void loginjh(String loginId ,String password)throws InterruptedException {
    }
    {
        System.setProperty("webdriver.gecko.driver","C:\\Users\\Selenium2017\\geckodriver.exe");
        WebDriver driver = new FirefoxDriver();
        driver.get("URL");
         driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
         driver.findElement(By.name("loginId")).sendKeys("loginId");
         driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
         driver.findElement(By.name("password")).sendKeys("password");
         driver.findElement(By.name("btnSubmit")).click();
         driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }

    @AfterMethod
    public void tearDown()
    {
        driver.quit();
    }


@DataProvider(name="Rahul")
public Object[][] TestData()

***Excel Dataconfig config = new Excel Dataconfig("Excel Path");

int rows = Config.getRowcount(0);

Object[][] data = new Object [rows][2];
for(int i=o;i<rows;i++)
{
    data[i][0]=config.getData(0,i,0);
    data[i][1]=config.getData(0,i,1);
}
return data;
5
  • Can you please explain this line ? ` ***Excel Dataconfig config = new Excel Dataconfig("Excel Path");`
    – Sagar007
    Feb 5, 2018 at 8:06
  • i want to read data from excel file
    – Rahul
    Feb 5, 2018 at 8:27
  • 1
    But as per my knowledge. Java do not allow this syntax . Please check your code. Also send me the link that you follow for read excel file.
    – Sagar007
    Feb 5, 2018 at 10:11
  • Your syntax is wrong. Fix it and get back with the issues if any.
    – Alexey R.
    Feb 5, 2018 at 12:27
  • Please paste you error/exception completely overhere first. Then only once can answer after seeing the root cause Jul 9, 2018 at 11:09

2 Answers 2

0

You start and closed your loginjhmethod. At TestData method you don't have any parenthesis and no entry data (empty at quotation marks)

0

Use this following code for reading the values from Excel sheet:

@DataProvider(name = “Rahul”)

public Object[][] readExcel(String sheetName) throws InvalidFormatException, IOException {

//Load the Excel File

File src = new File(“./data/”+sheetName+”.xlsx”);

//Open the Book

XSSFWorkbook wb = new XSSFWorkbook(src);

//Go to Sheet

XSSFSheet sheet = wb.getSheet(“Sheet1”);

//Row Count

int rowCount = sheet.getLastRowNum();

System.out.println(rowCount);

//Column Count

int column = sheet.getRow(0).getLastCellNum();

System.out.println(column);

Object[][] data = new Object[rowCount][column];

// Row – for

for (int i = 1; i <=rowCount; i++) {

XSSFRow row = sheet.getRow(i);

//Column – for

for (int j = 0; j < column; j++) {

XSSFCell cell = row.getCell(j);

System.out.println(cell.getStringCellValue());

data[i-1][j] = cell.getStringCellValue();

}

}

return data;

}

}

Your Answer

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

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