user5351559
user5351559

Reputation: 11

Parameter 'Name' is required by @Test on method parametertest but has not been marked @Optional

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 -->

Upvotes: 1

Views: 19885

Answers (5)

user2495926
user2495926

Reputation: 63

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:

public void parametertest(@Optional("Name"),String Name) {
System.out.println("Parameterized value is " +Name);
}

Works well for me! Let me know how it goes for you.

Upvotes: 0

Meetu
Meetu

Reputation: 11

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)

Upvotes: 0

Kabirul Islam
Kabirul Islam

Reputation: 164

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.

Upvotes: 0

IVL
IVL

Reputation: 103

Simply run you testclass from *.xml file (right click on *.xml -> Run). Parameterized test can't be run directly.

Upvotes: 3

MKay
MKay

Reputation: 836

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.

Upvotes: 0

Related Questions