Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix JBehave runtime API #1022

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.qameta.allure.model.StatusDetails;
import io.qameta.allure.model.StepResult;
import io.qameta.allure.model.TestResult;
import io.qameta.allure.util.ResultsUtils;
import org.jbehave.core.failures.UUIDExceptionWrapper;
import org.jbehave.core.model.ExamplesTable;
import org.jbehave.core.model.Scenario;
Expand Down Expand Up @@ -227,13 +228,15 @@ protected void startTestCase(final String uuid,
.map(entry -> createParameter(entry.getKey(), entry.getValue()))
.collect(Collectors.toList());

final List<Label> labels = Arrays.asList(
final List<Label> labels = new ArrayList<>(Arrays.asList(
createStoryLabel(story.getName()),
createHostLabel(),
createThreadLabel(),
createFrameworkLabel("jbehave"),
createLanguageLabel("java")
);
));

labels.addAll(ResultsUtils.getProvidedLabels());

final String historyId = getHistoryId(fullName, parameters);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

import io.qameta.allure.Issue;
import io.qameta.allure.jbehave5.samples.BrokenStorySteps;
import io.qameta.allure.jbehave5.samples.RuntimeApiSteps;
import io.qameta.allure.jbehave5.samples.SimpleStorySteps;
import io.qameta.allure.model.Attachment;
import io.qameta.allure.model.Label;
import io.qameta.allure.model.Parameter;
import io.qameta.allure.model.Stage;
import io.qameta.allure.model.Status;
Expand Down Expand Up @@ -259,6 +262,47 @@ void shouldNotFailIfGivenStoriesSpecified() {

}

@Test
void shouldSupportRuntimeApiInSteps() {
final AllureResults results = runStories("stories/runtimeapi.story");

assertThat(results.getTestResults())
.extracting(TestResult::getName, TestResult::getStatus)
.containsExactly(tuple("Runtime API", Status.PASSED));

assertThat(results.getTestResults())
.filteredOn("name", "Runtime API")
.flatExtracting(TestResult::getLabels)
.extracting(Label::getName, Label::getValue)
.contains(
tuple("jbehave-test-label", "some-value")
);

assertThat(results.getTestResults())
.filteredOn("name", "Runtime API")
.flatExtracting(TestResult::getSteps)
.filteredOn("name", "Given runtime api")
.flatExtracting(StepResult::getSteps)
.extracting(StepResult::getName)
.containsExactlyInAnyOrder("sub step 1", "sub step 2");

assertThat(results.getTestResults())
.filteredOn("name", "Runtime API")
.flatExtracting(TestResult::getParameters)
.extracting(Parameter::getName, Parameter::getValue)
.containsExactlyInAnyOrder(
tuple("test param", "param value")
);

assertThat(results.getTestResults())
.filteredOn("name", "Runtime API")
.flatExtracting(TestResult::getSteps)
.filteredOn("name", "Given runtime api")
.flatExtracting(StepResult::getAttachments)
.extracting(Attachment::getName)
.containsExactlyInAnyOrder("some attachment");
}

private AllureResults runStories(final String... storyResources) {
return RunUtils.runTests(lifecycle -> {
final Embedder embedder = new Embedder();
Expand All @@ -283,7 +327,8 @@ private AllureResults runStories(final String... storyResources) {
final InjectableStepsFactory stepsFactory = new InstanceStepsFactory(
embedder.configuration(),
new SimpleStorySteps(),
new BrokenStorySteps()
new BrokenStorySteps(),
new RuntimeApiSteps()
);
embedder.useStepsFactory(stepsFactory);
embedder.runStoriesAsPaths(Arrays.asList(storyResources));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2016-2024 Qameta Software Inc
*
* 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 io.qameta.allure.jbehave5.samples;

import io.qameta.allure.Allure;
import org.jbehave.core.annotations.Given;

public class RuntimeApiSteps {

@Given("runtime api")
public void given() {
Allure.label("jbehave-test-label", "some-value");
Allure.parameter("test param", "param value");
Allure.step("sub step 1");
Allure.step("sub step 2", () -> {
});

Allure.addAttachment("some attachment", "some content");
}

}
3 changes: 3 additions & 0 deletions allure-jbehave5/src/test/resources/stories/runtimeapi.story
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Scenario: Runtime API

Given runtime api
Loading