Selenium和testng .. testng.xml解析器异常没有意义

时间:2016-06-29 22:55:00

标签: xml selenium xml-parsing testng testng-eclipse

enter image description here enter image description here代码剪辑:

 @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);  

这是testng.xml文件:

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

以下是例外:

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)

任何想法都会受到赞赏。

在testng.xml中没有参数“parallel”设置为“none”,因此异常会抱怨一个没有意义。

谢谢,

CFR

1 个答案:

答案 0 :(得分:0)

尝试使用 TestNG 对象从其他类中运行testng类,如下例所示: -

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();
}

参考: -
TestNG Documentation


请参阅 setTestSuites 部分