Skip to content

Commit c2268cb

Browse files
authored
fix jbehave runtime api (via #1022)
1 parent 6ff650c commit c2268cb

File tree

4 files changed

+88
-3
lines changed

4 files changed

+88
-3
lines changed

allure-jbehave5/src/main/java/io/qameta/allure/jbehave5/AllureJbehave5.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import io.qameta.allure.model.StatusDetails;
2525
import io.qameta.allure.model.StepResult;
2626
import io.qameta.allure.model.TestResult;
27+
import io.qameta.allure.util.ResultsUtils;
2728
import org.jbehave.core.failures.UUIDExceptionWrapper;
2829
import org.jbehave.core.model.ExamplesTable;
2930
import org.jbehave.core.model.Scenario;
@@ -227,13 +228,15 @@ protected void startTestCase(final String uuid,
227228
.map(entry -> createParameter(entry.getKey(), entry.getValue()))
228229
.collect(Collectors.toList());
229230

230-
final List<Label> labels = Arrays.asList(
231+
final List<Label> labels = new ArrayList<>(Arrays.asList(
231232
createStoryLabel(story.getName()),
232233
createHostLabel(),
233234
createThreadLabel(),
234235
createFrameworkLabel("jbehave"),
235236
createLanguageLabel("java")
236-
);
237+
));
238+
239+
labels.addAll(ResultsUtils.getProvidedLabels());
237240

238241
final String historyId = getHistoryId(fullName, parameters);
239242

allure-jbehave5/src/test/java/io/qameta/allure/jbehave5/AllureJbehave5Test.java

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717

1818
import io.qameta.allure.Issue;
1919
import io.qameta.allure.jbehave5.samples.BrokenStorySteps;
20+
import io.qameta.allure.jbehave5.samples.RuntimeApiSteps;
2021
import io.qameta.allure.jbehave5.samples.SimpleStorySteps;
22+
import io.qameta.allure.model.Attachment;
23+
import io.qameta.allure.model.Label;
2124
import io.qameta.allure.model.Parameter;
2225
import io.qameta.allure.model.Stage;
2326
import io.qameta.allure.model.Status;
@@ -259,6 +262,47 @@ void shouldNotFailIfGivenStoriesSpecified() {
259262

260263
}
261264

265+
@Test
266+
void shouldSupportRuntimeApiInSteps() {
267+
final AllureResults results = runStories("stories/runtimeapi.story");
268+
269+
assertThat(results.getTestResults())
270+
.extracting(TestResult::getName, TestResult::getStatus)
271+
.containsExactly(tuple("Runtime API", Status.PASSED));
272+
273+
assertThat(results.getTestResults())
274+
.filteredOn("name", "Runtime API")
275+
.flatExtracting(TestResult::getLabels)
276+
.extracting(Label::getName, Label::getValue)
277+
.contains(
278+
tuple("jbehave-test-label", "some-value")
279+
);
280+
281+
assertThat(results.getTestResults())
282+
.filteredOn("name", "Runtime API")
283+
.flatExtracting(TestResult::getSteps)
284+
.filteredOn("name", "Given runtime api")
285+
.flatExtracting(StepResult::getSteps)
286+
.extracting(StepResult::getName)
287+
.containsExactlyInAnyOrder("sub step 1", "sub step 2");
288+
289+
assertThat(results.getTestResults())
290+
.filteredOn("name", "Runtime API")
291+
.flatExtracting(TestResult::getParameters)
292+
.extracting(Parameter::getName, Parameter::getValue)
293+
.containsExactlyInAnyOrder(
294+
tuple("test param", "param value")
295+
);
296+
297+
assertThat(results.getTestResults())
298+
.filteredOn("name", "Runtime API")
299+
.flatExtracting(TestResult::getSteps)
300+
.filteredOn("name", "Given runtime api")
301+
.flatExtracting(StepResult::getAttachments)
302+
.extracting(Attachment::getName)
303+
.containsExactlyInAnyOrder("some attachment");
304+
}
305+
262306
private AllureResults runStories(final String... storyResources) {
263307
return RunUtils.runTests(lifecycle -> {
264308
final Embedder embedder = new Embedder();
@@ -283,7 +327,8 @@ private AllureResults runStories(final String... storyResources) {
283327
final InjectableStepsFactory stepsFactory = new InstanceStepsFactory(
284328
embedder.configuration(),
285329
new SimpleStorySteps(),
286-
new BrokenStorySteps()
330+
new BrokenStorySteps(),
331+
new RuntimeApiSteps()
287332
);
288333
embedder.useStepsFactory(stepsFactory);
289334
embedder.runStoriesAsPaths(Arrays.asList(storyResources));
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2016-2024 Qameta Software Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.qameta.allure.jbehave5.samples;
17+
18+
import io.qameta.allure.Allure;
19+
import org.jbehave.core.annotations.Given;
20+
21+
public class RuntimeApiSteps {
22+
23+
@Given("runtime api")
24+
public void given() {
25+
Allure.label("jbehave-test-label", "some-value");
26+
Allure.parameter("test param", "param value");
27+
Allure.step("sub step 1");
28+
Allure.step("sub step 2", () -> {
29+
});
30+
31+
Allure.addAttachment("some attachment", "some content");
32+
}
33+
34+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Scenario: Runtime API
2+
3+
Given runtime api

0 commit comments

Comments
 (0)