1

enter image description hereenter image description hereCode snip:

 @Test    // checking the login functionality 
 @Parameters({"username" , "password"})
 public void TpPortalLogin(String username, String password)
                                               throws InterruptedException, IOException
 {
    System.out.println("Page title before login: " +driver.getTitle());  
    System.out.println("username: "+username);  
    System.out.println( "password"+password);  

and here is the testng.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="false">
    <test name="TpPortalLogin">
    <parameter name="browser" value="chrome"/>
    <parameter name="url" value="http://xyz.local/"/>
    <parameter name="username" value="somebody"/>
    <parameter name="password" value="something"/>
        <classes>
            <class name="com.parameterization.TestParameters" />
        </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

Here is the exception:

org.testng.TestNGException: org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 251;
    Attribute "parallel" with value "none" must have a value from
                                           the list "false methods tests classes instances ".
  at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:325)
  at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:103)
  at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:137)
  at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:58)
Caused by: org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 251;
  Attribute "parallel" with value "none" must have a value from
                                         the list "false methods tests classes instances ".
  at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)

Any thoughts would be appreciated.

In the testng.xml there is no parameter "parallel" set to "none", so it makes no sense that the exception would complain about one.

Thanks,

CFR.

Charles F Radley
  • 163
  • 1
  • 2
  • 11
  • Can you add your invocation command line? The most likely reason is that you're loading all `testng.xml` files under a directory, and it's a different file that has this issue. The exception doesn't say _which_ file has the invalid attribute. – Paul Hicks Jun 29 '16 at 23:09
  • I am invoking from within eclipse, not from command line, i.e. green drop down -> Run As -> TestNG Test Also I searched my hard drive and there is only one testng.xml file on my hard drive. – Charles F Radley Jun 30 '16 at 00:08
  • Run it from the command line. You will get better error messages. – Paul Hicks Jun 30 '16 at 01:26
  • What if you remove the parallel attribute or change it by none ? – juherr Jun 30 '16 at 04:31
  • Dear Julien, the presence or absence of a parallel attribute in the testng.xml makes no difference to the exception message, neither does the value of any parallel attribute. – Charles F Radley Jun 30 '16 at 12:12

1 Answers1

0

Try to run the testng class from the someother class using the TestNG object like example below :-

