dimanche 1 mai 2016

Exception in thread "main" java.lang.IllegalArgumentException: wrong number of arguments

public class DriverScript {

public static ActionKeywords actionKeywords;
public static String sActionKeyword;
public static Properties OR;
public static String sPageObject;

//Reflection Class object
public static Method method[];

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

    String sPath = Constants.path_TestData;
    ExcelUtils.setExcelFile(sPath, Constants.Sheet_TestSteps);
    String Path_OR = Constants.Path_OR;
    FileInputStream fs = new FileInputStream(Path_OR);
    OR = new Properties(System.getProperties());
    OR.load(fs);
    actionKeywords = new ActionKeywords();
    method = actionKeywords.getClass().getMethods();
    for(int iRow=1;iRow<=9;iRow++){
    sActionKeyword = ExcelUtils.getCellData(iRow, Constants.Col_ActionKeyword);
    sPageObject = ExcelUtils.getCellData(iRow, Constants.Col_PageObject);
    System.out.println(sPageObject);
        execute_Actions();      
    }

}
private static void execute_Actions() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {

    for(int i=0;i<method.length;i++){
        if(method[i].getName().equals(sActionKeyword)){
            method[i].invoke(actionKeywords, (sPageObject));
            break;
        }

    }

Note: when there were no arguments in reflection methods(which are in different class) i have used "method[i].invoke(actionKeywords));" this worked absolutely fine. but now i have added an argument for each of the method and trying to call them using "method[i].invoke(actionKeywords, (sPageObject));" i am getting Exception in thread "main" java.lang.IllegalArgumentException: wrong number of arguments.

Reflection methods class would look like below:

public class ActionKeywords {

public static WebDriver driver;

public static void openBrowser(){
    System.setProperty("webdriver.chrome.driver", "D:/chromedriver.exe");
    driver = new ChromeDriver();
}
public static void navigate(String object){
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.get(Constants.URL);
    driver.manage().window().maximize();
}

public static void click(String object){
    driver.findElement(By.xpath(DriverScript.OR.getProperty(object)));
}

public static void input_Username(String object){
    driver.findElement(By.xpath(DriverScript.OR.getProperty(object))).sendKeys(Constants.UserName);
}
public static void input_Password(String object){
    driver.findElement(By.xpath(DriverScript.OR.getProperty(object))).sendKeys(Constants.Password);
}

public static void waitFor(String object) throws InterruptedException{
    Thread.sleep(5000);
}

public static void closeBrowser(String object) {
    driver.quit();
}

}





Aucun commentaire:

Enregistrer un commentaire