使用Excel执行时在Java Reflection中获取“ NOSuchMethodException”

时间:2018-07-14 11:27:30

标签: java reflection apache-poi

我试图使用Java Reflection和Microsoft Excel执行Selenium代码,以实现关键字驱动框架。但是代码正在执行,没有任何问题,但是结果的末尾出现“ NoSuchMethodException”。任何人都可以帮忙吗我是这个“ Java Reflection”和“ keywordDriven框架”的新手。

 for(int Tests=1;Tests<TestData.sheet.getLastRowNum()+1;Tests++){

      if(this.getClass().getSimpleName().contains(TestData.sheet.getRow(Tests).getCell(0).getStringCellValue()))
        { 
                String MethodName=TestData.sheet.getRow(Tests).getCell(2).getStringCellValue();
            try{    
                Method method=FunctionLibrary.class.getMethod(MethodName,String.class,String.class,String.class);
                method.invoke(lib,TestData.sheet.getRow(Tests).getCell(5).getStringCellValue(),TestData.sheet.getRow(Tests).getCell(6).getStringCellValue(),TestData.sheet.getRow(Tests).getCell(4).getStringCellValue());
            }catch(InvocationTargetException | NoSuchMethodException e){
                e.printStackTrace();
            }
          }
        }

//错误日志目录//

java.lang.NoSuchMethodException: lib.FunctionLibrary.(java.lang.String, java.lang.String, java.lang.String)
    at java.lang.Class.getMethod(Unknown Source)
    at testCaseWithKeywordFramework.TestCase1_Login.Login(TestCase1_Login.java:36)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:669)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:877)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1201)
    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:776)
    at org.testng.TestRunner.run(TestRunner.java:634)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:425)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:420)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:385)
    at org.testng.SuiteRunner.run(SuiteRunner.java:334)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1318)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1243)
    at org.testng.TestNG.runSuites(TestNG.java:1161)
    at org.testng.TestNG.run(TestNG.java:1129)
    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)
java.lang.NoSuchMethodException: lib.FunctionLibrary.(java.lang.String, java.lang.String, java.lang.String)
    at java.lang.Class.getMethod(Unknown Source)
    at testCaseWithKeywordFramework.TestCase1_Login.Login(TestCase1_Login.java:36)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:669)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:877)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1201)
    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:776)
    at org.testng.TestRunner.run(TestRunner.java:634)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:425)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:420)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:385)
    at org.testng.SuiteRunner.run(SuiteRunner.java:334)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1318)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1243)
    at org.testng.TestNG.runSuites(TestNG.java:1161)
    at org.testng.TestNG.run(TestNG.java:1129)
    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)

我不知道为什么即使那个Classname不匹配也要继续执行。

ExcelSheetImage Please Check here

0 个答案:

没有答案