'While running suits using testng.xml getting null pointer Exception , While able to Run Individual tests case WITH TESTNG

i created the Three suites while trying to run all of them using Testng.xml getting Nullpointer Exception. Mentioned after the code of all three suites.xml code and Testng.xml code. Please let me know if you findout why this null pointer Exception is coming.


            <?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 at 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) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81) Caused by: java.lang.NullPointerException at org.testng.xml.Parser.parse(Parser.java:179) at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:300) ... 3 more



Solution 1:[1]

Please use correct tag's name probably -

<!-- Note the lowercase change to tag names -->

<suite name="SuiteB">
    <test name="TestCaseB1">
        <classes>
            <class   name="com.qtpselenium.suiteB.TestCaseB1" />
        </classes>

You can find them documented here - http://testng.org/testng-1.0.dtd.php. Being XML tags they mostly follow lowercase with hyphens.

Solution 2:[2]

The below code is working perfectly to run Multiple suites using 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>

Solution 3:[3]

For your Before and After annotations(BeforeTest, BeforeMethod, BeforeSuite, etc) add (alwaysRun = true), that might be the solution.

It worked for me. Although I was having issues when I was using Groups in TestNG XML coupled with One class. enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2
Solution 3 Sritaj Patel