|
| 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.awaitility; |
| 17 | + |
| 18 | +import io.qameta.allure.model.Status; |
| 19 | +import io.qameta.allure.model.TestResult; |
| 20 | +import org.awaitility.Awaitility; |
| 21 | +import org.junit.jupiter.api.*; |
| 22 | + |
| 23 | +import java.util.List; |
| 24 | +import java.util.stream.Stream; |
| 25 | + |
| 26 | +import static io.qameta.allure.test.RunUtils.runWithinTestContext; |
| 27 | +import static org.assertj.core.api.Assertions.assertThat; |
| 28 | +import static org.awaitility.Awaitility.await; |
| 29 | + |
| 30 | +public class MultipleConditionsTest { |
| 31 | + |
| 32 | + @AfterEach |
| 33 | + void reset() { |
| 34 | + Awaitility.reset(); |
| 35 | + } |
| 36 | + |
| 37 | + @BeforeEach |
| 38 | + void setup() { |
| 39 | + Awaitility.pollInSameThread(); |
| 40 | + Awaitility.setDefaultConditionEvaluationListener(new AllureAwaitilityListener()); |
| 41 | + } |
| 42 | + |
| 43 | + @TestFactory |
| 44 | + Stream<DynamicNode> bothAwaitilityStepsShouldAppearTest() { |
| 45 | + final List<TestResult> testResult = runWithinTestContext(() -> { |
| 46 | + await().with() |
| 47 | + .alias("First waiting") |
| 48 | + .until(() -> true); |
| 49 | + await().with() |
| 50 | + .alias("Second waiting") |
| 51 | + .until(() -> true); |
| 52 | + }, |
| 53 | + AllureAwaitilityListener::setLifecycle |
| 54 | + ).getTestResults(); |
| 55 | + |
| 56 | + return Stream.of( |
| 57 | + DynamicTest.dynamicTest("Exactly 2 top level step for 2 awaitility condition", () -> |
| 58 | + assertThat(testResult.get(0).getSteps()) |
| 59 | + .describedAs("Allure TestResult contains exactly 2 top level step for 2 awaitility condition") |
| 60 | + .hasSize(2) |
| 61 | + ), |
| 62 | + DynamicTest.dynamicTest("All top level step for all awaitility condition has PASSED", () -> |
| 63 | + assertThat(testResult.get(0).getSteps()) |
| 64 | + .describedAs("Allure TestResult contains all top level step for all awaitility with PASSED condition") |
| 65 | + .allMatch(step -> Status.PASSED.equals(step.getStatus())) |
| 66 | + ) |
| 67 | + ); |
| 68 | + } |
| 69 | + |
| 70 | +} |
0 commit comments