Tweak to run @AfterMethod before onTestSuccess/onTestFailure

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Tweak to run @AfterMethod before onTestSuccess/onTestFailure

akshay.maldhure
Hello all,

I would like to know if there's some way to tweak TestNG so that the method annotated by @AfterMethod gets executed first and then onTestSuccess/onTestFailure methods in the test listener run.

In my project, the method annotated by @AfterMethod has the logic to print the response body for each test method. And the onTestSuccess/onTestFailure methods have logic to print a message (e.g. "Test completed"). I do not want to put the code to print this message in the @AfterMethod of every test class in my project.

The problem is, the message "Test completed" is shown first and then the response body gets printed, which might be correct as per the TestNG design, but this is something I want to tweak.

--
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.
Reply | Threaded
Open this post in threaded view
|

Re: Tweak to run @AfterMethod before onTestSuccess/onTestFailure

⇜Krishnan Mahadevan⇝

Julien has already answered this on StackoverFlow for you here

 

But here’s a workaround. Instead of trying to log the response via an @AfterMethod, why not log them via IInvokedListener#afterInvocation() ?

 

Here’s a sample that shows you what I am talking about:

 

import com.google.gson.JsonObject;

import org.testng.IInvokedMethod;

import org.testng.IInvokedMethodListener;

import org.testng.ITestResult;

import org.testng.Reporter;

import org.testng.TestListenerAdapter;

import org.testng.annotations.Listeners;

import org.testng.annotations.Test;

 

@Listeners(TestClass.ResponseLoggingListener.class)

public class TestClass {

    @Test

    public void testMethod() {

        //We are just simulating an API call happening here.

        String json = simulateResponse().toString();

        Reporter.getCurrentTestResult().setAttribute("response", json);

    }

 

    private static JsonObject simulateResponse() {

        JsonObject json = new JsonObject();

        json.addProperty("Name", "Cedric");

        json.addProperty("owner", true);

        return json;

    }

 

    public static class ResponseLoggingListener extends TestListenerAdapter implements IInvokedMethodListener {

 

        @Override

        public void beforeInvocation(IInvokedMethod iInvokedMethod, ITestResult iTestResult) {

        }

 

        @Override

        public void afterInvocation(IInvokedMethod iInvokedMethod, ITestResult iTestResult) {

            Object object = iTestResult.getAttribute("response");

            if (object != null) {

                System.err.println("Simulating the Response logging");

                System.err.println(object.toString());

            }

        }

 

        @Override

        public void onTestSuccess(ITestResult iTestResult) {

            System.err.println("On Test Success invoked for " + iTestResult.getMethod().getMethodName());

        }

 

    }

}

 

Output:

 

Simulating the Response logging

{"Name":"Cedric","owner":true}

On Test Success invoked for testMethod

 

===============================================

Default Suite

Total tests run: 1, Failures: 0, Skips: 0

===============================================

 

 

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/

 

From: <[hidden email]> on behalf of <[hidden email]>
Reply-To: <[hidden email]>
Date: Saturday, August 19, 2017 at 12:49 PM
To: testng-users <[hidden email]>
Subject: [testng-users] Tweak to run @AfterMethod before onTestSuccess/onTestFailure

 

Hello all,

 

I would like to know if there's some way to tweak TestNG so that the method annotated by @AfterMethod gets executed first and then onTestSuccess/onTestFailure methods in the test listener run.

 

In my project, the method annotated by @AfterMethod has the logic to print the response body for each test method. And the onTestSuccess/onTestFailure methods have logic to print a message (e.g. "Test completed"). I do not want to put the code to print this message in the @AfterMethod of every test class in my project.

 

The problem is, the message "Test completed" is shown first and then the response body gets printed, which might be correct as per the TestNG design, but this is something I want to tweak.

--
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.

--
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.
Reply | Threaded
Open this post in threaded view
|

Re: Tweak to run @AfterMethod before onTestSuccess/onTestFailure

akshay.maldhure
Thanks Krishnan for your response!

Does it mean that the below line of code must be present in each of my @Test?

Reporter.getCurrentTestResult().setAttribute("response", json);



On Saturday, August 19, 2017 at 2:09:52 PM UTC+5:30, Krishnan wrote:

