How to resolve Can inject only one of <ITestContext, XmlTest> into a BeforeTest annotated setBrowser error

Viewed 17149

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)

2 Answers

I agree with Krishnan, it can resolve your problem; however, if you do not want to use one of ITestContext or XmlTest, there is another simple solution.

Just do not use any parameter in setBrowser function that was associated with @Parameters. By deleting these parameters, your test will run and you will not observe this error.

Secondly, for browser name and app url you should use config.properties in this case.

Related