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?

asked Jan 25, 2019 at 15:05

1 Answer 1

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
}
answered Jan 28, 2019 at 10:47

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.