0

I have two xml files to run tests - api.xml and ui.xml
In ui.xml I have TestNG Listener, but this Listener also is applied when API tests run.
I run tests using testng.xml

ui.xml

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="UI">
    <listeners>
        <listener class-name="utils.Listeners.DebugUiListener"/>
    </listeners>
    <parameter name="environment"  value="qa"/>
    <test name="Login and SignUp">
        <classes>
            <class name="utils.Settings" />
            <class name="UiTests.UILoginTest"/>
        </classes>
    </test>
</suite>

api.xml

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="API">
    <parameter name="environment"  value="qa"/>
    <test name="Login and SignUp">
        <classes>
            <class name="utils.Settings" />
            <class name="ApiTests.ApiLoginTest" />
        </classes>
    </test>
</suite>

testng.xml

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite">
<suite-files>
    <suite-file path="ui.xml" />
    <suite-file path="api.xml"/>
</suite-files>
</suite>

DebugUiListener

public class DebugUiListener implements ITestListener {
//some code
}

What could be the problem?

0

I didn't find any clue in TestNG documentation but according to what I can see in my Idea IDE (however IDE does not always show the truth since they implement their own plugins and hence their own vision on how everything has to work) when you configure a master-suite it is still a single suite

enter image description here

So looks like both your suites are merged into a single suite and your listener is applied to both your UI and API tests.

You can add your listener to your test code (do not forget to remove it from xml file) and that will let you segregate listener application like this:

@Listeners(value = {DebugUiListener.class})
public class UILoginTest {

    // some code here

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.