Julien has already answered this on StackoverFlow for you <a href="https://stackoverflow.com/questions/45768860/tweak-to-run-aftermethod-before-ontestsuccess-ontestfailure" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fstackoverflow.com%2Fquestions%2F45768860%2Ftweak-to-run-aftermethod-before-ontestsuccess-ontestfailure\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNE-rBIy8rSwIWm87y2euIvJ64sEqw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fstackoverflow.com%2Fquestions%2F45768860%2Ftweak-to-run-aftermethod-before-ontestsuccess-ontestfailure\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNE-rBIy8rSwIWm87y2euIvJ64sEqw&#39;;return true;">here

 

But here’s a workaround. Instead of trying to log the response via an @AfterMethod, why not log them via IInvokedListener#afterInvocation() ?

 

Here’s a sample that shows you what I am talking about:

 

import com.google.gson.JsonObject;

import org.testng.IInvokedMethod;

import org.testng.IInvokedMethodListener;

import org.testng.ITestResult;

import org.testng.Reporter;

import org.testng.TestListenerAdapter;

import org.testng.annotations.Listeners;

import org.testng.annotations.Test;

 

@Listeners(TestClass.ResponseLoggingListener.class)

public class TestClass {

    @Test

    public void testMethod() {

        //We are just simulating an API call happening here.

        String json = simulateResponse().toString();

        Reporter.getCurrentTestResult().setAttribute("response", json);

    }

 

    private static JsonObject simulateResponse() {

        JsonObject json = new JsonObject();

        json.addProperty("Name", "Cedric");

        json.addProperty("owner", true);

        return json;

    }

 

    public static class ResponseLoggingListener extends TestListenerAdapter implements IInvokedMethodListener {

 

        @Override

        public void beforeInvocation(IInvokedMethod iInvokedMethod, ITestResult iTestResult) {

        }

 

        @Override

        public void afterInvocation(IInvokedMethod iInvokedMethod, ITestResult iTestResult) {

            Object object = iTestResult.getAttribute("response");

            if (object != null) {

                System.err.println("Simulating the Response logging");

                System.err.println(object.toString());

            }

        }

 

        @Override

        public void onTestSuccess(ITestResult iTestResult) {

            System.err.println("On Test Success invoked for " + iTestResult.getMethod().getMethodName());

        }

 

    }

}

 

Output:

 

Simulating the Response logging

{"Name":"Cedric","owner":true}

On Test Success invoked for testMethod

 

===============================================

Default Suite

Total tests run: 1, Failures: 0, Skips: 0

===============================================

 

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ <a href="http://wakened-cognition.blogspot.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;">http://wakened-cognition.blogspot.com/

My Technical Scribbings @ <a href="http://rationaleemotions.wordpress.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;">http://rationaleemotions.wordpress.com/

 

From: <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="mHb5Y2nZCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng...@...> on behalf of <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="mHb5Y2nZCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">akshay....@...>
Reply-To: <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="mHb5Y2nZCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng...@...>
Date: Saturday, August 19, 2017 at 12:49 PM
To: testng-users <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="mHb5Y2nZCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng...@...>
Subject: [testng-users] Tweak to run @AfterMethod before onTestSuccess/onTestFailure

 

Hello all,

 

I would like to know if there's some way to tweak TestNG so that the method annotated by @AfterMethod gets executed first and then onTestSuccess/onTestFailure methods in the test listener run.

 

In my project, the method annotated by @AfterMethod has the logic to print the response body for each test method. And the onTestSuccess/onTestFailure methods have logic to print a message (e.g. "Test completed"). I do not want to put the code to print this message in the @AfterMethod of every test class in my project.

 

The problem is, the message "Test completed" is shown first and then the response body gets printed, which might be correct as per the TestNG design, but this is something I want to tweak.

--
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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="mHb5Y2nZCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="mHb5Y2nZCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng...@....
Visit this group at <a href="https://groups.google.com/group/testng-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;">https://groups.google.com/group/testng-users.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">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 https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Tweak to run @AfterMethod before onTestSuccess/onTestFailure

⇜Krishnan Mahadevan⇝

Yes it should. If you don’t want to do that, you can perhaps wrap up the operations of making the http call within a method, wherein you can do this. That way you don’t have to have to add this to each and every method.

 

Its like adding a logging mechanism to your own http client invocation methods.

 

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/

 

From: <[hidden email]> on behalf of <[hidden email]>
Reply-To: <[hidden email]>
Date: Saturday, August 19, 2017 at 7:26 PM
To: testng-users <[hidden email]>
Subject: Re: [testng-users] Tweak to run @AfterMethod before onTestSuccess/onTestFailure

 