public class TestNGRunTest {
   public static void main(String[] args) { 
      TestNG tng = new TestNG();
      List suites = Lists.newArrayList();
      suites.add("complete_path_of_testng.xml_file");
      tng.setTestSuites(suites);
      tng.run();
}

Reference :-
TestNG Documentation


See the setTestSuites section

manishgdev
  • 148
  • 3
  • 12
  • at the command line, when I run in the directory which contains the testng.xml, I get this error: C:\Users\charles\Documents\test-automation\selenium\TP Portal>java -cp testng.jar testng.xml Error: Could not find or load main class testng.xml – Charles F Radley Jun 30 '16 at 14:52
  • Try this java -cp "path-tojar/testng.jar:path_to_yourtest_classes" org.testng.TestNG testng.xml – manishgdev Jun 30 '16 at 15:37
  • I tried copying the testng.xml to the folder containing my classes, then running it from there ... same error ... – Charles F Radley Jun 30 '16 at 16:09
  • Can you edit your question to inckude the folder structure or the image of folder tree for the files of the project. So that it will get more clear about the classpath of tje project – manishgdev Jun 30 '16 at 16:15
  • all the various command line suggestions people are kindly giving me just give various types of errors ..... surely I do not need to give explicit path to the testng.jar because it is already in the classpath ... there is no difficulty to find the testng.jar, it is simply that the testng.jar is not importing the testng.xml file ... why is that ? – Charles F Radley Jun 30 '16 at 16:16
  • The problem is with the classpath which is used in the java command, any how if you include cucumber then first thing approach of execution will change and second thing there also the correct classpath in the command would matter. The answer which is provided is running the Testng class from a main method which can be executed easily without worrying about the class path in command – manishgdev Jun 30 '16 at 16:19
  • I disagree, there is no problem with the classpath .. it is finding the testng.jar AOK, but it is not finding the testng.xml .... am I missing something ? – Charles F Radley Jun 30 '16 at 16:22
  • here is my classpath ....C:\Users\charles\Documents\test-automation\selenium\TP Portal>set classpath CLASSPATH=.;C:\PROGRA~1\IBM\SQLLIB\java\db2java.zip;C:\PROGRA~1\IBM\SQLLIB\java\db2jcc.jar;C:\PROGRA~1\IBM\SQLLIB\java\sqlj.zip;C:\PROGRA~1\IBM\SQLLIB\java\db2jcc_license_cu.jar;C:\PROGRA~1\IBM\SQLLIB\bin;C:\PROGRA~1\IBM\SQLLIB\java\common.jar;C:\Users\charles\.p2\pool\plugins\org.testng.eclipse_6.9.11.201604020423\lib – Charles F Radley Jun 30 '16 at 16:23
  • Here are the transcripts with and without the testng.xml in the command line ...... C:\Users\charles\Documents\test-automation\selenium\TP Portal>java -cp testng.jar testng.xml Error: Could not find or load main class testng.xml C:\Users\charles\Documents\test-automation\selenium\TP Portal>java -cp testng.jar Usage: java [-options] class [args...] (to execute a class) or java [-options] -jar jarfile [args...] (to execute a jar file) where options include: [long lsit of options] – Charles F Radley Jun 30 '16 at 16:24
  • the classpath is only for finding the testng.jar file, right ? That file is being found correctly, right ? so why is it not parsing the testng.xml ? – Charles F Radley Jun 30 '16 at 16:28
  • as requested I have added screenshot of my eclipse project setup – Charles F Radley Jun 30 '16 at 16:33
  • Classpath is not only for passing the jar file but it is also required for locating the package/folder where the class files are located which will be used by the Testng.xml file – manishgdev Jun 30 '16 at 16:33
  • ok thanks for that explanation. I tried invoking the command line from the folder in which the class files are located, but i got the same error [even after copying the testng.xml to the folder containing the class files].... the dot is in the classpath so that should work, right ? – Charles F Radley Jun 30 '16 at 16:39
  • OK I now have got past this error. After considerable research I found that testng has a very arcane and complex syntax for command line invocation, and thou shalt be perished if thou deviatest the slightest from this .... this is the line which works for me in a test project I specifically created to research this issue : java -cp ".;C:\Users\charles\.m2\repository\org\testng\testng\6.9.10\testng-6.9.10.jar" org.testng.TestNG testng.xml -- I now have an exception....Error: A JNI error has occurred, please check your installation and try again -- – Charles F Radley Jun 30 '16 at 18:57
  • I now have an exception....Error: A JNI error has occurred, please check your installation and try again --java.lang.NoClassDefFoundError: com/beust/jcommander/ParameterException – Charles F Radley Jun 30 '16 at 19:01
  • ...apparently a bug in testng and/or eclipse regarding jcommander.jar ... also the behavior of testng command line invocation is poorly documented ... I am burning up a lot of time because of bugs in testng and eclipse and terrible documentation .... – Charles F Radley Jun 30 '16 at 19:15
  • Thanks for all your help, alas, none of the suggestions have resulted in any solution. I even tried going through a worked tutorial at this link: https://www.seleniumeasy.com/testng-tutorials/how-to-run-testng-xml-webdriver-tests-from-command-line#comment-5238 However, my system does not give the results claimed by the tutorial. I was trying to do something relatively simple [passing parameters] and it turned into a disaster. There seem to be a lot of serious undocumented problems in setting up TestNG. After four days I am giving up, and switching to Fitnesse instead of TestNG. – Charles F Radley Jul 01 '16 at 11:39