IConfigurationListener implementation is not called after specified in XML suite

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

IConfigurationListener implementation is not called after specified in XML suite

Jiong Fu
Hi there,

I'm now working on TestNG 6.9.5 and found a weird problem.

I implemented IConfigurationListener / IConfigurationListener2 and hope these methods can be called when any Exception is thrown from @Before methods. I tried to declare my listener with listener tag in XML suite but it wasn't called at all. However, when directly injecting with @Listeners annotation on my test case, it works fine. Can anyone figure out the problem?

Thanks,
Jiong

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

IConfigurationListener implementation is not called after specified in XML suite

Julien Herr
Can you try with 6.9.9?

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: IConfigurationListener implementation is not called after specified in XML suite

Jiong Fu
I just tried with 6.9.9 but it still doesn't work.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: IConfigurationListener implementation is not called after specified in XML suite

Krishnan Mahadevan
I just now tried with 6.9.9 and I cannot recreate the problem.

Here's my code :

public class ConfigListenerSample {
public ConfigListenerSample() {
String version = TestNG.class.getProtectionDomain().getCodeSource().getLocation().getFile();
System.err.println("TestNG Version being used: " + new File(version).getName());
}

@BeforeClass
public void beforeClass() {
throw new RuntimeException("Purposeful exception to fail a config method.");
}

@Test
public void testMethod() {
System.err.println("Hey I am a simple test method.");
}

public static class SimpleConfigListener implements IConfigurationListener {

public SimpleConfigListener() {
System.err.println("SimpleConfigListener was instantiated.");
}

@Override
public void onConfigurationSuccess(ITestResult itr) {

}

@Override
public void onConfigurationFailure(ITestResult itr) {
System.err.println("::::Failure method was " + itr.getMethod().getMethodName() + "()::::");
}

@Override
public void onConfigurationSkip(ITestResult itr) {

}
}
}
Here's the xml file I am using :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="MySuite" parallel="false" verbose="2">
<listeners>
<listener class-name="organized.chaos.testng.ConfigListenerSample$SimpleConfigListener"/>
</listeners>
<test name="MyTest">
<classes>
<class name="organized.chaos.testng.ConfigListenerSample"/>
</classes>
</test>
</suite>


Here's the output  (I run the test using Maven ) :

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite
SimpleConfigListener was instantiated.
...
... TestNG 6.9.9 by Cédric Beust ([hidden email])
...

TestNG Version being used: testng-6.9.9.jar
::::Failure method was beforeClass()::::
Tests run: 2, Failures: 1, Errors: 0, Skipped: 1, Time elapsed: 0.516 sec <<< FAILURE! - in TestSuite
beforeClass(organized.chaos.testng.ConfigListenerSample)  Time elapsed: 0.201 sec  <<< FAILURE!
java.lang.RuntimeException: Purposeful exception to fail a config method.
at organized.chaos.testng.ConfigListenerSample.beforeClass(ConfigListenerSample.java:18)


Results :

Failed tests:
  ConfigListenerSample.beforeClass:18 Runtime Purposeful exception to fail a con...

Tests run: 2, Failures: 1, Errors: 0, Skipped: 1

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.953 s
[INFO] Finished at: 2015-11-25T10:49:19+05:30
[INFO] Final Memory: 25M/215M
[INFO] ------------------------------------------------------------------------

So can you please help tell us, how you are running your test and if there is a sample class and xml file that you can share which we can execute to recreate 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 Scribbings @ http://rationaleemotions.wordpress.com/

On Wed, Nov 25, 2015 at 8:16 AM, Jiong Fu <[hidden email]> wrote:
I just tried with 6.9.9 but it still doesn't work.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: IConfigurationListener implementation is not called after specified in XML suite

Jiong Fu
Ah, I'm running test suite with latest TestNG Eclipse plugin in Eclipse Luna 4.4.1 version. However, if I directly use Windows command line it works fine, so the problem can be related to plugin.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: IConfigurationListener implementation is not called after specified in XML suite

Venkata Ramana
In reply to this post by Jiong Fu
I'm using testng 6.9.10 , and issue still persists..
Works only when listener is attached on top of class and did not get fired when declared in testng.xml.

Testng.xml
----------------------

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="ChromeSuite">
<listeners>
<listener class-name="listeners.ConfigLis"></listener>
</listeners>
<test name="chrometests">
<classes>
<class name="factorydata.TestCase2"></class>
</classes>
</test>
</suite> <!-- Suite -->

Listener
----------------------------------
public class ConfigLis implements IConfigurationListener2{
 public ConfigLis() {
       String version = TestNG.class.getProtectionDomain().getCodeSource().getLocation().getFile();
       System.err.println("TestNG Version being used: " + new File(version).getName());
   }

public void onConfigurationSuccess(ITestResult itr) {
System.out.println("onConfigurationSuccess-->" + itr.getName());
}

public void onConfigurationFailure(ITestResult itr) {
System.out.println("onConfigurationFailure-->" + itr.getName());
}

public void onConfigurationSkip(ITestResult itr) {
System.out.println("onConfigurationSkip-->" + itr.getName());
}

public void beforeConfiguration(ITestResult tr) {
System.out.println("beforeConfiguration-->" + tr.getName());
}

}

----------------------------------------------------------------------------------

public class TestCase2 {

@BeforeSuite
public void beforSuite() {
System.out.println("before suite  Invoking..." );
}

public TestCase2() {
System.out.println("@@Constructor-->");
}
@BeforeTest
public void beforetest() {
System.out.println("befortest.");
}
@BeforeClass
public void beforeclass() {
System.out.println("beforeclass");
}
}

----------------------------------------------------------

output

TestNG Version being used: testng-6.9.10.jar
@@Constructor-->
[TestNG] Running:
  H:\TrainingAuto\selenium.training\child1.xml

before suite  Invoking...
befortest.
beforeclass

*******************************************

when declared in class file

@Listeners(value = ConfigLis.class)
public class TestCase2 {

@BeforeSuite
public void beforSuite() {



Output
--------------------------
TestNG Version being used: testng-6.9.10.jar
[TestNG] Running:
  H:\TrainingAuto\selenium.training\child1.xml

beforeConfiguration-->beforSuite
before suite  Invoking...
onConfigurationSuccess-->beforSuite
beforeConfiguration-->beforetest
befortest.
onConfigurationSuccess-->beforetest
beforeConfiguration-->beforeclass
beforeclass
onConfigurationSuccess-->beforeclass

On Tuesday, November 24, 

2015 at 9:24:06 AM UTC+5:30, Jiong Fu wrote:
Hi there,

I'm now working on TestNG 6.9.5 and found a weird problem.

I implemented IConfigurationListener / IConfigurationListener2 and hope these methods can be called when any Exception is thrown from @Before methods. I tried to declare my listener with listener tag in XML suite but it wasn't called at all. However, when directly injecting with @Listeners annotation on my test case, it works fine. Can anyone figure out the problem?

Thanks,
Jiong

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Loading...