After creatin TestBase class is readin wrong data from xls | Selenium Forum
M
Posted on 24/02/2016
Sir i implemented TestBase class..

Incorrect data being used in testexecution.

PLease refer attachment. As there are too many classes ..am not able to figure out what went wrong..
PLease help....

Follwing is the test result:
PASSED: test1({RunMode=Y, pwd=nnn, username=chaitra.jagirdar7@gmail.com, Result=NA})
PASSED: test1({RunMode=Y, pwd=nnn, username=chaitra.jagirdar7@gmail.com, Result=NA})


Expected was :
As per SuiteA>data sheet[attachment]

M
Replied on 24/02/2016

contents of X [in utility class]

holds correct content sir...
contents of array X:row A{RunMode=Y, pwd=ui, username=chaitra108@gmail.com, Result=NA}
contents of array X:row A{RunMode=Y, pwd=nnn, username=chaitra.jagirdar7@gmail.com, Result=NA}

But something is wrong in @Test(dataProvider="callingReadData")
public void test1(Hashtable <String,String> table12){


}


M
Replied on 24/02/2016

what is th problem you're having?


M
Replied on 24/02/2016

Testdata at dataprovider is repeated...

Row0 data from xls is not sent instead, Row1 is sent twice


M
Replied on 25/02/2016

try adding more rows and tell me what you're getting then.


M
Replied on 25/02/2016

Added another row to test:
data of last row is sent 3 times to data provider ReadDataCalling().


M
Replied on 25/02/2016

give me sometime.


M
Replied on 25/02/2016

try to replace your function with this.


[code:ew312su1]public static Object[][] ReadData(String SheetName, Xls_Reader Read1) {
String TestName = "Test1";
String DataAtCol1;
String DataAtCol2;
int DataStartRowNum;
Object[][] Param = null;

Object[][] X = null;
Hashtable<String, String> H = new Hashtable<String, String>();
int TotalNumRows = Read1.getRowCount(SheetName);
System.out.println("TotalNumRows" + TotalNumRows);

// int DataStartRowNum=TestRowNUm+2;
// int ColHeader=TestRowNUm+1;

for (int TestRowNUm = 1; TestRowNUm <= TotalNumRows; TestRowNUm++) {
DataStartRowNum = TestRowNUm + 2;
int ColHeader = TestRowNUm + 1;
int colNum = 0;

// System.out.println("Reading row"+TestRowNUm);
if (Read1.getCellData(SheetName, 0, TestRowNUm).equals(TestName)) {

// int TestRowNUmStart=TestRowNUm;
int rowstarts = DataStartRowNum;
System.out.println("rowstarts" + rowstarts);
// System.out.println("ColHeader"+ColHeader);
while (!(Read1.getCellData(SheetName, 0, DataStartRowNum)
.equals(""))) {
// System.out.println("Data"+Read1.getCellData(SheetName, 0,
// DataStartRowNum));
// System.out.println("inside while loop"+DataStartRowNum);
DataStartRowNum++;
}
int TestRowNUmEnd = DataStartRowNum - 1;
System.out.println("TestRowNUmEnd" + TestRowNUmEnd);
while (!(Read1.getCellData(SheetName, colNum, ColHeader)
.equals(""))) {
// System.out.println("Name of cols"+Read1.getCellData(SheetName,
// colNum, ColHeader));
colNum++;
}
int NumOfCols = colNum;
System.out.println("NumOfCols" + NumOfCols);
Param = new Object[TestRowNUmEnd - rowstarts + 1][NumOfCols];
System.out.println("Rows" + (TestRowNUmEnd - rowstarts + 1)
+ "cols" + (NumOfCols));
int rowNumArray = 0;
int NumRows = TestRowNUmEnd - rowstarts + 1;
X = new Object[NumRows][1];
for (int rownum_c = rowstarts; rownum_c <= TestRowNUmEnd; rownum_c++) {
for (int colnum_c = 0; colnum_c < NumOfCols; colnum_c++) {

Param[rowNumArray][colnum_c] = Read1.getCellData(
SheetName, colnum_c, rownum_c);
// System.out.println(Param[rowNumArray][colnum_c]);
String key = Read1.getCellData(SheetName, colnum_c,
ColHeader);
String value = Read1.getCellData(SheetName, colnum_c,
rownum_c);
System.out.println("key:" + key + "--------" + "value:"
+ value);
H.put(key, value);

}
System.out.println("------------");
// ----------------------------------------------------------------
Enumeration e = H.keys();
while (e.hasMoreElements())
System.out.println(e.nextElement());
// -----------------------------------------------------------------
X[rowNumArray][0] = H;
System.out.println("this");
System.out.println(X[0][0]);
System.out.println(X[1][0]);

rowNumArray++;
}
}
}
// print the contents of the tes1 parramaeters
return X;

}
[/code:ew312su1]


