Here is my selenium testng script and XML file. I am getting the error message. Please help me how to proceed this
Err MSG : Parameter 'Name' is required by @Test on method parametertest but has not been marked @Optional
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class Sampleparameterized {
@Test
@Parameters("Name")
public void parametertest(String Name) {
System.out.println("Parameterized value is " +Name);
}
}
XML file is
<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="false">
<test name="Test">
<parameter name = "Name" value ="TOM"/>
<classes>
<class name="Testing.Sampleparameterized"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
This may be happening when you run from eclipse as Single TestNG test. You may want to refer SO answer given already on TestNG @Optional parameter error.
This error normally comes when you are trying to run individual TestNg class instead of run *.xml. Your parameter is set in *.xml file, so right click on *.xml file and Run as TestNg. Make sure your TestNg class is properly mapped in your *.xml file (class name="com.test.WebServices"). Here WebServices.java is your TestNg class.
You would need to add the following in order to be able to run the test directly from the test class: @Optional("Name").
For example:
Works well for me! Let me know how it goes for you.
Simply run you testclass from *.xml file (right click on *.xml -> Run). Parameterized test can't be run directly.
I was facing same issue which got resolved by below steps -
1. Set your xml file in Project->Properties->TestNG->Template XML File
2. Right click on your Java file and choosing Run As...->TestNG Test (Thus template will be used)