RE: Null Pointer exception in Keyword Driven Framework

hi Lakshay & Team,

Thanks for this wonderful site, Like me, you are helping lot of people out there. God bless you all.

I am getting same error, after debugging , error throws in execute_Actions() method, as you told sActionKeyword, it has a value openBrowser but when it enters the execute_Action method Method method.length will be null.

This the code

 

package executionEngine;
import java.lang.reflect.Method;

import config.ActionKeywords;

import utility.ExcelUtils;
public class DriverScript {
public static ActionKeywords actionKeywords;

public static String sActionKeyword;

public static Method method[];
public DriverScript() throws NoSuchMethodException, SecurityException{

actionKeywords = new ActionKeywords();

method = actionKeywords.getClass().getMethods();

}

public static void main(String[] args) throws Exception {

String sPath = “..\\src\\dataEngine\\DataEngine.xlsx”;

ExcelUtils.setExcelFile(sPath, “Test Steps”);

for (int iRow=1; iRow<=9; iRow++){

sActionKeyword = ExcelUtils.getCellData(iRow, 3);

execute_Actions();

}

}
private static void execute_Actions() throws Exception {

for (int i=0; i<method.length;i++){

if (method[i].getName().equals(sActionKeyword)){

method[i].invoke(actionKeywords);

break;

}

}

}

}
Add Comment
5 Answers

Hi Kiran,

Use a break opint at this code:
       actionKeywords = new ActionKeywords();
      method = actionKeywords.getClass().getMethods();

See if the method value is null or not, if it is null it means some problem in actionKeywords class. Frankly speaking code looks fine to me and it is hard to investigate like this without debugging on your system. I should suggest you to take any dev help from your project, I am sure they would be able to give you the root cause.

Regards,
Lakshay Sharma

Professor Answered on November 7, 2014.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.