/
koskv
/
TeamSync-Tests
Обзор
Документация
Войти
/
koskv
/
TeamSync-Tests
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/main/java/TeamSyncTest/config/SelenideConfig.java
153 строки
6 KB
Koskv
REF: CICD - добавлено развертывание БД в докере из дампа
23 ноя 2025, 21:08
23 ноя 2025, 21:08
fe402ff
Код
Авторство
О чём код?
package TeamSyncTest.config; import TeamSyncTest.constants.Urls; import TeamSyncTest.exceptions.ScreenshotOnFailureExtension; import TeamSyncTest.pages.HeaderPage; import com.codeborne.selenide.Configuration; import com.codeborne.selenide.FileDownloadMode; import com.codeborne.selenide.Selenide; import com.codeborne.selenide.WebDriverRunner; import com.codeborne.selenide.logevents.SelenideLogger; import io.qameta.allure.*; import io.qameta.allure.Allure; import io.qameta.allure.Attachment; import io.qameta.allure.Description; import io.qameta.allure.Epic; import io.qameta.allure.Link; import io.qameta.allure.Owner; import io.qameta.allure.Severity; import io.qameta.allure.SeverityLevel; import io.qameta.allure.Step; import io.qameta.allure.selenide.AllureSelenide; import org.junit.jupiter.api.*; import org.junit.jupiter.api.extension.ExtendWith; import org.openqa.selenium.OutputType; import org.openqa.selenium.chrome.ChromeOptions; import java.io.ByteArrayInputStream; @ExtendWith(ScreenshotOnFailureExtension.class) @Epic("UI Automation") //@Feature("Selenide Configuration") @Owner("TeamSync AQA team") @Severity(SeverityLevel.CRITICAL) @Link(name = "Selenide Documentation", url = "https://selenide.org") @DisplayName("Selenide Configuration and Setup") public class SelenideConfig { private static final String DRIVER_PATH = "src/main/resources/WebDriver/"; // protected static final String BROWSER = Browser.FIREFOX.getDisplayName(); // Финализировано protected static final String BROWSER = Browser.CHROME.getDisplayName(); // Финализировано private long startTime; @BeforeAll @Step("Initialize Selenide Configuration") @DisplayName("Setup Selenide Configuration") @Description("Configure browser settings, capabilities, and Allure integration") public static void setup() { io.qameta.allure.Allure.label("layer", "ui"); Allure.label("tool", "selenide"); Allure.label("browser", "chrome"); Configuration.browser = "chrome"; // или "firefox", но лучше chrome для headless Configuration.browserSize = "1900x1050"; Configuration.timeout = 10000; Configuration.fileDownload = FileDownloadMode.FOLDER; Configuration.headless = true; // обязательно для Docker или CI = true Configuration.screenshots = false; Configuration.fastSetValue = true; // Настройка Chrome (опционально, но рекомендуется для headless) ChromeOptions options = new ChromeOptions(); options.addArguments( "--no-sandbox", "--disable-dev-shm-usage", "--disable-gpu", "--disable-extensions", "--disable-notifications", "--incognito" ); Configuration.browserCapabilities = options; // Логирование в Allure SelenideLogger.addListener("allure", new AllureSelenide() .includeSelenideSteps(false) .savePageSource(true) .screenshots(true) ); Allure.addAttachment("Browser Configuration", "text/plain", "Browser: " + Configuration.browser + "\n" + "Headless: " + Configuration.headless + "\n" + "Timeout: " + Configuration.timeout + "\n" + "Browser Size: " + Configuration.browserSize ); } @BeforeEach @Step("Open Base URL: {Urls.BASE_URL}") @DisplayName("Open Application") @Description("Navigate to the base URL before each test") void openBaseURL() { startTime = System.currentTimeMillis(); Selenide.open(Urls.BASE_URL); Selenide.executeJavaScript("document.body.style.zoom='1'"); String browserInfo = WebDriverRunner.getWebDriver().getClass().getSimpleName(); System.out.println("Выбран браузер: " + WebDriverRunner.getWebDriver().getClass().getSimpleName()); Allure.addAttachment("Browser Session", "text/plain", "Browser: " + browserInfo + "\n" + "URL: " + Urls.BASE_URL + "\n" + "Session Started: " + java.time.LocalDateTime.now() ); } @AfterEach @Step("Close WebDriver and Collect Metrics") @DisplayName("Teardown Test") @Description("Close browser and collect performance metrics") public void tearDown() { long endTime = System.currentTimeMillis(); // Запоминаем время окончания теста long duration = endTime - startTime; // Вычисляем длительность String performanceMetrics = String.format( "Test Duration: %d ms\nStart Time: %d\nEnd Time: %d", duration, startTime, endTime ); Allure.addAttachment("Performance Metrics", "text/plain", performanceMetrics); System.out.println("Тест выполнен за: " + duration + " мс"); Selenide.closeWebDriver(); Allure.addAttachment("Session Closed", "text/plain", "WebDriver closed at: " + java.time.LocalDateTime.now() ); } // Helper method for test classes @Step("Take screenshot with description: {description}") @DisplayName("Capture Screenshot") public static void captureScreenshot(String description) { byte[] screenshot = Selenide.screenshot(OutputType.BYTES); if (screenshot != null) { Allure.addAttachment(description, "image/png", new ByteArrayInputStream(screenshot), ".png"); } } //----------------------------------------------------------------------------------------- @Step("Выполнить авторизацию с пользователем {customUsername}") @DisplayName("Login with custom credentials") protected void login(String customUsername, String customPassword) { new HeaderPage() .login() .loginSuccess(customUsername, customPassword) .getGreatingUsers(); } }