Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 配置失败:beforeTest方法需要1个参数,但@CONFIGURATION批注中提供了0_Java_Selenium Webdriver_Testng - Fatal编程技术网

Java 配置失败:beforeTest方法需要1个参数,但@CONFIGURATION批注中提供了0

Java 配置失败:beforeTest方法需要1个参数,但@CONFIGURATION批注中提供了0,java,selenium-webdriver,testng,Java,Selenium Webdriver,Testng,我试图创建一个用于Browserloading的函数,并从另一个类调用它,但遇到以下错误 FAILED CONFIGURATION: @BeforeMethod beforeTest org.testng.TestNGException: Method beforeTest requires 1 parameters but 0 were supplied in the @Configuration annotation. 我还在testngxml文件中创建了testN

我试图创建一个用于Browserloading的函数,并从另一个类调用它,但遇到以下错误

   FAILED CONFIGURATION: @BeforeMethod beforeTest
    org.testng.TestNGException: 
    Method beforeTest requires 1 parameters but 0 were supplied in the @Configuration annotation.
我还在testngxml文件中创建了testNG参数

下面是我为浏览器加载创建的函数,以便从其他类调用它

import com.seleniumdata.zmartano.LoanDetails;

public class Browser {

    public  static WebDriver driver;

     LoanDetails objLoan = new LoanDetails();

       @BeforeMethod
       @Parameters("Browser")
       public  void beforeTestUtility(String browser) throws Exception {
           LoanDetails.beforeTest(browser);
       }


   @Test
   public static void  GetBrowser(String Browser) 
   {

      if  (Browser.equalsIgnoreCase("Firefox")) {
              Log.info("Driver Initiated");
              System.setProperty("webdriver.firefox.driver", Constants.geckodriver);
              driver = new FirefoxDriver();
              driver.get(Constants.URL);
              Log.info("Application Opening");
              driver.manage().window().maximize();

        }

              else if (Browser.equalsIgnoreCase("Chrome")) {
                  Log.info("Driver Initiated");
                  System.setProperty("webdriver.chrome.driver", Constants.chromedriver);
                  driver = new ChromeDriver();
                  driver.get(Constants.URL);
                  Log.info("Application Opening");
                  driver.manage().window().maximize();


              }


   }   
}
我的另一个类需要从中调用browser函数

public class LoanDetails {



    public static  WebDriver driver ;





     public static  void beforeTest(String browser) throws Exception {
     Browser.GetBrowser(browser);

     }
TESSNGXML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="tests" thread-count="2">



  <test name ="FirefoxTest">
   <parameter name="Browser" value ="Firefox"/>


    <classes>

      <class name="com.seleniumdata.zmartano.LoanDetails"/>
    </classes>



  </test> <!-- Test -->
</suite> <!-- Suite -->

您正在将browser对象传递给LoandDetails类中的void beforeTest()方法

因此,您需要在@BeforeMethod注释上传递@Parameter注释:

public class LoanDetails {     

     WebDriver driver ;     

      public void commonMethod(String browser) throws Exception { 
              driver = Browser.GetBrowser(browser); 
      }
}
调用单独的类来测试类

public class Browser {

 private static WebDriver driver;
 LoanDetails objLoan = new LoanDetails();

   @BeforeMethod
   @Parameters("Browser")
   public  void beforeTestUtility(String browser) throws Exception {
        objLoan.commonMethod(browser);
   }

   @Test
   public static WebDriver  GetBrowser(String Browser) 
   {
    if (driver != null) 

        return driver;


        else if (Browser.equalsIgnoreCase("Firefox")) {
              Log.info("Driver Initiated");
              System.setProperty("webdriver.firefox.driver", Constants.geckodriver);
              driver = new FirefoxDriver();
              driver.get(Constants.URL);
              Log.info("Application Opening");
              driver.manage().window().maximize();
              return driver;
        }

              else if (Browser.equalsIgnoreCase("Chrome")) {
                  Log.info("Driver Initiated");
                  System.setProperty("webdriver.chrome.driver", Constants.chromedriver);
                  driver = new ChromeDriver();
                  driver.get(Constants.URL);
                  Log.info("Application Opening");
                  driver.manage().window().maximize();

                  return driver;
              }                    
   return driver;                    
   }   
}

您正在将browser对象传递给LoandDetails类中的void beforeTest()方法

因此,您需要在@BeforeMethod注释上传递@Parameter注释:

public class LoanDetails {     

     WebDriver driver ;     

      public void commonMethod(String browser) throws Exception { 
              driver = Browser.GetBrowser(browser); 
      }
}
调用单独的类来测试类

public class Browser {

 private static WebDriver driver;
 LoanDetails objLoan = new LoanDetails();

   @BeforeMethod
   @Parameters("Browser")
   public  void beforeTestUtility(String browser) throws Exception {
        objLoan.commonMethod(browser);
   }

   @Test
   public static WebDriver  GetBrowser(String Browser) 
   {
    if (driver != null) 

        return driver;


        else if (Browser.equalsIgnoreCase("Firefox")) {
              Log.info("Driver Initiated");
              System.setProperty("webdriver.firefox.driver", Constants.geckodriver);
              driver = new FirefoxDriver();
              driver.get(Constants.URL);
              Log.info("Application Opening");
              driver.manage().window().maximize();
              return driver;
        }

              else if (Browser.equalsIgnoreCase("Chrome")) {
                  Log.info("Driver Initiated");
                  System.setProperty("webdriver.chrome.driver", Constants.chromedriver);
                  driver = new ChromeDriver();
                  driver.get(Constants.URL);
                  Log.info("Application Opening");
                  driver.manage().window().maximize();

                  return driver;
              }                    
   return driver;                    
   }   
}

评论不用于扩展讨论;此对话已结束。评论不用于扩展讨论;这段对话已经结束。