From a9441708ee68261a4ee2069a974e519e719c9446 Mon Sep 17 00:00:00 2001 From: Factor Date: Thu, 20 Mar 2025 19:29:17 +0100 Subject: [PATCH] Enhance test hooks with improved configuration and screenshots Updated browser configuration for better resolution and enabled screenshots on failures. Implemented automatic screenshot attachment for failed scenarios to enhance debugging and reporting. Minor refactors and improvements for clarity and functionality. --- src/test/java/steps/Hooks.java | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/test/java/steps/Hooks.java b/src/test/java/steps/Hooks.java index ba2fbd4..75e7f14 100644 --- a/src/test/java/steps/Hooks.java +++ b/src/test/java/steps/Hooks.java @@ -1,12 +1,16 @@ package steps; import com.codeborne.selenide.Configuration; +import com.codeborne.selenide.Selenide; import io.cucumber.java.After; import io.cucumber.java.Before; import io.cucumber.java.Scenario; import lombok.extern.slf4j.Slf4j; +import org.openqa.selenium.OutputType; import org.openqa.selenium.chrome.ChromeOptions; +import java.util.concurrent.TimeUnit; + import static frameworkContext.ContextFactory.instantiateContextObject; @Slf4j @@ -21,24 +25,28 @@ public class Hooks { Configuration.browserCapabilities = options; Configuration.browser = "chrome"; - Configuration.timeout = 30000; + Configuration.timeout = TimeUnit.SECONDS.toMillis(30); + ; Configuration.pollingInterval = 500; - Configuration.browserSize = "1920x1080"; + Configuration.browserSize = "1920x1200"; Configuration.headless = true; + Configuration.screenshots = true; + + Configuration.reportsFolder = "target/screenshots/"; log.info("Start scenario: {}", scenario.getName()); } @After public void exit(Scenario scenario) { - genericAfter(scenario); - } - - private void genericAfter(Scenario scenario) { if (scenario.isFailed()) { - log.error("Scenario error"); + makeAndAttachScreenshot(scenario); } - log.info("Finished scenario: {}", scenario.getName()); } + + private void makeAndAttachScreenshot(Scenario scenario) { + byte[] screenshot = Selenide.screenshot(OutputType.BYTES); + scenario.attach(screenshot, "image/png", "Screenshot"); + } } \ No newline at end of file