-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add key-value attribute reporting example
- Loading branch information
Showing
4 changed files
with
96 additions
and
2 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
...in/java/com/epam/reportportal/example/cucumber6/attributes/KeyValueAttributeReporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright 2022 EPAM Systems | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.epam.reportportal.example.cucumber6.attributes; | ||
|
||
import com.epam.reportportal.cucumber.ScenarioReporter; | ||
import com.epam.ta.reportportal.ws.model.StartTestItemRQ; | ||
import com.epam.ta.reportportal.ws.model.attribute.ItemAttributeResource; | ||
import com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ; | ||
import io.cucumber.plugin.event.TestCase; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.net.URI; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Attribute Reporter to demonstrate attribute customization for different cases. | ||
*/ | ||
public class KeyValueAttributeReporter extends ScenarioReporter { | ||
public static final String ATTRIBUTE_VALUE_SEPARATOR = ":"; | ||
|
||
private static void processKeyValueAttributes(StartTestItemRQ rq) { | ||
rq.setAttributes(rq.getAttributes().stream().map(ItemAttributeResource::getValue).filter(Objects::nonNull).map(attr -> { | ||
if (attr.contains(ATTRIBUTE_VALUE_SEPARATOR)) { | ||
String[] parts = attr.split(ATTRIBUTE_VALUE_SEPARATOR, 2); | ||
return new ItemAttributesRQ(parts[0].trim(), parts[1].trim()); | ||
} else { | ||
return new ItemAttributesRQ(null, attr); | ||
} | ||
}).collect(Collectors.toUnmodifiableSet())); | ||
} | ||
|
||
@Override | ||
@Nonnull | ||
protected StartTestItemRQ buildStartScenarioRequest(@Nonnull TestCase testCase, @Nonnull String name, @Nonnull URI uri, int line) { | ||
StartTestItemRQ rq = super.buildStartScenarioRequest(testCase, name, uri, line); | ||
processKeyValueAttributes(rq); | ||
return rq; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
.../test/java/com/epam/reportportal/example/cucumber6/RunAttributesKeyValueReporterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright 2021 EPAM Systems | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.epam.reportportal.example.cucumber6; | ||
|
||
import io.cucumber.junit.Cucumber; | ||
import io.cucumber.junit.CucumberOptions; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(Cucumber.class) | ||
@CucumberOptions( | ||
plugin = { "pretty", "html:report.html", "com.epam.reportportal.example.cucumber6.attributes.KeyValueAttributeReporter" }, | ||
features = "src/test/resources/features/attributes/key-value.feature", | ||
tags = "not @ignore", | ||
glue = "com.epam.reportportal.example.cucumber6.attributes") | ||
public class RunAttributesKeyValueReporterTest { | ||
} |
7 changes: 7 additions & 0 deletions
7
example-cucumber6/src/test/resources/features/attributes/key-value.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Feature: Belly | ||
|
||
@MyAttribute:MyValue | ||
Scenario: a few cukes | ||
Given I have 42 cukes in my belly | ||
When I wait 1 hour | ||
Then my belly should growl |