gpt4 book ai didi

java - 配置失败: Method beforeTest requires 1 parameters but 0 were supplied in the @Configuration annotation

转载 作者:行者123 更新时间:2023-12-01 19:49:31 25 4
gpt4 key购买 nike

我试图为 Browserloading 创建一个函数,并从另一个类调用它,但出现以下错误。

   FAILED CONFIGURATION: @BeforeMethod beforeTest
org.testng.TestNGException:
Method beforeTest requires 1 parameters but 0 were supplied in the @Configuration annotation.

我还在 testNG xml 文件中创建了 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();


}


}
}

我需要调用浏览器功能的另一个类

public class LoanDetails {



public static WebDriver driver ;





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

}

tesng xml

<?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 -->

最佳答案

您正在将浏览器对象传递给 LoanDetails 类中的 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;
}
}

关于java - 配置失败: Method beforeTest requires 1 parameters but 0 were supplied in the @Configuration annotation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51927082/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com