Thanks Krishnan for your response!

 

Does it mean that the below line of code must be present in each of my @Test?

Reporter.getCurrentTestResult().setAttribute("response", json);

 


On Saturday, August 19, 2017 at 2:09:52 PM UTC+5:30, Krishnan wrote:

Julien has already answered this on StackoverFlow for you here

 

But here’s a workaround. Instead of trying to log the response via an @AfterMethod, why not log them via IInvokedListener#afterInvocation() ?

 

Here’s a sample that shows you what I am talking about:

 

import com.google.gson.JsonObject;

import org.testng.IInvokedMethod;

import org.testng.IInvokedMethodListener;

import org.testng.ITestResult;

import org.testng.Reporter;

import org.testng.TestListenerAdapter;

import org.testng.annotations.Listeners;

import org.testng.annotations.Test;

 

@Listeners(TestClass.ResponseLoggingListener.class)

public class TestClass {

    @Test

    public void testMethod() {

        //We are just simulating an API call happening here.

        String json = simulateResponse().toString();

        Reporter.getCurrentTestResult().setAttribute("response", json);

    }

 

    private static JsonObject simulateResponse() {

        JsonObject json = new JsonObject();

        json.addProperty("Name", "Cedric");

        json.addProperty("owner", true);

        return json;

    }

 

    public static class ResponseLoggingListener extends TestListenerAdapter implements IInvokedMethodListener {

 

        @Override

        public void beforeInvocation(IInvokedMethod iInvokedMethod, ITestResult iTestResult) {

        }

 

        @Override

        public void afterInvocation(IInvokedMethod iInvokedMethod, ITestResult iTestResult) {

            Object object = iTestResult.getAttribute("response");

            if (object != null) {

                System.err.println("Simulating the Response logging");

                System.err.println(object.toString());

            }

        }

 

        @Override

        public void onTestSuccess(ITestResult iTestResult) {

            System.err.println("On Test Success invoked for " + iTestResult.getMethod().getMethodName());

        }

 

    }

}

 

Output:

 

Simulating the Response logging

{"Name":"Cedric","owner":true}

On Test Success invoked for testMethod

 

===============================================

Default Suite

Total tests run: 1, Failures: 0, Skips: 0

===============================================

 

 

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/

 

From: <<a href="javascript:" target="_blank">testng...@...> on behalf of <<a href="javascript:" target="_blank">akshay....@...>
Reply-To: <<a href="javascript:" target="_blank">testng...@...>
Date: Saturday, August 19, 2017 at 12:49 PM
To: testng-users <<a href="javascript:" target="_blank">testng...@...>
Subject: [testng-users] Tweak to run @AfterMethod before onTestSuccess/onTestFailure

 

Hello all,

 

I would like to know if there's some way to tweak TestNG so that the method annotated by @AfterMethod gets executed first and then onTestSuccess/onTestFailure methods in the test listener run.

 

In my project, the method annotated by @AfterMethod has the logic to print the response body for each test method. And the onTestSuccess/onTestFailure methods have logic to print a message (e.g. "Test completed"). I do not want to put the code to print this message in the @AfterMethod of every test class in my project.

 

The problem is, the message "Test completed" is shown first and then the response body gets printed, which might be correct as per the TestNG design, but this is something I want to tweak.

--
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 <a href="javascript:" target="_blank">testng-users...@....
To post to this group, send email to <a href="javascript:" target="_blank">testng...@....
Visit this group at https://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 https://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 https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Tweak to run @AfterMethod before onTestSuccess/onTestFailure

akshay.maldhure
Cool, got it, thanks! I'll try it out.

On Saturday, August 19, 2017 at 7:38:29 PM UTC+5:30, Krishnan wrote:

Yes it should. If you don’t want to do that, you can perhaps wrap up the operations of making the http call within a method, wherein you can do this. That way you don’t have to have to add this to each and every method.

 

Its like adding a logging mechanism to your own http client invocation methods.

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ <a href="http://wakened-cognition.blogspot.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;">http://wakened-cognition.blogspot.com/

My Technical Scribbings @ <a href="http://rationaleemotions.wordpress.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;">http://rationaleemotions.wordpress.com/

 

From: <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="4PNiA1jrCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng...@...> on behalf of <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="4PNiA1jrCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">akshay....@...>
Reply-To: <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="4PNiA1jrCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng...@...>
Date: Saturday, August 19, 2017 at 7:26 PM
To: testng-users <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="4PNiA1jrCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng...@...>
Subject: Re: [testng-users] Tweak to run @AfterMethod before onTestSuccess/onTestFailure

 

