|
21 | 21 | import com.codeborne.selenide.logevents.SelenideLogger; |
22 | 22 | import io.qameta.allure.Allure; |
23 | 23 | import io.qameta.allure.model.Attachment; |
| 24 | +import io.qameta.allure.model.Stage; |
24 | 25 | import io.qameta.allure.model.Status; |
25 | 26 | import io.qameta.allure.model.StepResult; |
26 | 27 | import io.qameta.allure.test.AllureFeatures; |
27 | 28 | import io.qameta.allure.test.AllureResults; |
| 29 | +import org.junit.jupiter.api.AfterEach; |
| 30 | +import org.junit.jupiter.api.BeforeEach; |
28 | 31 | import org.junit.jupiter.api.Test; |
29 | 32 | import org.openqa.selenium.OutputType; |
| 33 | +import org.openqa.selenium.WebDriverException; |
30 | 34 | import org.openqa.selenium.chrome.ChromeDriver; |
31 | 35 |
|
32 | 36 | import java.nio.charset.StandardCharsets; |
|
42 | 46 | */ |
43 | 47 | class AllureSelenideTest { |
44 | 48 |
|
| 49 | + @BeforeEach |
| 50 | + @AfterEach |
| 51 | + void closeBrowser() { |
| 52 | + WebDriverRunner.closeWebDriver(); |
| 53 | + } |
| 54 | + |
45 | 55 | @AllureFeatures.Steps |
46 | 56 | @Test |
47 | 57 | void shouldLogPassedSteps() { |
@@ -175,6 +185,29 @@ void shouldSavePageSourceOnFail() { |
175 | 185 | .isEqualTo("dummy-page-source"); |
176 | 186 | } |
177 | 187 |
|
| 188 | + @AllureFeatures.Attachments |
| 189 | + @Test |
| 190 | + void shouldNotFailIfBrowserIsNotOpened() { |
| 191 | + final AllureResults results = runWithinTestContext(() -> { |
| 192 | + final AllureSelenide selenide = new AllureSelenide() |
| 193 | + .savePageSource(false) |
| 194 | + .screenshots(true); |
| 195 | + SelenideLogger.addListener(UUID.randomUUID().toString(), selenide); |
| 196 | + final SelenideLog log = SelenideLogger.beginStep( |
| 197 | + "open", |
| 198 | + "https://some.url" |
| 199 | + ); |
| 200 | + SelenideLogger.commitStep(log, new WebDriverException("failed to open a browser")); |
| 201 | + }); |
| 202 | + |
| 203 | + final StepResult selenideStep = extractStepFromResults(results); |
| 204 | + assertThat(selenideStep.getStatus()).isEqualTo(Status.BROKEN); |
| 205 | + assertThat(selenideStep.getStatusDetails().getMessage()).startsWith("failed to open a browser"); |
| 206 | + assertThat(selenideStep.getName()).isEqualTo("$(open) https://some.url"); |
| 207 | + assertThat(selenideStep.getStage()).isEqualTo(Stage.FINISHED); |
| 208 | + assertThat(selenideStep.getAttachments()).hasSize(0); |
| 209 | + } |
| 210 | + |
178 | 211 | @AllureFeatures.Steps |
179 | 212 | @Test |
180 | 213 | void shouldLogFailedSteps() { |
|
0 commit comments