M
Replied on 26/02/2016

Sir,

still same issue occurs sir...
i get result like this:
PASSED: test1({RunMode=Y, pwd=yyyy, username=chethan, Result=NA})
PASSED: test1({RunMode=Y, pwd=yyyy, username=chethan, Result=NA})
PASSED: test1({RunMode=Y, pwd=yyyy, username=chethan, Result=NA})

The data is from last row of the xls>data sheet>Test1


M
Replied on 26/02/2016

i'm not able to run your project.


but can you please run the project that we provided you? and see if it is running fine.


M
Replied on 28/02/2016

yes sir, i imported ur project ...it works fine...

But the function to read "data" sheet from xls[SuiteA.xls] is different logic in videos...i implemented that one...
The one in code from website appears different & am not able to understand that one.....

Pls could u correct my method to read data "data" sheet from xls[SuiteA.xls]....


M
Replied on 29/02/2016

Sir,

cud u pls correct my method :
Am reading 3 rows from xls , but only last row is reaching dataprovider.This is serious trouble sir. Request you to kindly correct my method.So that i proceed with next videos..

My code in utility class to read data:
------------------------------------
public static Object[][] ReadData(String SheetName, com.qtpselenium.utility.Xls_Reader xls2) {
String TestName = "Test1";
String DataAtCol1;
String DataAtCol2;
int DataStartRowNum;
Object[][] Param = null;

Object[][] X = null;
Hashtable<String, String> H = new Hashtable<String, String>();
int TotalNumRows = xls2.getRowCount(SheetName);
System.out.println("TotalNumRows" + TotalNumRows);

// int DataStartRowNum=TestRowNUm+2;
// int ColHeader=TestRowNUm+1;

for (int TestRowNUm = 1; TestRowNUm <= TotalNumRows; TestRowNUm++) {
DataStartRowNum = TestRowNUm + 2;
int ColHeader = TestRowNUm + 1;
int colNum = 0;

// System.out.println("Reading row"+TestRowNUm);
if (xls2.getCellData(SheetName, 0, TestRowNUm).equals(TestName)) {

// int TestRowNUmStart=TestRowNUm;
int rowstarts = DataStartRowNum;
System.out.println("rowstarts" + rowstarts);
// System.out.println("ColHeader"+ColHeader);
while (!(xls2.getCellData(SheetName, 0, DataStartRowNum)
.equals(""))) {
// System.out.println("Data"+Read1.getCellData(SheetName, 0,
// DataStartRowNum));
// System.out.println("inside while loop"+DataStartRowNum);
DataStartRowNum++;
}
int TestRowNUmEnd = DataStartRowNum - 1;
System.out.println("TestRowNUmEnd" + TestRowNUmEnd);
while (!(xls2.getCellData(SheetName, colNum, ColHeader)
.equals(""))) {
// System.out.println("Name of cols"+Read1.getCellData(SheetName,
// colNum, ColHeader));
colNum++;
}
int NumOfCols = colNum;
System.out.println("NumOfCols" + NumOfCols);
Param = new Object[TestRowNUmEnd - rowstarts + 1][NumOfCols];
System.out.println("Rows" + (TestRowNUmEnd - rowstarts + 1)
+ "cols" + (NumOfCols));
int rowNumArray = 0;
int NumRows = TestRowNUmEnd - rowstarts + 1;
X = new Object[NumRows][1];
for (int rownum_c = rowstarts; rownum_c <= TestRowNUmEnd; rownum_c++) {
for (int colnum_c = 0; colnum_c < NumOfCols; colnum_c++) {

Param[rowNumArray][colnum_c] = xls2.getCellData(
SheetName, colnum_c, rownum_c);
// System.out.println(Param[rowNumArray][colnum_c]);
String key = xls2.getCellData(SheetName, colnum_c,
ColHeader);
String value = xls2.getCellData(SheetName, colnum_c,
rownum_c);
//------------Seeing contents of hashtable .....bfore i move it to array
System.out.println("key:" + key + "--------" + "value:"
+ value);
H.put(key, value);

}
System.out.println("------------");
// ----------------------------------------------------------------
Enumeration e = H.keys();
while (e.hasMoreElements())
System.out.println(e.nextElement());
// -----------------------------------------------------------------
X[rowNumArray][0] = H;
System.out.println("print contents of array x before sending it to data provider");
System.out.println(X[0][0]);
System.out.println(X[1][0]);

rowNumArray++;
}
}
}
// sending x to dataprovider
return X;

}


M
Replied on 01/03/2016

you can download the code from the website.

use core_webdriver framework