java - Unable to return the read the values present in an excel file -
i want return values present in excel file returning values [[ljava.lang.string;@490ab905. data not returning values user name. used jxl , data provider. not aware of data provider much. please me fetch accurate values excel.
following code:
public class excelutil { // public string suitefilename = "/suite.xls"; string testdatafile = "/src/testdata/testdata.xls"; // public string testdatafile = "/testdata/testdata.xls"; @dataprovider public object[][] gettestdata(string sheetname) { //string gettestdata(string sheetname, int rownumber, int colnum) { // read excel string path = system.getproperty("user.dir") + testdatafile; workbook w = null; file inputworkbook = new file(path); // open workbook try { w = workbook.getworkbook(inputworkbook); } catch (biffexception | ioexception e) { // todo auto-generated catch block e.printstacktrace(); } // first sheet sheet sheet = w.getsheet(sheetname); //loop on first 10 column , lines // first sheet //loop on first 10 column , lines int rowcount = sheet.getrows(); int coulumncount = sheet.getcolumns(); object[][] data = new string[rowcount-1][coulumncount]; for(int i=1;i<rowcount;i++) { cell cell = sheet.getcell(0, i); string value = cell.getcontents().tostring(); system.out.println(value); data[i-1][0]= value.tostring(); system.out.println(data[i-1][0]); cell = sheet.getcell(1, i); value = cell.getcontents().tostring(); data[i-1][1]= value.tostring(); } w.close(); //system.out.println(value); system.out.println(data); return data; } public static webdriver driver ; @test(dataprovider = "gettestdata") public void orpaklogintest(object username, object password) { driver = new firefoxdriver(); driver.get("http:orpakqa.commdel.com"); driver.manage().window().maximize(); driver.manage().timeouts().implicitlywait(20, timeunit.seconds); loginelements lg = new loginelements(); webelement element_username = lg.getorpakusernamefield(driver); element_username.sendkeys(username.tostring()); webelement element_password = lg.getorpakpasswordfield(driver); element_password.sendkeys(password.tostring()); //webelement element_loginbtn = lg.getorpakloginbutton(driver); //element_loginbtn.click(); }
use poi jars
https://poi.apache.org/download.html
below code working me:-
public string getxlcellvalue(string xlpath, string sheetname, int rownum, int cellnum) { try{ fileinputstream fis=new fileinputstream(xlpath); workbook wb=workbookfactory.create(fis); log.info("get value cell(getxlcellvalue)"); return wb.getsheet(sheetname).getrow(rownum).getcell(cellnum).getstringcellvalue(); } catch(exception ex) { log.info("error in getxlcellvalue ="+ ex.getmessage()); } return ""; }
xlpath = path of excel file in system
sheetname = name of sheet in excel file
row = row number of username or password
cellnum = cell number of username or password
Comments
Post a Comment