diff --git a/.config/dictionary.txt b/.config/dictionary.txt index ad6f3a67..a0acd13b 100644 --- a/.config/dictionary.txt +++ b/.config/dictionary.txt @@ -15,6 +15,7 @@ collectonly confest devfile devspaces +geckodriver kubedock libonig lightspeed diff --git a/selenium/Containerfile b/selenium/Containerfile index e153c6ea..3c043b9c 100644 --- a/selenium/Containerfile +++ b/selenium/Containerfile @@ -137,7 +137,7 @@ curl -sSfL -C - https://github.com/SeleniumHQ/selenium/releases/download/seleniu -o ${SELENIUM_PATH} && \ curl -sSfL -C - https://repo1.maven.org/maven2/org/seleniumhq/selenium/selenium-http-jdk-client/${SELENIUM_HTTP_JDK_CLIENT_VERSION}/selenium-http-jdk-client-${SELENIUM_HTTP_JDK_CLIENT_VERSION}.jar \ -o ${SELENIUM_HTTP_JDK_CLIENT_PATH} && \ -curl -sSfL https://download-installer.cdn.mozilla.net/pub/firefox/releases/140.7.0esr/linux-$(arch)/en-US/firefox-140.7.0esr.tar.xz -o firefox.tar.xz && tar --xz -x -f firefox.tar.xz && rm firefox.tar.xz && \ +curl -sSfL https://download-installer.cdn.mozilla.net/pub/firefox/releases/140.7.0esr/linux-$(arch)/en-US/firefox-140.7.0esr.tar.xz -o firefox.tar.xz && tar --xz -x -f firefox.tar.xz -C ${SELENIUM_HOME} && \ curl -sSfL -C - -O https://github.com/mozilla/geckodriver/releases/download/${GECKODRIVER_VERSION}/geckodriver-${GECKODRIVER_VERSION}-${GECKODRIVER_ARCH}.tar.gz && \ tar -C /usr/bin/ -xvf geckodriver-${GECKODRIVER_VERSION}-${GECKODRIVER_ARCH}.tar.gz && \ cd ${SELENIUM_HOME} && \ @@ -146,6 +146,8 @@ echo "session.screen0.toolbar.autoHide: true" > .fluxbox/init && \ touch .Xauthority .vnc/config && \ curl -fsSL https://code-server.dev/install.sh | sh +COPY selenium-node.toml /home/selenium/selenium-node.toml + RUN \ code-server --install-extension ms-python.vscode-python-envs --install-extension redhat.vscode-yaml --install-extension redhat.vscode-redhat-account && \ mkdir -p workspace && touch workspace/playbook.yaml && \ @@ -159,8 +161,9 @@ code-server --version && \ Xvnc -version && \ fluxbox --version && \ java -version && \ +firefox --version && \ if [ "$(arch)" = "aarch64" ]; then export JAVA_TOOL_OPTIONS=-XX:UseSVE=0; fi && \ -java -Dwebdriver.http.factory=jdk-http-client -jar ${SELENIUM_PATH} -ext ${SELENIUM_HTTP_JDK_CLIENT_PATH} info +java -Dwebdriver.http.factory=jdk-http-client -jar ${SELENIUM_PATH} --ext ${SELENIUM_HTTP_JDK_CLIENT_PATH} info USER 1001 diff --git a/selenium/init.go b/selenium/init.go index fda613b4..d7110eda 100644 --- a/selenium/init.go +++ b/selenium/init.go @@ -68,6 +68,7 @@ func printSeleniumCombinedOutput(seleniumStdout io.ReadCloser) { func startSelenium() *exec.Cmd { fmt.Println("Starting selenium standalone") + configPath := os.Getenv("SELENIUM_HOME") + "/selenium-node.toml" selenium := exec.Command( "java", "-Dwebdriver.http.factory=jdk-http-client", @@ -76,10 +77,16 @@ func startSelenium() *exec.Cmd { "--ext", os.Getenv("SELENIUM_HTTP_JDK_CLIENT_PATH"), "standalone", + "--allow-cors", + "true", + "--host", + "0.0.0.0", // Allow remote access (containers too) "--port", os.Getenv("SELENIUM_PORT"), "--session-timeout", os.Getenv("SELENIUM_SESSION_TIMEOUT"), + "--config", + configPath, ) seleniumStdout, _ := selenium.StdoutPipe() selenium.Stderr = selenium.Stdout diff --git a/selenium/selenium-node.toml b/selenium/selenium-node.toml new file mode 100644 index 00000000..34202bd2 --- /dev/null +++ b/selenium/selenium-node.toml @@ -0,0 +1,10 @@ +# Explicit driver configuration so the node finds geckodriver and Firefox +# without relying on PATH detection (which can fail in container env). +[node] +detect-drivers = false + +[[node.driver-configuration]] +display-name = "firefox" +max-sessions = 4 +webdriver-executable = "/usr/bin/geckodriver" +stereotype = '{"browserName": "firefox", "platformName": "Linux", "moz:firefoxOptions": {"binary": "/home/selenium/firefox/firefox"}}' diff --git a/tools/selenium.sh b/tools/selenium.sh index 45f7bddb..490e8d7a 100755 --- a/tools/selenium.sh +++ b/tools/selenium.sh @@ -57,6 +57,26 @@ fi $BUILD_CMD -f selenium/Containerfile selenium/ --tag "${IMAGE_NAME}" +# Verify the container starts and Selenium server comes up; run for 1 minute then stop +CONTAINER_NAME="selenium-adt-verify-$$" +cleanup_verify_container() { + ${ADT_CONTAINER_ENGINE} rm -f "${CONTAINER_NAME}" 2>/dev/null || true +} +trap cleanup_verify_container EXIT + +echo "Starting container to verify Selenium server..." +SELENIUM_PORT=4444 +${ADT_CONTAINER_ENGINE} run -d -p ${SELENIUM_PORT}:${SELENIUM_PORT} --name "${CONTAINER_NAME}" "${IMAGE_NAME}" + +# Wait for Selenium to be ready (status endpoint on port 4444) using curl retries +echo "Waiting for Selenium server to be ready..." +if ! curl -sSf -o /dev/null --retry-all-errors --retry 30 --retry-delay 2 --connect-timeout 2 "http://localhost:${SELENIUM_PORT}/status"; then + echo "Selenium server did not become ready in time." + ${ADT_CONTAINER_ENGINE} logs "${CONTAINER_NAME}" + exit 1 +fi +echo "Selenium server is ready." + if [[ -n "${GITHUB_SHA:-}" && "${GITHUB_EVENT_NAME:-}" != "pull_request" ]]; then FQ_IMAGE_NAME="ghcr.io/ansible/selenium-adt-tmp:${GITHUB_SHA}-$ARCH" $ADT_CONTAINER_ENGINE tag $IMAGE_NAME "${FQ_IMAGE_NAME}"