1

Here is my testng.xml:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="com.mycompany.app_maven-project_jar_1.0-SNAPSHOT">
    <suite-files>
        <suite-file path="src/main/resources/testng.xml" />
    </suite-files>
    <test name="Regression Tests">
        <parameter name="username" value="rashRodeo"/>
        <parameter name="password" value="rashRodeo@1234"/>
        <classes>
            <class name="com.maven.regressionTwo.functionalTwo.TestNGTestsTwo">
             <methods>
                 <exclude name="enterSearchTextDTWO" />                     
             </methods>
            </class>
        </classes>
    </test>
</suite>

here is my @Test using the parameters above:

@Test
@Parameters ({"username","password"})
public void checkForParameters(String username, String password) {

       System.out.println("Username is :"+username+ " Password is: "+password);

}

what is wrong here, why it is getting skipped?

Sukhvinder
  • 11
  • 1

2 Answers2

3

I think you have to use proper TestNg annotations sequence-

Like this-

@Parameters ({"username","password"})
@Test
public void checkForParameters(String username, String password) 
{

       System.out.println("Username is :"+username+ " Password is: "+password);

}

It should works ......

Bharat Mane
  • 6,775
  • 10
  • 40
  • 67
0

If you give the following in the xml it works:

    <suite-file path="./testng.xml" />   

What exactly is the error message you get?

ilm
  • 386
  • 2
  • 5
  • 18
  • There is no error, the Test using @Parameters is just skipped. Even doing this change did not help. – Sukhvinder Nov 13 '15 at 11:17
  • Sorry here is the error: Parameter 'username' is required by Test on method printParametersFromTestNGXML but has not been marked Optional or defined – Sukhvinder Nov 13 '15 at 11:55
  • D you have another method called printParametersFromTestNGXML( )? Your checkForParameters( ) method is fine- printParametersFromTestNGXML( ) is where you need to correct parameter sequence. – demouser123 Nov 13 '15 at 12:11
  • Sorry I just renamed the method hence the confusion – Sukhvinder Nov 13 '15 at 12:17
  • Did the error go away? – demouser123 Nov 13 '15 at 12:20
  • No it did not, renaming the method will not work, guess its problem with my testng.xml – Sukhvinder Nov 13 '15 at 12:35
  • Based on your error message maybe the @optional in the method might work: public void printParametersFromTestNGXML( @Optional("test") String username, String password) – ilm Nov 13 '15 at 13:35
  • Yes optional works, but I want to refer to parameters from testng.xml. The whole setup seems fine, but still it gives an error, I am unable to get around this. – Sukhvinder Nov 16 '15 at 07:06
  • 1
    Figured it out, was using NetBeans IDE which was not running testng.xml as TestSuite – Sukhvinder Nov 18 '15 at 11:55