Use different listeners for local and CI executions in Quantum

Often, you need different steps to be executed depending on whether you run your tests locally or from a CI tool, such as Jenkins or Bamboo. An example of such CI tool-related listeners are listeners that perform API calls that are usually not going trough Eclipse, for example to check if the device is available. If you keep that same listener during local execution with the same device opened from the IDE, the device appears busy and the test could fail (DriverListener). Another example is the listener implemented to reinitiate the driver every hour, to prevent various server hanging problems (ScenarioListener).

This article explains how to use different listeners for local and CI executions in Quantum. Watch this short video for a demo, or follow the detailed steps below.

To use different listeners:

  1. Decide if you want to keep the listeners that are needed for your CI executions or the ones you need for your local executions.

    Chances are that you have several TestNG.xml configuration files for your CI execution (one for smoke testing, one for regressions testing, and so on). If this is the case, you are well adviced to keep the listeners you need for your CI executions and remove the ones that you need for local executions. This way, you need to edit only the TestNG.xml file for your local executions.

    Following is an example of how your listeners are listed in the application.properties file:

    Copy
    wd.command.listeners=com.quantum.listeners.PerfectoDriverListener;com.quantum.listeners.DriverListener;com.quantum.listeners.ScenarioListener
  2. Create a separate TestNG.xml config file for your local executions, such as debug.xml.

    During executions, parameters from the application.properties file are loaded first, so the listeners needed for all untouched TestNG.xml files (our CI executions) should be kept here. After the params from application.properties are loaded, the parameters from TestNG.xml get loaded. 

    • If these are the CI-related TestNG.xml files, they do not contain any changes, so only the listener params from application.properties file will be taken.

    • If this is the debug.xml file related to local executions, it includes different listener params, which now overwrite the ones from the application.properties file. In our example, we provide parameters that overwrite the ones from the application.properties file by removing the unneeded listeners and running only the listeners that we need for local executions (or possibly adding additional listeners that you need only for local execution and debugging). 

  3. Add additional parameters in your new XML file. In the following sample code, this is line 7. The parameter name is the same as the one in the application.properties file, and the value should contain all of the listeners that you want to pass. If there is more than one, you can separate them with comma (",").

    Copy
    <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
    <suite name="Web Demo Suite" verbose="0" parallel="tests"
        thread-count="100">
        <listeners>
            <listener class-name="com.quantum.listeners.QuantumReportiumListener" />
        </listeners>
        <parameter name="wd.command.listeners" value="com.quantum.listeners.PerfectoDriverListener"/>
        <test name="Web Scenarios Android Test" enabled="true" thread-count="10">
            <parameter name="driver.capabilities.model" value="Galaxy.*"></parameter>
            <groups>
                <run>
                    <include name="@WebSearch" />
                </run>
            </groups>
            <classes>
                <class
                    name="com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory" />
            </classes>
        </test>

See also the Perfecto Knowledgebase.