2

I have 100s of tests in my testng.xml, most of tests failing due to timing issue, but when I am running them in chunks it works fine

One ineffective solution I tried is to divide the small number of tests in to multiple testng.xml file and run one by one, looking for alternate which I can do the same at run time

Here is how my testng.xml looks like

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite">
    <listeners>
        <listener class-name="baseClasses.TestListener"></listener>
    </listeners>
    <test name="Android">
        <parameter name="platform" value="android"></parameter>
        <classes>
           <class name="testCases.android.VerifyLoginLogout" />
           <class name="testCases.android.test1" /> 
           <class name="testCases.android.test2" />
           ...

           <class name="testCases.android.test100" />
        </classes>
    </test>
</suite>

Any suggestions on how to divide the tests in chunks and run them one by one at run time so I need not to divide the tests into multiple testng.xml files

Note - even tried with package wise run inside testng.xml

sunpat
  • 389
  • 2
  • 7
  • 28
  • Hi Sunpat, will you please provide details on what was not working as well? is above provided xml also not working? Also provide details about how you managing driver. Are you running all tests on same driver instance? for example driver created, application opened and same session used for all test or for each test separate session is created. – user861594 Apr 12 '19 at 23:14
  • Ok here are more details - 1. one @test in one java file, 2. driver instance created for each test. as I told i have 100 tests, when i run whole testng.xml, nearly 30 to 40 tests fail.. but when i run the failed tests again by picking few tests, it passes.. so I am looking for a way at run time to just buffer few tests from that 100 tests to run and then pick another chunk n run... – sunpat Apr 13 '19 at 18:38
  • When you say tests failed in first run and passed in re-run, did you observed same reason of the failure each time during first run? It is important to look into and analyze the failure. Can you also share the reason of failure and exception details? – user861594 Apr 17 '19 at 18:05

2 Answers2

0

As I can understand, you want to run your test cases are in multiple batches. If I am correct then it's very simple. Just divide your all test cases in multiple test tag and use test classes you want to execute in test tag. Please have a look below.

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite">
    <listeners>
        <listener class-name="baseClasses.TestListener"></listener>
    </listeners>


    <test name="Android-1">
        <parameter name="platform" value="android"></parameter>
        <classes>
           <class name="testCases.android.VerifyLoginLogout" />
           <class name="testCases.android.test1" /> 
           <class name="testCases.android.test2" />
           <class name="testCases.android.test3" />
        </classes>
    </test>


        <test name="Android-2">
        <parameter name="platform" value="android"></parameter>
        <classes>
           <class name="testCases.android.test4" /> 
           <class name="testCases.android.test5" />
           <class name="testCases.android.test6" />

        </classes>
    </test>


</suite>

I hope it will help you.

Muzzamil
  • 2,823
  • 2
  • 11
  • 23
  • As I have mentioned earlier, I have divided the tests as per the package [one package per module in our framework] and I have run the tests package wise inside the test tag, just looking for a way where the testng doesn't buffer all the test cases to run rather run each tests as individual. – sunpat Apr 15 '19 at 13:47
-1

You want to 'group' your tests as follows:

import org.testng.Assert;
import org.testng.annotations.Test;

public class GroupTestExample {
   String message = ".com";
   MessageUtil messageUtil = new MessageUtil(message);

   @Test(groups = { "functest", "checkintest" })

   public void testPrintMessage() {
      System.out.println("Inside testPrintMessage()");
      message = ".com";
      Assert.assertEquals(message, messageUtil.printMessage());
   }

   @Test(groups = { "checkintest" })

   public void testSalutationMessage() {
      System.out.println("Inside testSalutationMessage()");
      message = "tutorialspoint" + ".com";
      Assert.assertEquals(message, messageUtil.salutationMessage());
   }

   @Test(groups = { "functest" })

   public void testingExitMessage() {
      System.out.println("Inside testExitMessage()");
      message = "www." + "tutorialspoint"+".com";
      Assert.assertEquals(message, messageUtil.exitMessage());
   }  
}

and then run specific groups in your suite:

<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name = "Suite1">
   <test name = "test1">

      <groups>
         <run>
            <include name = "functest" />
         </run>
      </groups>

      <classes>
         <class name = "GroupTestExample" />
      </classes>

   </test>
</suite>

Reference: Tutorials Point: TestNG - Group Test

Mike Collins
  • 4,108
  • 1
  • 21
  • 28
  • I do not want to run then by groups or package wise.. please see my 1st comment above for more details of my issue. – sunpat Apr 13 '19 at 18:43
  • "Batches" and "groups" are effectively the same thing; you're trying to break a large set of cases into smaller sets. Wrap that all in a script that runs the groups in sequence. – Mike Collins Apr 17 '19 at 16:07