Skip to content

Commit

Permalink
Merge pull request #2151 from zebrunner/develop
Browse files Browse the repository at this point in the history
8.0.10
  • Loading branch information
vdelendik authored Apr 1, 2023
2 parents 1e5f55c + e48a0c2 commit f1482ac
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*******************************************************************************/
package com.qaprosoft.carina.core.foundation;

import org.testng.ITestResult;
import org.testng.SkipException;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
Expand Down Expand Up @@ -65,11 +64,9 @@ private void onCarinaBeforeMethod() {
/**
* Carina AfterMethod<br>
* <b>For internal usage only - should not be overridden!</b>
*
* @param result see {@link ITestResult}. For {@link CarinaListener}
*/
@AfterMethod(alwaysRun = true)
default void onCarinaAfterMethod(ITestResult result) {
default void onCarinaAfterMethod() {
// do nothing
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
public class CarinaListener extends AbstractTestListener implements ISuiteListener, IQTestManager, ITestRailManager, IClassListener {
private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
protected static final long EXPLICIT_TIMEOUT = Configuration.getLong(Parameter.EXPLICIT_TIMEOUT);
private static final ThreadLocal<Boolean> IS_REMOVE_DRIVER = ThreadLocal.withInitial(() -> Boolean.FALSE);

protected static final String SUITE_TITLE = "%s%s%s - %s (%s)";
protected static final String XML_SUITE_NAME = " (%s)";
Expand Down Expand Up @@ -288,26 +289,18 @@ private void onConfigurationFinish(ITestResult configurationResult) {
ITestNGMethod testMethod = configurationResult.getMethod();
if (testMethod instanceof ConfigurationMethod) {
ConfigurationMethod configurationMethod = (ConfigurationMethod) testMethod;
if (configurationMethod.isAfterMethodConfiguration()) {
// we want to intercept IAbstractTest#onCarinaAfterMethod that have only one parameter -
// result of the test method
// We are not going to check amount of parameters / their type because it is our method
if (IAbstractTest.class.equals(configurationMethod.getRealClass()) &&
StringUtils.equals("onCarinaAfterMethod", configurationMethod.getMethodName())) {
ITestResult testMethodResult = (ITestResult) Arrays.stream(configurationResult.getParameters())
.filter(ITestResult.class::isInstance)
.findFirst()
.orElseThrow(() -> new RuntimeException("onCarinaAfterMethod should have ITestResult parameter"));

// result status == 2 means failure, status == 3 means skip. We need to quit driver anyway for failure and skip
if (((automaticDriversCleanup &&
!hasDependencies(testMethodResult)) ||
testMethodResult.getStatus() == 2 ||
testMethodResult.getStatus() == 3) &&
!Configuration.getBoolean(Parameter.FORCIBLY_DISABLE_DRIVER_QUIT)) {
quitDrivers(Phase.BEFORE_METHOD, Phase.METHOD);
}
if (configurationMethod.isAfterMethodConfiguration() &&
IAbstractTest.class.equals(configurationMethod.getRealClass()) &&
StringUtils.equals("onCarinaAfterMethod", configurationMethod.getMethodName())) {
// If an error occurs in afterMethod , then all subsequent test methods in the class? become skipped (if run in one thread).
// If this occurred (the number of threads is unimportant), then onCarinaAfterMethod received an incorrect ITestResult
// object
// (namely, as a result of calling result.getTestContext() on it, we got null, and when we tried to call .getSuite().getAllMethods()
// we got a NullPointerException. Also, the test method status was CREATED.
if (IS_REMOVE_DRIVER.get()) {
quitDrivers(Phase.BEFORE_METHOD, Phase.METHOD);
}
IS_REMOVE_DRIVER.remove();
}
}
}
Expand Down Expand Up @@ -379,8 +372,15 @@ private void onTestFinish(ITestResult result) {
R.ZAFIRA.clearTestProperties();
//remove thread proxy rule
com.zebrunner.carina.proxy.ProxyPool.clearThreadRule();

LOGGER.debug("Test result is : " + result.getStatus());
// result status == 2 means failure, status == 3 means skip. We need to quit driver anyway for failure and skip
if (((automaticDriversCleanup &&
!hasDependencies(result)) ||
result.getStatus() == 2 ||
result.getStatus() == 3) &&
!Configuration.getBoolean(Parameter.FORCIBLY_DISABLE_DRIVER_QUIT)) {
IS_REMOVE_DRIVER.set(Boolean.TRUE);
}
attachTestLabels(result);
} catch (Exception e) {
LOGGER.error("Exception in CarinaListener->onTestFinish!", e);
Expand Down

0 comments on commit f1482ac

Please sign in to comment.