I have @BeforeTest and @AfterTest Annotations used. Please find below code
WebDriverFactory wd = new WebDriverFactory();
//@Parameters({"browserName","appURL"})
@BeforeTest
public void setBrowser(String browserName, String appURL){
wd.setDriver("chrome", "https:URL");
}
@AfterTest
public void tearDown()
{
wd.closeBrowser();
}
And getting below error
AILED CONFIGURATION: @BeforeTest setBrowser org.testng.TestNGException: Can inject only one of into a BeforeTest annotated setBrowser. For more information on native dependency injection please refer to http://testng.org/doc/documentation-main.html#native-dependency-injection at org.testng.internal.Parameters.checkParameterTypes(Parameters.java:244) at org.testng.internal.Parameters.createParameters(Parameters.java:172)
The reason for the error is pretty straight forward:
Your @BeforeTest
annotated method is accepting two String parameters, but you aren't injecting those parameters via the @Parameters
annotation (I am seeing that in the code that you shared, you have commented it out).
TestNG is basically complaining that it doesn't know what to provide as values for those two String parameters, and TestNG can ONLY natively inject either a
ITestContext
object for which your @BeforeTest
annotated method signature would look like public void setBrowser(ITestContext context){
(or) XmlTest
object for which your @BeforeTest
annotated method signature would look like public void setBrowser(XmlTest xmlTest){
So you would need to either uncomment your @Parameters
annotation on top of the setBrowser()
method, or change its signature to one of the above two variants.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With