Training Video 6 - Reflections API | Selenium Forum
M
Posted on 25/05/2016
We will use Reflections API to develop keyword driven framework. The keyword will be read into a variable from the xls file. Which means there will one method per keyword.

In the main function, we will have for loop which will read 1 keyword at a time.So as soon it reads the keyword with variable x,the function corresponding to that x will be called. I understood this concept as in video String x="SampleTest"; is given and then we called SampleTest method using Reflections API.

My question is :- If suppose there are 100 keywords in xls file, then do we need to declare 100 variables for it so that using for loop we will iterate through each variable and read those keywords into each variable. I mean how exactly this reading of 100 or 300 keywords will be done using for loop? I mean how exactly keywords will be read into variable when there are so many? \

Thanks
Sankalp

M
Replied on 26/05/2016

xls_reader.java will help you read the keywords from xlsx file


M
Replied on 29/05/2016

This means the String path which is passed on constructor will be for String variable x. And after creating object of Xls_reader class we will use methods from Xls_Reader.Java to read all keywords?


M
Replied on 29/05/2016

yes.


M
Replied on 09/06/2016

I tried the following code to read Xlsx using Reflections and then call the corresponding methods :


import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;


public class Practice {

public static void main(String[] args) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Xls_Reader dbt=new Xls_Reader("D:\\testing\\Data.xlsx");
for(int i=2;i<=dbt.getRowCount("Record");i++){
for(int j=0;j<dbt.getColumnCount("Record");j++){
String a=dbt.getCellData("Record", j,i);


Method method = Practice.class.getMethod(a);
method.invoke(method);
}
}
}


public static void Sankalp(){
System.out.println("hello");

}
public static void Mumbai(){

System.out.println("hi");
}
}

Although it is calling the 2 functions defined, I am getting the following Exception :

hello
hi
Exception in thread "main" java.lang.NoSuchMethodException: Practice.()
at java.lang.Class.getMethod(Unknown Source)
at Practice.main(Practice.java:15)

Please help


M
Replied on 12/06/2016

send me data.xlsx also


M
Replied on 13/06/2016

Data.xlsx mailed to you


M
Replied on 14/06/2016

attach it here