0
votes

While running my test suite from testng.xml for parallel browsers, tests are getting executed properly but on running same tests from my testscriptclass file getting below error.

FAILED CONFIGURATION: @BeforeTest setup org.testng.TestNGException: Parameter 'browser' is required by @Configuration on method setup but has not been marked @Optional or defined in C:\Users\hp\AppData\Local\Temp\testng-eclipse-1150453903\testng-customsuite.xml

My question is Is it necessary to use @optional annotation in method under .java class while running selenium test using @Parameters ?

2

2 Answers

0
votes

I think the answer is NO. Try these solutions, please let us know if it works: https://github.com/browserstack/testng-browserstack/issues/10

0
votes

@Optional annotation is specifically there to handle the scenario where no parameters are passed to the test. It's like the default value of the parameter that will be considered for execution if you miss some parameters. It's totally up to you to decide whether to use it or not.

Eg:

@Test
@Parameters(value = {"username"})
public void login
            (@Optional("user1") String username){

   System.out.println(username)
}

In the above example, if the username parameter is not passed, the string username will be assigned the value of "user1".

Try executing the above program with/without parameter to understand the output.