jeudi 25 novembre 2021

Getting "java.lang.NoSuchMethodException: cicd.testSet.Login.

I tried to call the method from excel sheet and it is getting failed with NoSuchmethodException eventhough I'm using correct set of constructor parameters and everything

Base Class code

    Class<?> classname=Class.forName("cicd.testSet."+excelRead.sheet.getRow(flag).getCell(0).getStringCellValue().trim());
                  String MethodName=excelRead.sheet.getRow(flag).getCell(2).getStringCellValue().trim(); //Method Name from Excel
                  try{  
                      Object parameter=null;
                       try{
                           parameter=excelRead.sheet.getRow(flag).getCell(3).getStringCellValue();
                       }catch(Exception e){
                           parameter=excelRead.sheet.getRow(flag).getCell(3).getRawValue();
                       }
                       int parameterCount=0;
                       if(parameter instanceof String)
                           parameterCount=Integer.valueOf((String)parameter);
                       else if(parameter instanceof Double || parameter instanceof Integer)
                           parameterCount=(int)parameter;
                       for(Method m: classname.getMethods())    //reading Method names from Functional library
                        {  
                            if(m.getName().equals(MethodName))  //Compapring Method Name with Excel method name
                            {
                                if(m.getParameterCount()==parameterCount)   //Comparing paraameter Count from both FL and Excel
                                {
                                    Class<?> param[]={};
                                    if(parameterCount!=0){
                                    param=new Class[parameterCount]; //Creating an array with class
                
                                    for(int i=0;i<m.getParameterCount();i++) 
                                    {
                                        param[i]=m.getParameterTypes()[i];  //assigning values in to array with parameter type
                                    }
                                    }
                                    Method method=classname.getMethod(MethodName,param);
<--Getting error at this Line--> Constructor<?> con=classname.getConstructor(new Class[]{Object.class,Object.class});
                                    method.invoke(con.newInstance(new Object[]{driver,reports}),ParameterData(parameterCount, flag));
                                }
                        }
                    }

Class which I'm calling to invoke the method

\\Constructor
public Login(RemoteWebDriver driver,Reports report){
        this.driver=driver;
        this.report=report;
        logger=BrowserBase.logManager(BrowserBase.testCaseDesc);
        commonFunctions=new CommonFunctions(driver, report);
        excelRead=new ExcelRead();
    }
    
    public void login_field_verification(){
        driver.get("https://google.com");
        logger.info("URL Loaded in browser https://google.com");
        if(driver.getTitle().contains("Google"))
            report.reportStepStatus("pass", "URL loaded successfully");
        else
            report.reportStepStatus("Fail", "URL not loaded successfully");
    }

Error Log

java.lang.NoSuchMethodException: cicd.testSet.Login.<init>(java.lang.Object, java.lang.Object)
    at java.lang.Class.getConstructor0(Class.java:3082)
    at java.lang.Class.getConstructor(Class.java:1825)
    at cicd.base.BrowserBase.TestCaseExecutor(BrowserBase.java:85)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
    at org.testng.TestRunner.privateRun(TestRunner.java:648)
    at org.testng.TestRunner.run(TestRunner.java:505)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
    at org.testng.SuiteRunner.run(SuiteRunner.java:364)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
    at org.testng.TestNG.runSuites(TestNG.java:1049)
    at org.testng.TestNG.run(TestNG.java:1017)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

I tried to find the root cause and upto my research they way I written is correct, but don't know why it is not creating constructor and saying NoSuchMethodException





Aucun commentaire:

Enregistrer un commentaire