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

5

1

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 -->
Morpho answered 18/9, 2015 at 18:4 Comment(0)
D
3

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

Delimitate answered 21/9, 2015 at 20:1 Comment(1)
But if I do that, any before or after annotations doesn't trigger. So what is the best way to tackle this?Samiel
A
0

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.

Amory answered 21/9, 2015 at 4:44 Comment(0)
R
0

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.

Raincoat answered 6/6, 2017 at 7:58 Comment(0)
S
0

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)

Solorio answered 22/1, 2018 at 5:59 Comment(0)
H
0

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.

Helpmate answered 21/6, 2018 at 12:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.