[testng-dev] Access to log messages from BeforeMethod/AfterMethod in Reporter.getOutput(ITestResult) in a custom Listener

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

[testng-dev] Access to log messages from BeforeMethod/AfterMethod in Reporter.getOutput(ITestResult) in a custom Listener

Arcadie C.
Hi Team,

I am writing a custom ITestListener and would like to group in a specific way (separate scenarios that can be collapsed in a HTML log) all the messages issues before/during/after a test method.

From what I can see, whenever I print all messages related to a ITestResult (available in onTestSuccess/onTestFailure...), the messages logged from BeforeMethod/AfterMethod are not there:

@Override
public void onTestSuccess(ITestResult testResult) {
  for(String message : Reporter.getOutput(testResult)) {
    System.out.println(message);
  }
}

When running multiple test methods with a data provider in parallel mode, it is difficult to trace these messages back to a test method.

Do you have any suggestions on how this could be done?

What I've come up so far is:
 - identifying each log message with it's thread Id, ITestResult (when available) and timestamp
 - merging the logs based on a complex logic:
    - based on the timestamp (to get messages logged in BeforeClass/AfterClass)
    - base on the thread id, merging messages issued with a null ITestResult with the next messages with a non-null ITestResult, logged on the same thread.
- other magic

All this is very complex and I'm looking for another way.

Do you have any suggestions?