Thanks Krishnan for your response!

 

Does it mean that the below line of code must be present in each of my @Test?

Reporter.getCurrentTestResult().setAttribute("response", json);

 


On Saturday, August 19, 2017 at 2:09:52 PM UTC+5:30, Krishnan wrote:

Julien has already answered this on StackoverFlow for you <a href="https://stackoverflow.com/questions/45768860/tweak-to-run-aftermethod-before-ontestsuccess-ontestfailure" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fstackoverflow.com%2Fquestions%2F45768860%2Ftweak-to-run-aftermethod-before-ontestsuccess-ontestfailure\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNE-rBIy8rSwIWm87y2euIvJ64sEqw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fstackoverflow.com%2Fquestions%2F45768860%2Ftweak-to-run-aftermethod-before-ontestsuccess-ontestfailure\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNE-rBIy8rSwIWm87y2euIvJ64sEqw&#39;;return true;">here

 

But here’s a workaround. Instead of trying to log the response via an @AfterMethod, why not log them via IInvokedListener#afterInvocation() ?

 

Here’s a sample that shows you what I am talking about:

 

import com.google.gson.JsonObject;

import org.testng.IInvokedMethod;

import org.testng.IInvokedMethodListener;

import org.testng.ITestResult;

import org.testng.Reporter;

import org.testng.TestListenerAdapter;

import org.testng.annotations.Listeners;

import org.testng.annotations.Test;

 

@Listeners(TestClass.ResponseLoggingListener.class)

public class TestClass {

    @Test

    public void testMethod() {

        //We are just simulating an API call happening here.

        String json = simulateResponse().toString();

        Reporter.getCurrentTestResult().setAttribute("response", json);

    }

 

    private static JsonObject simulateResponse() {

        JsonObject json = new JsonObject();

        json.addProperty("Name", "Cedric");

        json.addProperty("owner", true);

        return json;

    }

 

    public static class ResponseLoggingListener extends TestListenerAdapter implements IInvokedMethodListener {

 

        @Override

        public void beforeInvocation(IInvokedMethod iInvokedMethod, ITestResult iTestResult) {

        }

 

        @Override

        public void afterInvocation(IInvokedMethod iInvokedMethod, ITestResult iTestResult) {

            Object object = iTestResult.getAttribute("response");

            if (object != null) {

                System.err.println("Simulating the Response logging");

                System.err.println(object.toString());

            }

        }

 

        @Override

        public void onTestSuccess(ITestResult iTestResult) {

            System.err.println("On Test Success invoked for " + iTestResult.getMethod().getMethodName());

        }

 

    }

}

 

Output:

 

Simulating the Response logging

{"Name":"Cedric","owner":true}

On Test Success invoked for testMethod

 

===============================================

Default Suite

Total tests run: 1, Failures: 0, Skips: 0

===============================================

 

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ <a href="http://wakened-cognition.blogspot.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;">http://wakened-cognition.blogspot.com/

My Technical Scribbings @ <a href="http://rationaleemotions.wordpress.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;">http://rationaleemotions.wordpress.com/

 

From: <[hidden email]> on behalf of <[hidden email]>
Reply-To: <[hidden email]>
Date: Saturday, August 19, 2017 at 12:49 PM
To: testng-users <[hidden email]>
Subject: [testng-users] Tweak to run @AfterMethod before onTestSuccess/onTestFailure

 

Hello all,

 

I would like to know if there's some way to tweak TestNG so that the method annotated by @AfterMethod gets executed first and then onTestSuccess/onTestFailure methods in the test listener run.

 

In my project, the method annotated by @AfterMethod has the logic to print the response body for each test method. And the onTestSuccess/onTestFailure methods have logic to print a message (e.g. "Test completed"). I do not want to put the code to print this message in the @AfterMethod of every test class in my project.

 

The problem is, the message "Test completed" is shown first and then the response body gets printed, which might be correct as per the TestNG design, but this is something I want to tweak.

--
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 post to this group, send email to [hidden email].
Visit this group at <a href="https://groups.google.com/group/testng-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;">https://groups.google.com/group/testng-users.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="4PNiA1jrCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="4PNiA1jrCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng...@....
Visit this group at <a href="https://groups.google.com/group/testng-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;">https://groups.google.com/group/testng-users.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">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 https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.