I was trying to implement the DriverScript-class as mentioned in the below-link, but, it seems that the non-default DriverScript()-constructor is not getting called. As a result all the codes (shown below) are not getting executed. That's why I’m getting a “NullPointerException” whenever referring the “method” (of type Method[]) variable afterwards in the class.
public DriverScript() throws NoSuchMethodException, SecurityException {
actionKeywords = new ActionKeywords();
method = actionKeywords.getClass().getMethods();
}
Reference Link: http://toolsqa.com/selenium-webdriver/keyword-driven-framework/set-up-java-constant-variables/
Here is my DriverScript.class for reference:
package executionEngine;
import java.lang.reflect.Method;
import config.ActionKeywords;
import utility.ExcelUtils;
public class DriverScript {
public static ActionKeywords actKeyObj;
public static String stepActionKey;
public static Method method[];
public DriverScript() throws NoSuchMethodException, SecurityException {
actKeyObj = new ActionKeywords();
method = actKeyObj.getClass().getMethods();
//System.out.println(“Hello”);
}
public static void main(String[] args) throws Exception {
String spreadSheetPath = “C:\\Users\\demo\\Desktop\\Workspace\\Mydemo2\\src\\dataEngine\\DataEngine.xlsx”;
ExcelUtils.setExcelFile(spreadSheetPath, “Test Steps”);
for(int row=1; row<9; row++) {
stepActionKey = ExcelUtils.getCellData(row, 3);
//System.out.println(stepActionKey);
execute_Step();
}
}
private static void execute_Step() throws Exception {
//System.out.println(method.length);
for(int i=0; i<method.length; i++) {
if(method[i].getName().equals(stepActionKey)) {
method[i].invoke(actKeyObj);
break;
}
}
}
}
Please help/suggest me on this issue.
Aucun commentaire:
Enregistrer un commentaire