Do you think it is possible to have Reporter.setCurrentTestResult(...) called before BeforeMethod is called, and set back to null after the AfterMethod (class hint: https://github.com/cbeust/testng/blob/master/src/main/java/org/testng/internal/Invoker.java)?

Any help would be appreciated,
Thanks.

--
You received this message because you are subscribed to the Google Groups "testng-dev" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-dev/-/qF84zdLCPNgJ.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-dev?hl=en.
R K
Reply | Threaded
Open this post in threaded view
|

[testng-dev] Re: Access to log messages from BeforeMethod/AfterMethod in Reporter.getOutput(ITestResult) in a custom Listener

R K
HI Arcadie,

I'm also looking into accessing the Before and After Method log messages. Did you find a solution this problem? It'll be great if you can share what you have found.

Thanks
RK

On Friday, October 5, 2012 10:22:12 PM UTC+5:30, Arcadie wrote:
Hi Team,

I am writing a custom ITestListener and would like to group in a specific way (separate scenarios that can be collapsed in a HTML log) all the messages issues before/during/after a test method.

From what I can see, whenever I print all messages related to a ITestResult (available in onTestSuccess/onTestFailure...), the messages logged from BeforeMethod/AfterMethod are not there:

@Override
public void onTestSuccess(ITestResult testResult) {
  for(String message : Reporter.getOutput(testResult)) {
    System.out.println(message);
  }
}

When running multiple test methods with a data provider in parallel mode, it is difficult to trace these messages back to a test method.

Do you have any suggestions on how this could be done?

What I've come up so far is:
 - identifying each log message with it's thread Id, ITestResult (when available) and timestamp
 - merging the logs based on a complex logic:
    - based on the timestamp (to get messages logged in BeforeClass/AfterClass)
    - base on the thread id, merging messages issued with a null ITestResult with the next messages with a non-null ITestResult, logged on the same thread.
- other magic

All this is very complex and I'm looking for another way.

Do you have any suggestions?

Do you think it is possible to have Reporter.setCurrentTestResult(...) called before BeforeMethod is called, and set back to null after the AfterMethod (class hint: <a href="https://github.com/cbeust/testng/blob/master/src/main/java/org/testng/internal/Invoker.java" target="_blank" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Fcbeust%2Ftestng%2Fblob%2Fmaster%2Fsrc%2Fmain%2Fjava%2Forg%2Ftestng%2Finternal%2FInvoker.java\46sa\75D\46sntz\0751\46usg\75AFQjCNH5mFqwo6tU5t2JWJvbauzHun4qZw';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Fcbeust%2Ftestng%2Fblob%2Fmaster%2Fsrc%2Fmain%2Fjava%2Forg%2Ftestng%2Finternal%2FInvoker.java\46sa\75D\46sntz\0751\46usg\75AFQjCNH5mFqwo6tU5t2JWJvbauzHun4qZw';return true;">https://github.com/cbeust/testng/blob/master/src/main/java/org/testng/internal/Invoker.java)?

Any help would be appreciated,
Thanks.

--
You received this message because you are subscribed to the Google Groups "testng-dev" 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-dev.
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

[testng-dev] Re: Access to log messages from BeforeMethod/AfterMethod in Reporter.getOutput(ITestResult) in a custom Listener

Michael May
You could maybe use static testId's for grouping all test information together for a certain test. This is what I did for tracking down information on from a certain test:
In the test case class (using java 8):

    private static LongAdder testIdIndex;
    private static LongAdder classIdIndex;
    private String classId;

    static {
        testIdIndex = new LongAdder();
        classIdIndex = new LongAdder();
    }

    @BeforeMethod
    public void beforeMethodMasterTestCase(ITestResult result) {
        testIdIndex.increment();
        int testId = testIdIndex.intValue();
        result.setAttribute("test_id", "TID-" + testId);
        result.setAttribute("class_id", classId);
    }

    @AfterMethod
    public void afterMethodMasterTestCase(ITestResult result) {
    }
   
    @BeforeClass
    public void beforeClassMasterTestCase() {
        classIdIndex.increment();
        classId = "CLSID-" + classIdIndex.intValue();
    }
   
    public String getTestId() {
        return (String) Reporter.getCurrentTestResult().getAttribute("test_id");
    }
   
    public String getClassId() {
        return classId;
    }

Then when you are logging messages, you append the message with the test_id or class_id for tracking purposes. I use the classId for outputting stuff in @BeforeClass. Then in ReportNG I output the ClassId and TestId for every test case so I can track down test information in the logs if a test fails.

On Tuesday, December 3, 2013 1:40:57 AM UTC-5, R K wrote:
HI Arcadie,

I'm also looking into accessing the Before and After Method log messages. Did you find a solution this problem? It'll be great if you can share what you have found.

Thanks
RK

On Friday, October 5, 2012 10:22:12 PM UTC+5:30, Arcadie wrote:
Hi Team,

I am writing a custom ITestListener and would like to group in a specific way (separate scenarios that can be collapsed in a HTML log) all the messages issues before/during/after a test method.

From what I can see, whenever I print all messages related to a ITestResult (available in onTestSuccess/onTestFailure...), the messages logged from BeforeMethod/AfterMethod are not there:

@Override
public void onTestSuccess(ITestResult testResult) {
  for(String message : Reporter.getOutput(testResult)) {
    System.out.println(message);
  }
}

When running multiple test methods with a data provider in parallel mode, it is difficult to trace these messages back to a test method.

Do you have any suggestions on how this could be done?

What I've come up so far is:
 - identifying each log message with it's thread Id, ITestResult (when available) and timestamp
 - merging the logs based on a complex logic:
    - based on the timestamp (to get messages logged in BeforeClass/AfterClass)
    - base on the thread id, merging messages issued with a null ITestResult with the next messages with a non-null ITestResult, logged on the same thread.
- other magic

All this is very complex and I'm looking for another way.

Do you have any suggestions?

Do you think it is possible to have Reporter.setCurrentTestResult(...) called before BeforeMethod is called, and set back to null after the AfterMethod (class hint: <a href="https://github.com/cbeust/testng/blob/master/src/main/java/org/testng/internal/Invoker.java" target="_blank" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Fcbeust%2Ftestng%2Fblob%2Fmaster%2Fsrc%2Fmain%2Fjava%2Forg%2Ftestng%2Finternal%2FInvoker.java\46sa\75D\46sntz\0751\46usg\75AFQjCNH5mFqwo6tU5t2JWJvbauzHun4qZw';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Fcbeust%2Ftestng%2Fblob%2Fmaster%2Fsrc%2Fmain%2Fjava%2Forg%2Ftestng%2Finternal%2FInvoker.java\46sa\75D\46sntz\0751\46usg\75AFQjCNH5mFqwo6tU5t2JWJvbauzHun4qZw';return true;">https://github.com/cbeust/testng/blob/master/src/main/java/org/testng/internal/Invoker.java)?

Any help would be appreciated,
Thanks.

--
You received this message because you are subscribed to the Google Groups "testng-dev" 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-dev.
For more options, visit https://groups.google.com/d/optout.