Quantum test duplicator - Beta

When you need to execute the same TestNG XML test more than once, but with a different set of capabilities or groups, this procedure will greatly simplify the process.

Run the Quantum test duplicator

Note:

This procedure is currently in beta, so there may be bugs. At some point, this procedure may be integrated as a new feature with the official Quantum branch, but for now, you can add it to any existing Quantum project. With any issues or questions, contact Perfecto Support.

To duplicate a Quantum test:

  1. Add the SuiteAlterer class to your project and update the package reference to clear any exceptions. As an example, see the attached file SuiteAlterer.java.
  2. Register the SuiteAlterer class to your existing testNg.xml file in the listeners section, as found in the example testng_web.xml.

    Copy
    <listeners>
        <listener class-name="com.quantum.listeners.QuantumReportiumListener" />
        <listener class-name="com.quantum.listeners.SuiteAlterer" />
    </listeners>
  3. Add a parameter named csvParams to your test XML section of your testNg.xml file, as follows:

    Copy
    <test name="Web Scenarios Test With Param" enabled="true">
    <parameter name="csvParams" value="src/main/resources/data/testParams.csv"></parameter>
  4. Create a CSV file similar to the one found in the testParams.csv file.

How the Quantum test duplicator works

The duplicator takes the suite XML of the TestNG.xml file and consumes it as is, without modification. Then, the duplicator consumes all test XML from the TestNG.xml file. When a reference to a parameter called csvParams is found, it duplicates the test XML. When the test is duplicated, all existing parameters in the test XML are considered, and the parameters from the CSV file are added on top or, in the case of duplication, the CSV will trump the test XML. If the test XML does not have a reference to the csvParams parameter, it is left alone.

CSV format

Headers take any capability that you would normally add, such as perfecto.capability.model . Those capabilities are consumed into the final test XML when the duplication occurs. Make sure that capabilities are typed explicitly the way you would add them to the testNg.xml file. In addition to capabilities, you can add custom headers, such as includedGroups or excludedGroups.

As two headers suggest, you can add a comma-delimited string of groups to either include groups in or exclude groups from the test XML.

Note:

When modifying the CSV file in TextPad, make sure to wrap any delimited strings in quotes (see the example CSV file). If you modify the CSV file in Excel, it automatically wraps the column in quotes in the final output.

Input and output example

Each line of the CSV file duplicates the test XML. Therefore, given the examples provided above (testNg.xml and the CSV file), the original testNg.xml looks as follows.

Copy
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Web Demo Suite" verbose="0" parallel="tests"
thread-count="2">
<listeners>
    <listener class-name="com.quantum.listeners.QuantumReportiumListener" />
    <listener class-name="com.quantum.listeners.SuiteAlterer" />
</listeners>
<test name="Web Scenarios Test With Param" enabled="true">
<parameter name="csvParams" value="src/main/resources/data/testParams.csv"></parameter>
<groups>
    <run>
        <include name="regression" />
    </run>
</groups>
<classes>
    <class
    name="com.quantum.steps.Tests" />
</classes>
</test>
</suite>

When ran through the Duplicator, the file would look as follows. As you can see, the single test is now two tests.

Copy
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite thread-count="2" guice-stage="DEVELOPMENT" verbose="0" name="Web Demo Suite" parallel="tests">
  <listeners>
    <listener class-name="com.quantum.listeners.QuantumReportiumListener"/>
  </listeners>
  <test verbose="0" name="Web Scenarios Test With Param :  1" parallel="tests">
    <parameter name="csvParams" value="src/main/resources/data/testParams.csv"/>
    <parameter name="perfecto.capabilities.report.tags" value="blehan,blehan2"/>
    <parameter name="env.resources" value="src/main/resources/android"/>
    <parameter name="driver.capabilities.model" value="Galaxy.*"/>
    <groups>
      <run>
        <include name="regression"/>
        <include name="@AppleAn"/>
        <include name="@JacksAn"/>
        <exclude name="@UnicornAn"/>
        <exclude name="@MuffinsAn"/>
      </run>
    </groups>
    <classes>
      <class name="com.quantum.steps.Tests"/>
    </classes>
  </test> <!-- Web Scenarios Test With Param :  1 -->
  <test verbose="0" name="Web Scenarios Test With Param :  2" parallel="tests">
    <parameter name="csvParams" value="src/main/resources/data/testParams.csv"/>
    <parameter name="perfecto.capabilities.report.tags" value="blehio,blehio2"/>
    <parameter name="env.resources" value="src/main/resources/iOS"/>
    <parameter name="driver.capabilities.model" value="iPhone.*"/>
    <groups>
      <run>
        <include name="regression"/>
        <include name="@AppleIo"/>
        <include name="@JacksIo"/>
        <exclude name="@UnicornAn"/>
        <exclude name="@MuffinsAn"/>
      </run>
    </groups>
    <classes>
      <class name="com.quantum.steps.Tests"/>
    </classes>
  </test> <!-- Web Scenarios Test With Param :  2 -->
</suite> <!-- Web Demo Suite -->