@Parameter annotation with xml file

@Parameters Annotation

This annotation is used to pass the parameter; Parameter can be passed from xml file or from Goal.

Value passed from xml

Java Code-

public class Testing_Parameters {
@Parameters({"browser","skill"})
@Test
public void testNGParameter(String browser, String skill)
{
System.out.println("The Parameter is :-"+browser+":"+skill);
}
}

XML File-

    
<?xml version="1.0" encoding="UTF-8"?>
<suite name="parameter">
<test name= "param">
<parameter name="skill" value="TestNG"/>
<parameter name="browser" value="Chrome"/>-->
<classes>
<class name="org.Testngpro.Testing_Parameters"></class>
</classes>
</test>
</suite>

Output-

 
[RemoteTestNG] detected TestNG version 7.4.0
[TestNGContentHandler] [WARN] It is strongly recommended to add "" at the top of the suite file [F:\eclipse\Practice_2022\TestNGMethod\parameter.xml] otherwise TestNG may fail or not work as expected.
The Parameter is :-Chrome:TestNG

===============================================
parameter
Total tests run: 1, Passes: 1, Failures: 0, Skips: 0
===============================================


Related topics-
















@Parameters with @optional attribute

This annotation will make the parameter optional and print the message mentioned in optional attribute

Java Code-

public class Testing_parameterOptional {
@Parameters({"browser","skill"})
@Test
public void testNGOptionalParameter(@Optional("Browser is optional")String browser, String skill)
{
System.out.println("The Parameter is :-"+browser+":"+skill);
}
}

XML Code-

   
 <?xml version="1.0" encoding="UTF-8"?>
<suite name="parameter">
<test name= "param">
<parameter name="skill" value="TestNG"/>
<parameter name="browser" value="Chrome"/>
<classes>
<class name="org.Testngpro.Testing_parameterOptional"></class>
</classes>
</test>
</suite>
    

Outcome-

[RemoteTestNG] detected TestNG version 7.4.0
[TestNGContentHandler] [WARN] It is strongly recommended to add "" at the top of the suite file [F:\eclipse\Practice_2022\TestNGMethod\parameter.xml] otherwise TestNG may fail or not work as expected.
The Parameter is :-Browser is optional:TestNG

===============================================
parameter
Total tests run: 1, Passes: 1, Failures: 0, Skips: 0
===============================================

No comments:

Post a Comment