Unable to read test data from excel file

2019-08-20 04:17发布

I am using POM framework and test data I kept in excel file. As per my code its reading only login email id and login password with a help of

((row.getcell(0).getstringcellvalue())),row.getcell(1).getstringcellvalue();)

but i want to read complete excel sheet without hard coding as mentioned above. Also my test data has Numerical values and this also not reading. My test data looks like,

loginusername - abc@123.com
loginpassword-xxxxxx
customer_code-123456
sfdc- aoa_1205
customer_phoneno-12345

Public static string readtestdata(string key) throws illegalargumentexception, ioexception {
            String path = system.getproperty("user.dir") + "/data/testdata.xlsx";
            Fileinputstream fs = new fileinputstream(path);
            Workbook sapworkbook = new xssfworkbook(fs);
            Sheet sapsheet = sapworkbook.getsheet("sheet1");
            Int rowcount = sapsheet.getlastrownum() - sapsheet.getfirstrownum();
            For (int i = 0; i < rowcount + 1; i++) {
                Row row = sapsheet.getrow(i);
                If (key.equals(row.getcell(0).getstringcellvalue())) {
                    Return row.getcell(1).getstringcellvalue();
                }
            }
            Throw new illegalargumentexception(string.format("%s not found!", key));
        }

Note : My current issue is i am not able to read Numerical values in excel (Test data) & also i want to read complete excel file (test data has 50 rows) i don't want to hard code it.

0条回答
登录 后发表回答