Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can TestNG run multiple suites?

I am testing a web-ui using Selenium and TestNG. I have a test suite with many test classes in it. I have a @BeforeSuite method which also has a @Parameters annotation, this method receives as a parameter the browser in which the Selenium test will be run, executing the lines:

selenium = new DefaultSelenium("localhost", 4444, browser, "http://localhost:8099");
selenium.start();

The XML I'm using to run the test suite is:

<suite name="suite">
<parameter name = "browser" value = "*firefox"/>
 <test name="allTests">
  <classes>
   <class name="test.webui.MemcachedDeploymentTest" />
  </classes>
 </test> 
</suite>

This works fine and the test runs in Firefox. my problem is that i would like to somehow run this suite again, immediately after the first run finishes, but this time with Chrome as the browser. i now have 2 XML suites, one with Chrome and one with Firefox. Is there any way to run these test suites one after the other automatically? maybe using a third XML?

like image 846
Eli Avatar asked Dec 21 '10 16:12

Eli


People also ask

Can we run multiple suites using TestNG?

We can run multiple test cases using TestNG test suite in Selenium webdriver. To execute test cases simultaneously, we have to enable parallel execution in TestNG. A TestNG execution is driven by the TestNG xml file. To trigger parallel execution we have to use the attributes – parallel and thread-count.

How do you run 100 test cases parallely in TestNG?

To trigger parallel test execution in TestNG, i.e., run tests on separate threads, we need to set the parallel attribute. This attribute accepts four values: methods – runs all methods with @Test annotation in parallel mode. tests – runs all test cases present inside <test> tag in the XML in parallel mode.


2 Answers

You can runt testNG suites like this:

<suite name="allSuites">
  <suite-files>
    <suite-file path="suite1.xml" />
    <suite-file path="suite2.xml" />
    ...
  </suite-files>
</suite>

You can also run those suites in parallel with an ant task. If you want I ll provide example code for ant.

like image 182
Tarken Avatar answered Oct 20 '22 07:10

Tarken


To Run Multiple suites using TestNG XML the correct code goes below, Where I have prepared Three suites suiteA.xml, suiteB.xml, suiteC.xml and have consolidated them in testng.xml. You can copy paste the below code and change the packagename.classname in the class tag and run it would work...

suiteA.xml

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

suiteB.xml

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

suiteC.xml

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

testng.xml

 <?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>
like image 44
Arpan Saini Avatar answered Oct 20 '22 05:10

Arpan Saini