/
koskv
/
TeamSync-Tests
Обзор
Документация
Войти
/
koskv
/
TeamSync-Tests
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/main/java/TeamSyncTest/exceptions/ScreenshotOnFailureExtension.java
33 строки
1 KB
Koskv
26-09-2025 commit
26 сен 2025, 08:58
26 сен 2025, 08:58
e45aa2b
Код
Авторство
О чём код?
package TeamSyncTest.exceptions; import com.codeborne.selenide.WebDriverRunner; import io.qameta.allure.Attachment; import org.junit.jupiter.api.extension.AfterTestExecutionCallback; import org.junit.jupiter.api.extension.ExtensionContext; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebDriver; public class ScreenshotOnFailureExtension implements AfterTestExecutionCallback { @Override public void afterTestExecution(ExtensionContext context) throws Exception { if (context.getExecutionException().isPresent()) { takeScreenshotOnFailure(); captureUrlOnFailure(); } } @Attachment(value = "Screenshot on failure", type = "image/png") public static byte[] takeScreenshotOnFailure() { WebDriver driver = WebDriverRunner.getWebDriver(); if (driver instanceof TakesScreenshot) { return ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES); } return new byte[0]; } @Attachment(value = "Page URL on failure", type = "text/plain") public static String captureUrlOnFailure() { return WebDriverRunner.url(); } }