+1 vote
in TestNG by
What are the optional parameters in TestNG?

1 Answer

0 votes
by
Optional parameters work similarly to the default case in the parameterization in TestNG. We use the optional parameter when no other parameter gets defined for that test case method. Additionally, the @Optional annotation declares the optional parameter. We don’t define the @Optional parameter above the test method definition but alongside where the method is declared. Subsequently, the following code snippet demonstrates the declaration of the optional parameters in TestNG:

import org.testng.annotations.Optional;

import org.testng.annotations.Parameters;

import org.testng.annotations.Test;

public class Params

{

    @Test

    @Parameters ("message")

    public void OP( @Optional("Optional Parameter Selected") String message) {

        System.out.println(message);

    }

}

import org.testng.annotations.Optional;

import org.testng.annotations.Parameters;

import org.testng.annotations.Test;

 

public class Params

{

    @Test

    @Parameters ("message")

    public void OP( @Optional("Optional Parameter Selected") String message) {

        System.out.println(message);

    }

}

Related questions

0 votes
asked Apr 19, 2021 in TestNG by rajeshsharma
+1 vote
asked Apr 19, 2021 in TestNG by rajeshsharma
...