Listener declared in testng.xml under <listeners> tag doesn't work

152 views
Skip to first unread message

Arthur Khasanov

unread,
Jun 5, 2023, 4:38:13 PM6/5/23
to testng-users
Hello !

I have the following testng.xml file:
-------------------------------------------------------------------------------
<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name = "Suite #1" configfailurepolicy="continue">
    <listeners>
        <listener class-name="com.codeborne.selenide.testng.SoftAsserts"/>
    </listeners>

    <test name = "Know my IP test">
        <classes>
            <class name="tests.KnowMyIP"/>
        </classes>
    </test>

    <test name="Check PDF content">
        <classes>
            <class name="tests.PDFContentTest"/>
        </classes>
    </test>
</suite>
-------------------------------------------------------------

And after running it, i got:
Starting ChromeDriver 114.0.5735.90 (386bc09e8f4f2e025eddae123f36f6263096ae49-refs/branch-heads/5735@{#1052}) on port 31175
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
июн. 05, 2023 1:22:32 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find an exact match for CDP version 114, so returning the closest version found: 113

java.lang.IllegalStateException: You must configure you classes using JUnit4/JUnit5/TestNG mechanism as documented in https://github.com/selenide/selenide/wiki/SoftAssertions

I use Selenide for UI Automation:
<dependency>
            <groupId>com.codeborne</groupId>
            <artifactId>selenide-testng</artifactId>
            <version>6.15.0</version>
            <scope>compile</scope>
</dependency>

The author of framework said that this is probably issue in TestNG.
Could you help me resolve that issue ?

I use 7.7.0 testng version:
<dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.7.0</version>
        </dependency>

⇜Krishnan Mahadevan⇝

unread,
Jun 6, 2023, 12:47:36 AM6/6/23
to testng...@googlegroups.com
Arthur,

This is a very basic use case for TestNG and we would have known about it via the unit tests if it didn't work. Can you please help share a sample project which we can use to reproduce the problem ?


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-users/95eac612-0dfd-4b23-8e33-489e769c5f86n%40googlegroups.com.

Arthur Khasanov

unread,
Jun 6, 2023, 4:04:41 PM6/6/23
to testng-users

⇜Krishnan Mahadevan⇝

unread,
Jun 6, 2023, 11:16:54 PM6/6/23
to testng...@googlegroups.com
Arthur,

The project you shared is NOT using the latest released version of TestNG.
  • v7.5.1 - JDK8 compliant
  • v7.8.0 - JDK11 compliant
Please refactor your pom file to use one of the above versions and try again. 

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/

Arthur Khasanov

unread,
Jun 7, 2023, 2:01:10 PM6/7/23
to testng-users
I've upgraded TestNG to  v7.5.1 but still get the same error.

⇜Krishnan Mahadevan⇝

unread,
Jun 8, 2023, 1:03:02 AM6/8/23
to testng...@googlegroups.com
Arthur,

I have tried fetching your changes and then running the test code.
I can see that TestNG is invoking the listeners.  There's not much that can be done from the TestNG side.

The documentation of Selenide+TestNG states that the "SoftAsserts" listener is supposed to be added at the class level, but in your example code on github, I don't see the annotation on the test class but instead I see that being added in the suite file.

When I added the "@Listeners(SoftAsserts.class)" to your test class and then ran the suite file, the testcase ran to completion without any issues.

I looked at the implementation and I see that you have to add the listener as a class level annotation and it will NOT work if you add it as a listener on your suite file. 

So please fix your code according to the Selenide + TestNG documentation to get the sample working.

I can confirm that there's no issues with TestNG in terms of listener invocation. If you still feel that there's a problem, I would request you to please help share a test sample that uses only TestNG as a reproducible sample (using TestNG 7.8.0 with JDK11) so that we can further look into it.




Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/

Arthur Khasanov

unread,
Jun 8, 2023, 12:40:55 PM6/8/23
to testng-users
Hmm, but I spoke with frameworks' author and he said that this is TestNG issue :)
Ok, I'll reach him once again about it.

Yeah, I know that documentation says that if you place  SoftAsserts listener at the class level then it will work BUT i want to specify this listener at the suite level becaute it's time consumint to add it every time at the class level.

Reply all
Reply to author
Forward
0 new messages