Jenkins не собирается сборка с включенным UI браузера

Хочу собрать сборку в дженкинсе. Проект на градле
При инициализации хромдрайвера без интерфейса все собирается

WebDriverManager.chromedriver().driverVersion("114").setup();
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--no-sandbox", "--headless", "--disable-dev-shm-usage");
         driver = new ChromeDriver(options);

Если без options, но вот такая ошибка

Test1 > initializationError FAILED

org.openqa.selenium.SessionNotCreatedException at ProtocolHandshake.java:140

Test2 > initializationError FAILED

org.openqa.selenium.SessionNotCreatedException at ProtocolHandshake.java:140

2 tests completed, 2 failed

Task :test FAILED

FAILURE: Build failed with an exception.

  • What went wrong:

Execution failed for task ‘:test’.

There were failing tests. See the report at: file:///var/jenkins_home/workspace/test/build/reports/tests/test/index.html

  • Try:

Run with --stacktrace option to get the stack trace.

Run with --info or --debug option to get more log output.

Run with --scan to get full insights.

BUILD FAILED in 19s

4 actionable tasks: 4 executed

Build step ‘Execute shell’ marked build as failure

[test] $ /var/jenkins_home/tools/ru.yandex.qatools.allure.jenkins.tools.AllureCommandlineInstallation/allure_jenkins/bin/allure generate /var/jenkins_home/workspace/test/build/allure-results -c -o /var/jenkins_home/workspace/test/allure-report

Report successfully generated to /var/jenkins_home/workspace/test/allure-report

Allure report was successfully generated.

Creating artifact for the build.

Artifact was added to the build.

Finished: FAILURE

Сборка в дженкинсе через шелл

chmod +x gradlew
./gradlew clean test

Ставить драйвер через System,setPropery пробовал
В вебдрайвер менеджер ставлю 114 версию хрома, но я пробовал это убирать - безрезультатно

совсем забыл, мой докер файл

FROM jenkins/jenkins:2.401.2-jdk11
USER root
RUN apt-get update && apt-get install -y lsb-release
RUN curl -fsSLo /usr/share/keyrings/docker-archive-keyring.asc
https://download.docker.com/linux/debian/gpg
RUN echo “deb [arch=$(dpkg --print-architecture)
signed-by=/usr/share/keyrings/docker-archive-keyring.asc]
Index of linux/debian/
$(lsb_release -cs) stable” > /etc/apt/sources.list.d/docker.list

Chrome instalation

RUN curl -LO https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN apt-get install -y ./google-chrome-stable_current_amd64.deb
RUN rm google-chrome-stable_current_amd64.deb

Check chrome version

RUN echo "Chrome: " && google-chrome --version

RUN apt-get update && apt-get install -y docker-ce-cli
USER jenkins
RUN jenkins-plugin-cli --plugins “blueocean docker-workflow”

без графики не заработает

ставьте xvfb или vnc и запускайте с дисплеем

спойлер - это довольно затратно

2 лайка

А если тогда как то изменить инициализацию драйвера? Если запускает дженкинс, то с такими опциями. Делать параллельную ветку, которая бы отличалась только инициализацией тоже наверное не лучший выход

Инициализация драйвера выглядит так:

package common;

import dataproviders.ConfigDataProvider;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;

import java.time.Duration;

import static common.Browsers.valueOf;
import static common.Constant.TimeoutVariable.IMPLICIT_WAIT;

public class DriverActions {

private static ThreadLocal<WebDriver> localDriver = new ThreadLocal<>();
private static DriverActions instance;

public static DriverActions getInstance() {
    if (instance == null)
        instance = new DriverActions();
    return instance;
}

public WebDriver getDriver() {
    if (localDriver.get() == null) {
        String browser = ConfigDataProvider.getInstance().getBrowser();
        String isHeadless = System.getProperty("headless");
        switch (valueOf(browser)) {
            case EDGE:
                WebDriverManager.edgedriver().setup();
                EdgeOptions edgeOptions = new EdgeOptions();
                edgeOptions.setAcceptInsecureCerts(true);
                if (System.getProperty("headless") != null) {
                    edgeOptions.setHeadless(Boolean.parseBoolean(isHeadless));
                }
                localDriver.set(new EdgeDriver(edgeOptions));
                break;
            case CHROME:
                WebDriverManager.chromedriver().setup();
                ChromeOptions chromeOptions = new ChromeOptions();
                chromeOptions.setAcceptInsecureCerts(true);
                chromeOptions.addArguments("--remote-allow-origins=*");
                if (System.getProperty("headless") != null) {
                    chromeOptions.setHeadless(Boolean.parseBoolean(isHeadless));
                }
                localDriver.set(new ChromeDriver(chromeOptions));
                break;
            default:
                throw new IllegalStateException("Unexpected value: " + browser);
        }
    }
    WebDriver driver = localDriver.get();
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(IMPLICIT_WAIT));
    return driver;
}

public void quitDriver() {
    if (localDriver.get() != null) {
        localDriver.get().quit();
    }
    localDriver.remove();
}

}

https://snakeboost.readthedocs.io/en/latest/enhancers/xvfbrun.html

xvfb -run is a linux utility that starts a virtual X-server. This is useful for performing rendering jobs on headless servers and cluster environments, as an easier alternative to X-11 forwarding with SSH.
Computers without graphic support, such as compute clusters, cannot typically run commands requiring and x-server (browsers)The XvfbRun … Читать ещё