我创建了三个套件,同时尝试使用Testng.xml运行所有这些套件获取Nullpointer Exception。在所有三个suites.xml代码和Testng.xml代码的代码之后提到。如果你发现为什么这个空指针异常即将到来,请告诉我。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<Suite name="SuiteA">
<Test name="Test CaseA1">
<Classes>
<Class name="com.qtpselenium.suiteA.TestCaseA1" />
</Classes>
</Test>
<Test name="Test CaseA2">
<Classes>
<Class name="com.qtpselenium.suiteA.TestCaseA2" />
</Classes>
</Test>
</Suite>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<Suite name="SuiteB">
<Test name="TestCaseB1">
<Classes>
<Class name="com.qtpselenium.suiteB.TestCaseB1" />
</Classes>
</Test>
<Test name="TestCaseB2">
<Classes>
<Class name="com.qtpselenium.suiteB.TestCaseB2" />
</Classes>
</Test>
</Suite>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<Suite name="SuiteC">
<Test name="TestCaseC1">
<Classes>
<Class name="com.qtpselenium.suiteC.TestCaseC1" />
</Classes>
</Test>
<Test name="TestCaseC2">
<Classes>
<Class name="com.qtpselenium.suiteC.TestCaseC2" />
</Classes>
</Test>
</Suite>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite Name" >
<!-- suite name="Suite Name" -->
<suite-files>
<suite-file path="./suiteA.xml" />
<suite-file path="./suiteB.xml" />
<suite-file path="./suiteC.xml" />
</suite-files>
</suite>
org.testng.TestNGException:java.lang.NullPointerException 在org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:320) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:109) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236) 在org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81) 引起:java.lang.NullPointerException 在org.testng.xml.Parser.parse(Parser.java:179) 在org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:300) ......还有3个
答案 0 :(得分:2)
请使用正确的标签名称 -
<!-- Note the lowercase change to tag names -->
<suite name="SuiteB">
<test name="TestCaseB1">
<classes>
<class name="com.qtpselenium.suiteB.TestCaseB1" />
</classes>
你可以在这里找到它们 - http://testng.org/testng-1.0.dtd.php。作为XML标记,它们大多数都使用连字符小写。
答案 1 :(得分:0)
以下代码完美地运行使用selenium运行多个套件。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="SuiteA" >
<!-- suite name="Suite Name" -->
<test name="TestA1" allow-return-values="true">
<classes>
<!-- packagename.Testcase class name -->
<class name ="com.qtpselenium.suiteA.TestCaseA1" />
</classes>
</test>
<test name="TestA2" allow-return-values="true">
<classes>
<!-- packagename.Testcase class name -->
<class name ="com.qtpselenium.suiteA.TestCaseA1" />
</classes>
</test>
</suite>
************************
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="SuiteB" >
<!-- suite name="Suite Name" -->
<test name="TestB1" allow-return-values="true">
<classes>
<!-- packagename.Testcase class name -->
<class name ="com.qtpselenium.suiteB.TestCaseB1" />
</classes>
</test>
<test name="TestB2" allow-return-values="true">
<classes>
<!-- packagename.Testcase class name -->
<class name ="com.qtpselenium.suiteB.TestCaseB2" />
</classes>
</test>
</suite>
***************************
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="SuiteC" >
<!-- suite name="Suite Name" -->
<test name="TestC1" allow-return-values="true">
<classes>
<!-- packagename.Testcase class name -->
<class name ="com.qtpselenium.suiteC.TestCaseC1" />
</classes>
</test>
<test name="TestC2" allow-return-values="true">
<classes>
<!-- packagename.Testcase class name -->
<class name ="com.qtpselenium.suiteC.TestCaseC2" />
</classes>
</test>
</suite>
********************************
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="TestNG Dadadriver suite" >
<!-- suite name="Suite Name" -->
<suite-files>
<suite-file path="./suiteA.xml" />
<suite-file path="./suiteB.xml" />
<suite-file path="./suiteC.xml" />
</suite-files>
</suite>