From ece6cf08bc6252407019a39364d567cb940401e3 Mon Sep 17 00:00:00 2001 From: Andrei Kamarouski Date: Tue, 20 Aug 2024 09:09:30 +0200 Subject: [PATCH 1/3] revert before class registration as headless --- .../com/zebrunner/agent/testng/adapter/TestNGAdapter.java | 3 +-- .../com/zebrunner/agent/testng/listener/RetryService.java | 4 ---- .../zebrunner/agent/testng/listener/TestRunListener.java | 6 ------ 3 files changed, 1 insertion(+), 12 deletions(-) diff --git a/src/main/java/com/zebrunner/agent/testng/adapter/TestNGAdapter.java b/src/main/java/com/zebrunner/agent/testng/adapter/TestNGAdapter.java index 4022962..0dfe9a6 100644 --- a/src/main/java/com/zebrunner/agent/testng/adapter/TestNGAdapter.java +++ b/src/main/java/com/zebrunner/agent/testng/adapter/TestNGAdapter.java @@ -133,8 +133,7 @@ private TestInvocationContext buildTestStartInvocationContext(ITestResult testRe } private void setZebrunnerTestIdOnRerun(ITestResult testResult, ITestNGMethod testMethod, TestStartDescriptor testStartDescriptor) { - // testMethod is not available for BeforeClass configuration method, so we just skip this logic in such case - if (RunContextHolder.isRerun() && testMethod != null) { + if (RunContextHolder.isRerun()) { ITestContext context = testResult.getTestContext(); Object[] parameters = testResult.getParameters(); diff --git a/src/main/java/com/zebrunner/agent/testng/listener/RetryService.java b/src/main/java/com/zebrunner/agent/testng/listener/RetryService.java index b0fa06f..7db8a0d 100644 --- a/src/main/java/com/zebrunner/agent/testng/listener/RetryService.java +++ b/src/main/java/com/zebrunner/agent/testng/listener/RetryService.java @@ -90,10 +90,6 @@ private static RetryItemContext getOrInitRetryItemContext(ITestNGMethod method, } public static boolean isRetryFinished(ITestNGMethod method, ITestContext context) { - if (method == null) { - // method is not available for BeforeClass configuration method, so we just return true here - return true; - } return getRetryContext(context) .map(RetryContext::getRetryItemContexts) .map(retryItemContext -> retryItemContext.get(method.getParameterInvocationCount())) diff --git a/src/main/java/com/zebrunner/agent/testng/listener/TestRunListener.java b/src/main/java/com/zebrunner/agent/testng/listener/TestRunListener.java index 90ba2e3..45b2024 100644 --- a/src/main/java/com/zebrunner/agent/testng/listener/TestRunListener.java +++ b/src/main/java/com/zebrunner/agent/testng/listener/TestRunListener.java @@ -95,12 +95,6 @@ public void beforeConfiguration(ITestResult tr, ITestNGMethod tm) { if (testMethod instanceof ConfigurationMethod) { ConfigurationMethod configurationMethod = (ConfigurationMethod) testMethod; - //unable to register test for before suite because all tests reported to the single test - - if (configurationMethod.isBeforeClassConfiguration()) { - adapter.registerHeadlessTestStart(tr, tm); - } - if (configurationMethod.isBeforeMethodConfiguration()) { adapter.registerHeadlessTestStart(tr, tm); } From 551304a1d5e50011683568f5a8a0acf0205b92d1 Mon Sep 17 00:00:00 2001 From: Andrei Kamarouski Date: Thu, 22 Aug 2024 10:21:54 +0200 Subject: [PATCH 2/3] clear pre-test logs queue after 'AfterClass/AfterTest' configuration methods --- .../com/zebrunner/agent/testng/listener/TestRunListener.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/zebrunner/agent/testng/listener/TestRunListener.java b/src/main/java/com/zebrunner/agent/testng/listener/TestRunListener.java index 45b2024..03f8511 100644 --- a/src/main/java/com/zebrunner/agent/testng/listener/TestRunListener.java +++ b/src/main/java/com/zebrunner/agent/testng/listener/TestRunListener.java @@ -1,5 +1,6 @@ package com.zebrunner.agent.testng.listener; +import com.zebrunner.agent.core.registrar.LogsBuffer; import com.zebrunner.agent.testng.adapter.TestNGAdapter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -124,6 +125,10 @@ private void registerFinishOfAfterMethod(ITestResult testResult) { if (testMethod instanceof ConfigurationMethod) { ConfigurationMethod configurationMethod = (ConfigurationMethod) testMethod; + if(configurationMethod.isAfterClassConfiguration() || + configurationMethod.isAfterTestConfiguration()) { + LogsBuffer.clearPreTestQueue(); + } if (configurationMethod.isAfterMethodConfiguration()) { adapter.registerAfterTestFinish(); } From 71243b1ed05a6c6e1600ebc6ea29511f534cc3ed Mon Sep 17 00:00:00 2001 From: Andrei Kamarouski Date: Thu, 29 Aug 2024 12:05:12 +0200 Subject: [PATCH 3/3] reuse clearConfiguration logs method --- .../com/zebrunner/agent/testng/adapter/TestNGAdapter.java | 4 ++++ .../com/zebrunner/agent/testng/listener/TestRunListener.java | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/zebrunner/agent/testng/adapter/TestNGAdapter.java b/src/main/java/com/zebrunner/agent/testng/adapter/TestNGAdapter.java index 0dfe9a6..f9a6212 100644 --- a/src/main/java/com/zebrunner/agent/testng/adapter/TestNGAdapter.java +++ b/src/main/java/com/zebrunner/agent/testng/adapter/TestNGAdapter.java @@ -294,6 +294,10 @@ public void registerAfterTestFinish() { registrar.registerAfterTestFinish(); } + public void clearConfigurationLogs() { + registrar.clearConfigurationLogs(); + } + private TestInvocationContext buildTestInvocationContext(ITestNGMethod testMethod, int dataProviderIndex, Object[] parameters, int invocationIndex) { String displayName = null; Test testAnnotation = testMethod.getConstructorOrMethod() diff --git a/src/main/java/com/zebrunner/agent/testng/listener/TestRunListener.java b/src/main/java/com/zebrunner/agent/testng/listener/TestRunListener.java index 03f8511..82e66fc 100644 --- a/src/main/java/com/zebrunner/agent/testng/listener/TestRunListener.java +++ b/src/main/java/com/zebrunner/agent/testng/listener/TestRunListener.java @@ -1,6 +1,5 @@ package com.zebrunner.agent.testng.listener; -import com.zebrunner.agent.core.registrar.LogsBuffer; import com.zebrunner.agent.testng.adapter.TestNGAdapter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -127,7 +126,7 @@ private void registerFinishOfAfterMethod(ITestResult testResult) { if(configurationMethod.isAfterClassConfiguration() || configurationMethod.isAfterTestConfiguration()) { - LogsBuffer.clearPreTestQueue(); + adapter.clearConfigurationLogs(); } if (configurationMethod.isAfterMethodConfiguration()) { adapter.registerAfterTestFinish();