POM -Data Driven Framework | Selenium Forum
M
Posted on 11/04/2016
Hello Sir,
Can you please explain me following code. I am having difficulty in understanding following code. Mainly the part highlighted in bold letters.
why we wrote 'rowNum-datastartIndex' when putting data in table ???


[b:29g36h26]
Object[][] data = new Object[row][1];[/b:29g36h26]
Hashtable<String, String> table = null;
for (int rowNum = datastartIndex; rowNum < (datastartIndex + row); rowNum++) {
table = new Hashtable<String, String>();
for (int cNum = 0; cNum < cols; cNum++) {
table.put(xls.getCellData("Test Data", cNum, colstartIndex),
xls.getCellData("Test Data", cNum, rowNum));
System.out.println(xls.getCellData("Test Data", cNum, colstartIndex)+" --- "+
xls.getCellData("Test Data", cNum, rowNum));
}
System.out.println();
[b:29g36h26]data[rowNum-datastartIndex][0]=table;[/b:29g36h26]
}

M
Replied on 11/04/2016

where did you pick this code up?


M
Replied on 11/04/2016

Module no. 39
part 9 --> Data driven framework.....for login,change pic,find a friend...
so that code is just a part of it. I understood how we should get the test case start index,no. of cols,no. of rows. but this part when we put the data in object array i did not understood ...
I have indicated the things in bold letters.


M
Replied on 12/04/2016

execute this and send me a screen shot.

[quote:a0rifddi][b:a0rifddi]System.out.println(row);[/b:a0rifddi]
Object[][] data = new Object[row][1];
Hashtable<String, String> table = null;
for (int rowNum = datastartIndex; rowNum < (datastartIndex + row); rowNum++) {
table = new Hashtable<String, String>();
for (int cNum = 0; cNum < cols; cNum++) {
table.put(xls.getCellData("Test Data", cNum, colstartIndex),
xls.getCellData("Test Data", cNum, rowNum));
System.out.println(xls.getCellData("Test Data", cNum, colstartIndex)+" --- "+
xls.getCellData("Test Data", cNum, rowNum));
}
[b:a0rifddi]System.out.println(datastartIndex);
System.out.println(rowNum);
System.out.println(rowNum-datastartIndex);
[/b:a0rifddi]data[rowNum-datastartIndex][0]=table;
}
[/quote:a0rifddi]


M
Replied on 12/04/2016

I understood the code ,following is the console.
Well thank you for help.
Kindly find the screenshot with the reply....
(rowNum - datastartIndex)--> this I was not understanding mainly.....
Thank u, Thanks alot.


*************
Test Case Index is : 1
No. of Cols are : 4
No. of Rows are : 4
ROW: 4
Runmode --- Y --- Username --- its.thakur@gmail.com --- Password --- affirm123 --- Flag --- Y ---
DATASINDEX: 3
ROWNUM: 3
RN-DSI: 0
Runmode --- Y --- Username --- abc@rediff.com --- Password --- xyz --- Flag --- N ---
DATASINDEX: 3
ROWNUM: 4
RN-DSI: 1
Runmode --- N --- Username --- xxxx --- Password --- yyyy --- Flag --- N ---
DATASINDEX: 3
ROWNUM: 5
RN-DSI: 2
Runmode --- N --- Username --- rrrr --- Password --- dds --- Flag --- N ---
DATASINDEX: 3
ROWNUM: 6
RN-DSI: 3
*************
Test Case Index is : 8
No. of Cols are : 2
No. of Rows are : 2
ROW: 2
Rumode --- Y --- Pic_Location --- C:\\abc.jpg ---
DATASINDEX: 10
ROWNUM: 10
RN-DSI: 0
Rumode --- N --- Pic_Location --- C:\\xyz.jpg ---
DATASINDEX: 10
ROWNUM: 11
RN-DSI: 1
*************
Test Case Index is : 13
No. of Cols are : 2
No. of Rows are : 3
ROW: 3
Runmode --- Y --- Friend_Name --- Vishnu Prabhakar ---
DATASINDEX: 15
ROWNUM: 15
RN-DSI: 0
Runmode --- N --- Friend_Name --- Annie ---
DATASINDEX: 15
ROWNUM: 16
RN-DSI: 1
Runmode --- N --- Friend_Name --- Rakesh ---
DATASINDEX: 15
ROWNUM: 17
RN-DSI: 2

Responsive image