Skip to content

Fix Steps lifecycle in Awaitility evaluations (fixes #1135) #1158

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion allure-awaitility/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ For more information about awaitility highly recommended look into [awaitility u


### Configuration examples
Single line for all awaitility conditions in project
Single line for all awaitility conditions in project
```java
Awaitility.setDefaultConditionEvaluationListener(new AllureAwaitilityListener());
```

And another line to prevent breaking allure lifecycle for Steps inside Awaitility evaluations
```java
Awaitility.pollInSameThread();
```

Moreover, it's possible logging only few unstable conditions with method `.conditionEvaluationListener()`
```java
final AtomicInteger atomicInteger = new AtomicInteger(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import io.qameta.allure.model.Status;
import io.qameta.allure.model.StepResult;
import io.qameta.allure.model.TestResult;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DynamicNode;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.Test;
Expand All @@ -38,6 +40,11 @@

class ConditionListenersPositiveTest {

@BeforeAll
static void setup() {
Awaitility.pollInSameThread();
}

/**
* Positive test to check proper allure steps generation.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ void reset() {

@BeforeEach
void setup() {
Awaitility.pollInSameThread();
Awaitility.setDefaultConditionEvaluationListener(new AllureAwaitilityListener());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ void reset() {

@BeforeEach
void setup() {
Awaitility.pollInSameThread();
Awaitility.setDefaultConditionEvaluationListener(new AllureAwaitilityListener());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* 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.awaitility;

import io.qameta.allure.model.Status;
import io.qameta.allure.model.TestResult;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.*;

import java.util.List;
import java.util.stream.Stream;

import static io.qameta.allure.test.RunUtils.runWithinTestContext;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;

public class MultipleConditionsTest {

@AfterEach
void reset() {
Awaitility.reset();
}

@BeforeEach
void setup() {
Awaitility.pollInSameThread();
Awaitility.setDefaultConditionEvaluationListener(new AllureAwaitilityListener());
}

@TestFactory
Stream<DynamicNode> bothAwaitilityStepsShouldAppearTest() {
final List<TestResult> testResult = runWithinTestContext(() -> {
await().with()
.alias("First waiting")
.until(() -> true);
await().with()
.alias("Second waiting")
.until(() -> true);
},
AllureAwaitilityListener::setLifecycle
).getTestResults();

return Stream.of(
DynamicTest.dynamicTest("Exactly 2 top level step for 2 awaitility condition", () ->
assertThat(testResult.get(0).getSteps())
.describedAs("Allure TestResult contains exactly 2 top level step for 2 awaitility condition")
.hasSize(2)
),
DynamicTest.dynamicTest("All top level step for all awaitility condition has PASSED", () ->
assertThat(testResult.get(0).getSteps())
.describedAs("Allure TestResult contains all top level step for all awaitility with PASSED condition")
.allMatch(step -> Status.PASSED.equals(step.getStatus()))
)
);
}

}
Loading