|
30 | 30 | import org.junit.jupiter.api.BeforeEach; |
31 | 31 | import org.junit.jupiter.api.Test; |
32 | 32 | import org.openqa.selenium.OutputType; |
33 | | -import org.openqa.selenium.WebDriverException; |
34 | 33 | import org.openqa.selenium.WebDriver.Options; |
| 34 | +import org.openqa.selenium.WebDriverException; |
35 | 35 | import org.openqa.selenium.chrome.ChromeDriver; |
36 | 36 | import org.openqa.selenium.logging.LogEntries; |
37 | 37 | import org.openqa.selenium.logging.LogEntry; |
@@ -191,6 +191,68 @@ void shouldSavePageSourceOnFail() { |
191 | 191 | .isEqualTo("dummy-page-source"); |
192 | 192 | } |
193 | 193 |
|
| 194 | + @AllureFeatures.Attachments |
| 195 | + @Test |
| 196 | + void shouldHaveHTMLPageSourceAsDefault() { |
| 197 | + final ChromeDriver wdMock = mock(ChromeDriver.class); |
| 198 | + WebDriverRunner.setWebDriver(wdMock); |
| 199 | + doReturn("html-page-source") |
| 200 | + .when(wdMock).getPageSource(); |
| 201 | + |
| 202 | + final AllureResults results = runWithinTestContext(() -> { |
| 203 | + final AllureSelenide selenide = new AllureSelenide() |
| 204 | + .screenshots(false) |
| 205 | + .savePageSource(true); |
| 206 | + SelenideLogger.addListener(UUID.randomUUID().toString(), selenide); |
| 207 | + final SelenideLog log = SelenideLogger.beginStep( |
| 208 | + "dummy source", |
| 209 | + "dummyMethod()", |
| 210 | + "param1", |
| 211 | + "param2" |
| 212 | + ); |
| 213 | + SelenideLogger.commitStep(log, new Exception("something went wrong")); |
| 214 | + }); |
| 215 | + |
| 216 | + final StepResult selenideStep = extractStepFromResults(results); |
| 217 | + assertThat(selenideStep.getAttachments()) |
| 218 | + .hasSize(1); |
| 219 | + |
| 220 | + final Attachment attachment = selenideStep.getAttachments().iterator().next(); |
| 221 | + assertThat(attachment.getType()).isEqualTo("text/html"); |
| 222 | + } |
| 223 | + |
| 224 | + @AllureFeatures.Attachments |
| 225 | + @Test |
| 226 | + void shouldAllowToConfigurePageSource() { |
| 227 | + final String sourceType = "text/xml"; |
| 228 | + final ChromeDriver wdMock = mock(ChromeDriver.class); |
| 229 | + WebDriverRunner.setWebDriver(wdMock); |
| 230 | + doReturn("xml-page-source") |
| 231 | + .when(wdMock).getPageSource(); |
| 232 | + |
| 233 | + final AllureResults results = runWithinTestContext(() -> { |
| 234 | + final AllureSelenide selenide = new AllureSelenide() |
| 235 | + .screenshots(false) |
| 236 | + .savePageSource(true) |
| 237 | + .configureSource(sourceType, "xml"); |
| 238 | + SelenideLogger.addListener(UUID.randomUUID().toString(), selenide); |
| 239 | + final SelenideLog log = SelenideLogger.beginStep( |
| 240 | + "dummy source", |
| 241 | + "dummyMethod()", |
| 242 | + "param1", |
| 243 | + "param2" |
| 244 | + ); |
| 245 | + SelenideLogger.commitStep(log, new Exception("something went wrong")); |
| 246 | + }); |
| 247 | + |
| 248 | + final StepResult selenideStep = extractStepFromResults(results); |
| 249 | + assertThat(selenideStep.getAttachments()) |
| 250 | + .hasSize(1); |
| 251 | + |
| 252 | + final Attachment attachment = selenideStep.getAttachments().iterator().next(); |
| 253 | + assertThat(attachment.getType()).isEqualTo(sourceType); |
| 254 | + } |
| 255 | + |
194 | 256 | @AllureFeatures.Attachments |
195 | 257 | @Test |
196 | 258 | void shouldNotFailIfBrowserIsNotOpened() { |
|
0 commit comments