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:
-
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.xmlconfiguration 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 theTestNG.xmlfile for your local executions.Following is an example of how your listeners are listed in the
application.propertiesfile:Copywd.command.listeners=com.quantum.listeners.PerfectoDriverListener;com.quantum.listeners.DriverListener;com.quantum.listeners.ScenarioListener -
Create a separate
TestNG.xmlconfig file for your local executions, such asdebug.xml.During executions, parameters from the
application.propertiesfile are loaded first, so the listeners needed for all untouchedTestNG.xmlfiles (our CI executions) should be kept here. After the params fromapplication.propertiesare loaded, the parameters fromTestNG.xmlget loaded.-
If these are the CI-related
TestNG.xmlfiles, they do not contain any changes, so only the listener params fromapplication.propertiesfile will be taken. -
If this is the
debug.xmlfile related to local executions, it includes different listener params, which now overwrite the ones from theapplication.propertiesfile. In our example, we provide parameters that overwrite the ones from theapplication.propertiesfile 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).
-
-
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.propertiesfile, 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
See also the Perfecto Knowledgebase.