How to pass data stored in excel sheet as parameters under @Parameter in junit selenium?

109
June 19, 2017, at 02:22 AM

I have around 10 userIds which are pure numbers stored in a excel sheet and am using getUserIds() method to read input file. I want to pass them as Parameters under @Parameters instead of passing individual user ids which also i've tried but commented below. And those user ids have to passed for same testMethod(). Can anyone help me here?

@RunWith(Parameterized.class)
public class PlansClass{
private String userId;
static File file = new File("url.xlsx");
@Parameters
public static Collection<Object> testData() throws Exception {
    return Arrays.asList(ReadExcel.getUserIds(file));
    //return Arrays.
}
/*@Parameters
public static Collection<Object> testData(){
    return Arrays.asList(111, 222);
}*/
public PlansClass(String userID) {
  this.userID= userID;
}

@Before
public void before() throws Exception {
    MainApp main= new MainApp(driver, "http://launchUrl");
    main.launch();
    main.login("q12345", "Selenium");
        //for (String clientID : ReadExcel.getClientIds(file)) {
            int clientData = Integer.parseInt(userId);
            main.searchClient(clientData);
            main.launchApplication("Web Application");
            main.switchToApplication();
        }

@Test
public void testMethod(){
try {
    List<String> userNameList = new ArrayList<String>();
    userNameList = baseApp.getUserName();
    System.out.println(userNameList );
} catch (Exception e) {
    e.printStackTrace();
}
}

public class ReadExcel{
public static List<String> getUserIds(File file) throws IOException{
List<String> userIdList = new ArrayList<String>();
FileInputStream inputStream = new FileInputStream(file);
XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
XSSFSheet workSheet = workbook.getSheetAt(0);
Iterator<Row> rowIterator = workSheet.iterator();
while (rowIterator.hasNext()) {
                Row row = (Row) rowIterator.next();
                Iterator<Cell> cellIterator = ((Iterable<Cell>) row).iterator();
                while (cellIterator.hasNext()) {
                                Cell cell = cellIterator.next();
                                cell.setCellType(Cell.CELL_TYPE_STRING);
                                clientIdList.add(cell.getStringCellValue());
                }
}
return userIdList;
}
}
READ ALSO
Out Of Memory when selecting images from phone storage

Out Of Memory when selecting images from phone storage

I am creating an app in which you store information about clients in your phoneI also store bitmap locations to a database that when loaded are thumbnail size in a gridView when viewing the clients information like so

110
Always Round UP a Double

Always Round UP a Double

How could I always round UP a double to an int, and never round it downI know of Math

112
Attribute getting removed after render

Attribute getting removed after render

I am creating a maze solver with a front end solution

79
Make GridBagLayout JPanel size to contents, not container?

Make GridBagLayout JPanel size to contents, not container?

I have a GridBagLayout JPanel contained within a Box contained within a JTabbedPaneI want the GridBagLayout to size itself to its internal grid

80