Setting Up Unique Parameters Once you've enabled Demographic reporting for more insight into your audience, you can start creating custom campaigns and tracking their progress in Analytics. Adding campaign parameters to your campaign destination URLs will help you analyze how effective those campaigns are for your site traffic and sales. Name Type Since Description File-File to be deployed. User property is: file. String-Server Id to map on the under section of settings.xml In most cases, this parameter will be required for authentication.HowToDoInJava
One of the important features of TestNG is parameterization. This feature allows user to pass parameters to tests as arguments. This is supported by using the testng @Parameters annotation.
There are mainly two ways through which we can provide parameter values to testng tests.
testng.xmlXML configuration file
The @Parameters annotation can be used for any of the @Before, @After, @Factory, and @Test annotated methods. It can be used to initialize variables and use them in a class, test, or may be for the whole test execution.
1. TestNG @Parameters – test parameters with testng.xml
If you need to pass some simple values such as
String types to the test methods at runtime, you can use this approach of sending parameter values through testng XML configuration files. You have to use the @Parameters annotation for passing parameter values to the test method.
Let’s write a simple example of passing parameters to test methods through the XML configuration file.
In below test, we created a test class with multiple methods that accepts parameters from testng. The parameter values are set at both suite and test level in the testng XML file.
Starting now, you can order two of the following things for only $5: Big Mac; 10-piece Chicken McNuggets; Filet-O-Fish; Quarter Pounder with Cheese; Sorry—no McLobster, though. Previously, McDonald’s had offered a similar Mix & Match deal for $5, as well as the McPick 2 for $2 menu. But the deal never included the Quarter Pounder. These Big Mac Biscuit Bombs are perfect for a fun twist on burger night at home or new party appetizer everyone will love. These Big Mac Biscuit Bombs are 3 WW SP for 1, 5 WW SP for 2, and 8 WW SP for 3. Recipe makes 18. The one and only McDonald’s Big Mac® Combo Meal. Big Mac Ingredients include a classic sesame hamburger bun, Big Mac Sauce, American cheese and sliced pickles. The Big Mac Combo Meal is served with our World Famous Fries® and your choice of an icy Coca-Cola fountain drink. Mouthwatering perfection starts with two 100% pure beef patties and Big Mac sauce sandwiched between a sesame seed bun. It’s topped off with pickles, crisp shredded lettuce, finely chopped onion and American cheese. Get a Big Mac now with Mobile Order & Pay on iOS or Android. Order on the App, and pass the line with a tap with Mobile Order & Pay. Starting on Feb. 29, the fast-food giant will offer its Big Mac, 10-piece Chicken McNuggets, Filet-O-Fish and Quarter Pounder with Cheese nationwide on its McPick 2 for $5 menu. While these items. 2 for 5 big mac.
Any parameter value defined at the test level will override the value of a parameter, with same name, if defined at suite level. You can see this in test three for test method
Now add a
testng.xml file to the project root and put the following code to it. Here we define the parameter values to be passed.
Now run above tests using
testng.xml. Output of above test run is given below:
As you can see from the test results, only
timeTestTwo() for executed because it’s execution time was less than timeout time defined in
timeTestOne() execution got cancelled because it took more time to complete than timeout duration configured.
2. TestNG @Parameters – Optional parameters
TestNG also provides an option to provide optional parameters, this value will be used if parameter value is not found in the defined file.
2.1. Test with @Optional annotation
To pass optional parameters, use
The preceding class file contains a single test method that takes one parameter as input. The said test method on execution prints the parameter value that is passed onto the console using the
The parameter value is passed to the test method using the parameter named optional-value from the XML file. An optional value for the said parameter is defined using the
@Optional annotation against the said parameter.
2.2. Test with @Optional annotation
testng.xml file has two tests defined above. No parameter is defined in the first test where as the second test declares a parameter named ‘optional-value‘ in it.
Output of running above code as test suite is :
As you can see from the previous test results, TestNG has passed the optional value to the test method during first test execution. This happened because TestNG was unable to find a parameter named optional-value in the XML file from the first test.
During the second test it found the parameter value in the XML and passed the said value to the test method during execution.
Happy Learning !!