Skip to content
This repository has been archived by the owner on Nov 15, 2024. It is now read-only.

Commit

Permalink
Common Stack Trace frames skip in logs
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Nov 15, 2024
1 parent 344d9b3 commit 587fa87
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 26 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Changelog
### Changed
- Client version updated on [5.2.21](https://github.com/reportportal/client-java/releases/tag/5.2.21), by @HardNorth

## [Unreleased]
### Added
- Common Stack Trace frames skip in logs, by @HardNorth
### Changed
- Client version updated on [5.2.14](https://github.com/reportportal/client-java/releases/tag/5.2.14), by @HardNorth
- Client version updated on [5.2.21](https://github.com/reportportal/client-java/releases/tag/5.2.21), by @HardNorth

## [5.2.2]
### Changed
Expand Down
56 changes: 33 additions & 23 deletions src/main/java/com/epam/reportportal/cucumber/AbstractReporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import com.epam.reportportal.service.tree.TestItemTree;
import com.epam.reportportal.utils.*;
import com.epam.reportportal.utils.files.ByteSource;
import com.epam.reportportal.utils.formatting.MarkdownUtils;
import com.epam.reportportal.utils.http.ContentType;
import com.epam.reportportal.utils.markdown.MarkdownUtils;
import com.epam.reportportal.utils.properties.SystemAttributesExtractor;
import com.epam.ta.reportportal.ws.model.FinishExecutionRQ;
import com.epam.ta.reportportal.ws.model.FinishTestItemRQ;
Expand Down Expand Up @@ -66,10 +66,10 @@
import static com.epam.reportportal.cucumber.Utils.*;
import static com.epam.reportportal.cucumber.util.ItemTreeUtils.createKey;
import static com.epam.reportportal.cucumber.util.ItemTreeUtils.retrieveLeaf;
import static com.epam.reportportal.utils.formatting.ExceptionUtils.getStackTrace;
import static java.util.Optional.of;
import static java.util.Optional.ofNullable;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace;

/**
* Abstract Cucumber 2.x formatter for Report Portal
Expand Down Expand Up @@ -312,11 +312,13 @@ protected RunningContext.ScenarioContext getCurrentScenarioContext() {
* @param scenarioContext current scenario context
*/
protected void beforeScenario(RunningContext.FeatureContext featureContext, RunningContext.ScenarioContext scenarioContext) {
String scenarioName = Utils.buildName(scenarioContext.getKeyword(),
String scenarioName = Utils.buildName(
scenarioContext.getKeyword(),
AbstractReporter.COLON_INFIX,
scenarioContext.getTestCase().getName()
);
Maybe<String> id = startScenario(featureContext.getFeatureId(),
Maybe<String> id = startScenario(
featureContext.getFeatureId(),
buildStartScenarioRequest(scenarioContext.getTestCase(), scenarioName, featureContext.getUri(), scenarioContext.getLine())
);
scenarioContext.setId(id);
Expand Down Expand Up @@ -381,7 +383,8 @@ protected Maybe<String> startStep(@Nonnull Maybe<String> scenarioId, @Nonnull St
}

private void addToTree(RunningContext.ScenarioContext scenarioContext, String text, Maybe<String> stepId) {
retrieveLeaf(scenarioContext.getFeatureUri(),
retrieveLeaf(
scenarioContext.getFeatureUri(),
scenarioContext.getLine(),
ITEM_TREE
).ifPresent(scenarioLeaf -> scenarioLeaf.getChildItems().put(createKey(text), TestItemTree.createTestItemLeaf(stepId)));
Expand Down Expand Up @@ -436,8 +439,8 @@ protected StartTestItemRQ buildStartHookRequest(HookType hookType) {
/**
* Start before/after-hook item on Report Portal
*
* @param parentId parent item id
* @param rq hook start request
* @param parentId parent item id
* @param rq hook start request
* @return hook item id
*/
@Nonnull
Expand Down Expand Up @@ -514,7 +517,7 @@ protected void reportResult(Result result, String message) {
if (errorMessage != null) {
sendLog(errorMessage, level);
} else if (result.getError() != null) {
sendLog(getStackTrace(result.getError()), level);
sendLog(getStackTrace(result.getError(), new Throwable()), level);
}
}

Expand All @@ -537,7 +540,8 @@ private static String getDataType(@Nonnull byte[] data) {
protected void embedding(String mimeType, byte[] data) {
String type = ofNullable(mimeType).filter(ContentType::isValidType).orElseGet(() -> getDataType(data));
String attachmentName = ofNullable(type).map(t -> t.substring(0, t.indexOf("/"))).orElse("");
ReportPortal.emitLog(new ReportPortalMessage(ByteSource.wrap(data), type, attachmentName),
ReportPortal.emitLog(
new ReportPortalMessage(ByteSource.wrap(data), type, attachmentName),
"UNKNOWN",
Calendar.getInstance().getTime()
);
Expand Down Expand Up @@ -625,25 +629,29 @@ protected void handleStartOfTestCase(TestCaseStarted event) {
TestCase testCase = event.testCase;
RunningContext.FeatureContext newFeatureContext = new RunningContext.FeatureContext(testCase);
String featureUri = newFeatureContext.getUri();
RunningContext.FeatureContext featureContext = currentFeatureContextMap.computeIfAbsent(featureUri, u -> {
getRootItemId(); // trigger root item creation
newFeatureContext.setFeatureId(startFeature(buildStartFeatureRequest(newFeatureContext.getFeature(), featureUri)));
if (launch.get().getParameters().isCallbackReportingEnabled()) {
addToTree(newFeatureContext);
}
return newFeatureContext;
});
RunningContext.FeatureContext featureContext = currentFeatureContextMap.computeIfAbsent(
featureUri, u -> {
getRootItemId(); // trigger root item creation
newFeatureContext.setFeatureId(startFeature(buildStartFeatureRequest(newFeatureContext.getFeature(), featureUri)));
if (launch.get().getParameters().isCallbackReportingEnabled()) {
addToTree(newFeatureContext);
}
return newFeatureContext;
}
);

if (!featureContext.getUri().equals(testCase.getUri())) {
throw new IllegalStateException("Scenario URI does not match Feature URI.");
}

RunningContext.ScenarioContext newScenarioContext = featureContext.getScenarioContext(testCase);
Pair<Integer, String> scenarioLineFeatureURI = Pair.of(newScenarioContext.getLine(), featureContext.getUri());
RunningContext.ScenarioContext scenarioContext = currentScenarioContextMap.computeIfAbsent(scenarioLineFeatureURI, k -> {
currentScenarioContext.set(newScenarioContext);
return newScenarioContext;
});
RunningContext.ScenarioContext scenarioContext = currentScenarioContextMap.computeIfAbsent(
scenarioLineFeatureURI, k -> {
currentScenarioContext.set(newScenarioContext);
return newScenarioContext;
}
);

beforeScenario(featureContext, scenarioContext);
}
Expand Down Expand Up @@ -714,7 +722,8 @@ protected ItemStatus mapItemStatus(@Nullable Result.Type status) {
return null;
} else {
if (STATUS_MAPPING.get(status) == null) {
LOGGER.error(String.format("Unable to find direct mapping between Cucumber and ReportPortal for TestItem with status: '%s'.",
LOGGER.error(String.format(
"Unable to find direct mapping between Cucumber and ReportPortal for TestItem with status: '%s'.",
status
));
return ItemStatus.SKIPPED;
Expand Down Expand Up @@ -906,7 +915,8 @@ protected TestCaseIdEntry getTestCaseId(@Nonnull TestStep testStep, @Nullable St
if (definitionMatch != null) {
try {
Method method = retrieveMethod(definitionMatch);
return TestCaseIdUtils.getTestCaseId(method.getAnnotation(TestCaseId.class),
return TestCaseIdUtils.getTestCaseId(
method.getAnnotation(TestCaseId.class),
method,
codeRef,
(List<Object>) ARGUMENTS_TRANSFORM.apply(testStep.getDefinitionArgument())
Expand Down

0 comments on commit 587fa87

Please sign in to comment.