Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Why is testng unable to find a parameter?


Asked by Bria Stark on Dec 13, 2021 FAQ



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.
Similarly,
Parameterized tests allow developers to run the same test over and over again using different values. TestNG lets you pass parameters directly to your test methods in two different ways − With this technique, you define the simple parameters in the testng.xml file and then reference those parameters in the source files.
Just so, 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. Any parameter value defined at the test level will override the value of a parameter, with same name, if defined at suite level.
In this manner,
The parameters would be passed from testng.xml. This file is located inside your project directory. If it doesn’t exist, you can create the file by going to: File menu > New > File. Name the file as “testng.xml” and click on Finish.
Keeping this in consideration,
Suppose we want to set the global variables such url settings, username, password or API Keys, there are some values which are constant in all the test cases, in such case we use the TestNG Parameters. TestNG Parameters are present in the xml file. They can be applied either inside the tag or tag.