title: "Executing a test in testNG based on condition"
body: <p>i have a testNG xml which will execute a (one)test case 2 times. the difference between each time is the test level parameter. so i have to execute the test case with 2 different parameter (2 user).</p>
  
  <p>Now i will be creating new xml (suite of xml) from which i will call the existing xml. i will define a new parameter in suite xml for the User.</p>
  
  <p>Expectation is if suite xml parameter="user2", then the child xml should execute the test case only once which has parameter as user2. </p>
  
  <p>i tried beanshell scripting and found it useful for method-selector. but i want to make decision for test level and not method level.</p>
  
  <p>Below is the testNG.xml which calls the test case 2 times with different user value. TestCase will be called first time with User="USER1" and second time with User="USER2".</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0"?&gt;
  &lt;suite name="TestLoad"&gt;
      &lt;test verbose="10" name="TestForUser1" preserve-order="true"&gt;
          &lt;parameter name="User" value="USER1"/&gt;
          &lt;classes&gt;
              &lt;class name="com.dummy.test.TestCase"/&gt;
          &lt;/classes&gt;
      &lt;/test&gt;
      &lt;test verbose="10" name="TestForUser2" preserve-order="true"&gt;
          &lt;parameter name="User" value="USER2"/&gt;
          &lt;classes&gt;
              &lt;class name="com.dummy.test.TestCase"/&gt;
          &lt;/classes&gt;
      &lt;/test&gt;
  &lt;/suite&gt;
  </code></pre>
  
  <p>Below is the Suite of xml which i will be newly creating to call many testng.xml described as above. </p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0"?&gt;
  &lt;suite name="suiteOfXml"&gt;
      &lt;parameter name="User" value="USER1"/&gt;
      &lt;suite-files&gt;
          &lt;suite-file path="TestLoad.xml"/&gt;
          &lt;suite-file path="TestStage.xml"/&gt;
      &lt;/suite-files&gt;
  &lt;/suite&gt;
  </code></pre>
  
  <p>Expectation is something like:</p>
  
  <ul>
  <li>if the suiteOfXml has User="USER1" then each testNG xml should run the TestCase only once with User=USER1.</li>
  <li>if the suiteOfXml has User="USER2" then each testNG xml should run the TestCase only once with User=USER2.</li>
  <li>if the suiteOfXml has User="ALL" then each testNG xml should run the TestCase twice. once with User=USER1 and next time with User=USER2.</li>
  </ul>
  
  <p>I cannot make any changes to the TestCase (java class level). condition should be made at xml only.  </p>
  
  <p>Kindly provide a possible solution. Thanks in advance</p>