From 20fa6f96484aa374aee9925d8d6d691f349b859c Mon Sep 17 00:00:00 2001 From: Viet Nguyen Duc Date: Wed, 22 Nov 2023 22:26:41 +0530 Subject: [PATCH] feat: NodeChrome support latest version from GoogleChromeLabs Signed-off-by: Viet Nguyen Duc --- NodeBase/start-selenium-node.sh | 12 +-- NodeChrome/Dockerfile | 93 +++++++++++++------ NodeDocker/start-selenium-grid-docker.sh | 5 + NodeEdge/Dockerfile | 9 +- NodeFirefox/Dockerfile | 11 +++ Standalone/start-selenium-standalone.sh | 14 ++- .../ci/customIngressPath-values.yaml | 52 +++++++++++ tests/test.py | 3 - 8 files changed, 150 insertions(+), 49 deletions(-) create mode 100644 charts/selenium-grid/ci/customIngressPath-values.yaml diff --git a/NodeBase/start-selenium-node.sh b/NodeBase/start-selenium-node.sh index 6a50d9069..9e251c9a9 100755 --- a/NodeBase/start-selenium-node.sh +++ b/NodeBase/start-selenium-node.sh @@ -31,6 +31,10 @@ if [ ! -z "$SE_OPTS" ]; then echo "Appending Selenium options: ${SE_OPTS}" fi +if [ ! -z "$SE_DRIVER_OPTS" ]; then + echo "Appending Selenium Driver Service property: ${SE_DRIVER_OPTS}" +fi + if [ "$GENERATE_CONFIG" = true ]; then echo "Generating Selenium Config" /opt/bin/generate_config @@ -52,14 +56,8 @@ echo "Selenium Grid Node configuration: " cat "$CONFIG_FILE" echo "Starting Selenium Grid Node..." -CHROME_DRIVER_PATH_PROPERTY=-Dwebdriver.chrome.driver=/usr/bin/chromedriver -EDGE_DRIVER_PATH_PROPERTY=-Dwebdriver.edge.driver=/usr/bin/msedgedriver -GECKO_DRIVER_PATH_PROPERTY=-Dwebdriver.gecko.driver=/usr/bin/geckodriver - java ${JAVA_OPTS:-$SE_JAVA_OPTS} \ - ${CHROME_DRIVER_PATH_PROPERTY} \ - ${EDGE_DRIVER_PATH_PROPERTY} \ - ${GECKO_DRIVER_PATH_PROPERTY} \ + ${SE_DRIVER_OPTS} \ -jar /opt/selenium/selenium-server.jar \ ${EXTRA_LIBS} node \ --bind-host ${SE_BIND_HOST} \ diff --git a/NodeChrome/Dockerfile b/NodeChrome/Dockerfile index 63eb00bd3..88f6b1660 100644 --- a/NodeChrome/Dockerfile +++ b/NodeChrome/Dockerfile @@ -6,22 +6,51 @@ LABEL authors=${AUTHORS} USER root +RUN apt-get update -qqy \ + && apt-get -qqy --no-install-recommends install libatk1.0-0 libatk-bridge2.0-0 \ + libxkbcommon-x11-0 libgbm1 libpango-1.0-0 \ + && rm -rf /var/lib/apt/lists/* /var/cache/apt/* + #============================================ # Google Chrome #============================================ # can specify versions by CHROME_VERSION; -# e.g. google-chrome-stable -# google-chrome-beta -# google-chrome-unstable -#============================================ -ARG CHROME_VERSION="google-chrome-stable" -RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \ - && echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list \ - && apt-get update -qqy \ - && apt-get -qqy install \ - ${CHROME_VERSION:-google-chrome-stable} \ - && rm /etc/apt/sources.list.d/google-chrome.list \ - && rm -rf /var/lib/apt/lists/* /var/cache/apt/* +# Support these inputs (following https://github.com/GoogleChromeLabs/chrome-for-testing): +# LATEST_RELEASE_STABLE +# LATEST_RELEASE_BETA +# LATEST_RELEASE_DEV +# LATEST_RELEASE_CANARY +# 121 (specific major version) +# 119.0.6045.105 (specific full version) +#============================================ +ARG DOWNLOAD_HOST="https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing" +ARG VERSION_HOST="https://googlechromelabs.github.io/chrome-for-testing" +ARG CHROME_VERSION="LATEST_RELEASE_STABLE" +ARG CHROME_PLATFORM="linux64" +RUN if [ ! -z "$CHROME_VERSION" ]; \ + then GET_VERSION_URL=$VERSION_HOST/$CHROME_VERSION \ + && if [ $(curl -I -s -o /dev/null -w "%{http_code}" $GET_VERSION_URL) -eq 200 ]; \ + then echo "Getting Chrome version from "$GET_VERSION_URL \ + && CHROME_VERSION=$(wget -qO- $VERSION_HOST"/"$CHROME_VERSION | sed 's/\r$//') ; \ + fi \ + else echo "Getting Chrome version "$CHROME_DRIVER_VERSION ; \ + fi \ + && CHROME_URL=$DOWNLOAD_HOST/$CHROME_VERSION/$CHROME_PLATFORM/chrome-$CHROME_PLATFORM.zip \ + && if [ $(curl -I -s -o /dev/null -w "%{http_code}" $CHROME_URL) -ne 200 ]; \ + then CHROME_MAJOR_VERSION=$(echo $CHROME_VERSION | sed -E "s/([0-9]+).*/\1/") \ + && echo "Getting Chrome latest major version from "$VERSION_HOST"/LATEST_RELEASE_"$CHROME_MAJOR_VERSION \ + && CHROME_VERSION=$(wget -qO- $VERSION_HOST/LATEST_RELEASE_${CHROME_MAJOR_VERSION} | sed 's/\r$//') \ + && CHROME_URL=$DOWNLOAD_HOST/$CHROME_VERSION/$CHROME_PLATFORM/chrome-$CHROME_PLATFORM.zip ; \ + fi \ + && echo "Using Chrome from: "$CHROME_URL \ + && wget --no-verbose -O /tmp/chrome-$CHROME_PLATFORM.zip $CHROME_URL \ + && rm -rf /opt/google/chrome \ + && unzip /tmp/chrome-$CHROME_PLATFORM.zip -d /opt/google \ + && mv /opt/google/chrome-$CHROME_PLATFORM /opt/google/chrome \ + && rm /tmp/chrome-$CHROME_PLATFORM.zip \ + && mv /opt/google/chrome/chrome-wrapper /opt/google/chrome/google-chrome \ + && chmod +x /opt/google/chrome/google-chrome \ + && ln -fs /opt/google/chrome/google-chrome /usr/bin/google-chrome #================================= # Chrome Launch Script Wrapper @@ -29,35 +58,45 @@ RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key COPY wrap_chrome_binary /opt/bin/wrap_chrome_binary RUN /opt/bin/wrap_chrome_binary -USER 1200 - #============================================ # Chrome webdriver #============================================ # can specify versions by CHROME_DRIVER_VERSION -# Latest released version will be used by default +# Latest released version (following browser version) will be used by default #============================================ -ARG CHROME_DRIVER_VERSION +ARG CHROME_DRIVER_VERSION=$CHROME_VERSION RUN if [ ! -z "$CHROME_DRIVER_VERSION" ]; \ - then CHROME_DRIVER_URL=https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/$CHROME_DRIVER_VERSION/linux64/chromedriver-linux64.zip ; \ - else echo "Geting ChromeDriver latest version from https://googlechromelabs.github.io/chrome-for-testing/LATEST_RELEASE_" \ - && CHROME_MAJOR_VERSION=$(google-chrome --version | sed -E "s/.* ([0-9]+)(\.[0-9]+){3}.*/\1/") \ - && CHROME_DRIVER_VERSION=$(wget -qO- https://googlechromelabs.github.io/chrome-for-testing/LATEST_RELEASE_${CHROME_MAJOR_VERSION} | sed 's/\r$//') \ - && CHROME_DRIVER_URL=https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/$CHROME_DRIVER_VERSION/linux64/chromedriver-linux64.zip ; \ + then GET_VERSION_URL=$VERSION_HOST/$CHROME_DRIVER_VERSION \ + && if [ $(curl -I -s -o /dev/null -w "%{http_code}" $GET_VERSION_URL) -eq 200 ]; \ + then echo "Getting ChromeDriver version from "$GET_VERSION_URL \ + && CHROME_DRIVER_VERSION=$(wget -qO- $VERSION_HOST"/"$CHROME_DRIVER_VERSION | sed 's/\r$//') ; \ + fi \ + else CHROME_DRIVER_VERSION=$(google-chrome --version | sed -E "s/.* ([0-9]+(\.[0-9]+)+).*/\1/") \ + && echo "Getting ChromeDriver same as browser version "$CHROME_DRIVER_VERSION ; \ + fi \ + && CHROME_DRIVER_URL=$DOWNLOAD_HOST/$CHROME_DRIVER_VERSION/$CHROME_PLATFORM/chromedriver-$CHROME_PLATFORM.zip \ + && if [ $(curl -I -s -o /dev/null -w "%{http_code}" $CHROME_DRIVER_URL) -ne 200 ]; \ + then CHROME_MAJOR_VERSION=$(echo $CHROME_DRIVER_VERSION | sed -E "s/([0-9]+).*/\1/") \ + && echo "Getting ChromeDriver latest major version from "$VERSION_HOST"/LATEST_RELEASE_"$CHROME_MAJOR_VERSION \ + && CHROME_DRIVER_VERSION=$(wget -qO- $VERSION_HOST/LATEST_RELEASE_${CHROME_MAJOR_VERSION} | sed 's/\r$//') \ + && CHROME_DRIVER_URL=$DOWNLOAD_HOST/$CHROME_DRIVER_VERSION/$CHROME_PLATFORM/chromedriver-$CHROME_PLATFORM.zip ; \ fi \ && echo "Using ChromeDriver from: "$CHROME_DRIVER_URL \ && echo "Using ChromeDriver version: "$CHROME_DRIVER_VERSION \ - && wget --no-verbose -O /tmp/chromedriver_linux64.zip $CHROME_DRIVER_URL \ + && wget --no-verbose -O /tmp/chromedriver_$CHROME_PLATFORM.zip $CHROME_DRIVER_URL \ && rm -rf /opt/selenium/chromedriver \ - && unzip /tmp/chromedriver_linux64.zip -d /opt/selenium \ - && rm /tmp/chromedriver_linux64.zip \ - && mv /opt/selenium/chromedriver-linux64/chromedriver /opt/selenium/chromedriver-$CHROME_DRIVER_VERSION \ + && unzip /tmp/chromedriver_$CHROME_PLATFORM.zip -d /opt/selenium \ + && rm /tmp/chromedriver_$CHROME_PLATFORM.zip \ + && mv /opt/selenium/chromedriver-$CHROME_PLATFORM/chromedriver /opt/selenium/chromedriver-$CHROME_DRIVER_VERSION \ && chmod 755 /opt/selenium/chromedriver-$CHROME_DRIVER_VERSION \ - && sudo ln -fs /opt/selenium/chromedriver-$CHROME_DRIVER_VERSION /usr/bin/chromedriver + && ln -fs /opt/selenium/chromedriver-$CHROME_DRIVER_VERSION /usr/bin/chromedriver +ENV SE_DRIVER_OPTS="-Dwebdriver.chrome.driver="${CHROME_DRIVER_PATH_PROPERTY:-"/usr/bin/chromedriver"}" "$SE_DRIVER_OPTS + +USER 1200 #============================================ # Dumping Browser information for config #============================================ RUN echo "chrome" > /opt/selenium/browser_name -RUN google-chrome --version | awk '{print $3}' > /opt/selenium/browser_version +RUN google-chrome --version | awk '{print $5}' > /opt/selenium/browser_version RUN echo "\"goog:chromeOptions\": {\"binary\": \"/usr/bin/google-chrome\"}" > /opt/selenium/browser_binary_location diff --git a/NodeDocker/start-selenium-grid-docker.sh b/NodeDocker/start-selenium-grid-docker.sh index b13474c6b..c0feb6c61 100755 --- a/NodeDocker/start-selenium-grid-docker.sh +++ b/NodeDocker/start-selenium-grid-docker.sh @@ -24,6 +24,10 @@ if [ ! -z "$SE_OPTS" ]; then echo "Appending Selenium options: ${SE_OPTS}" fi +if [ ! -z "$SE_DRIVER_OPTS" ]; then + echo "Appending Selenium Driver Service property: ${SE_DRIVER_OPTS}" +fi + if [ ! -z "$SE_NODE_GRID_URL" ]; then echo "Appending Grid url: ${SE_NODE_GRID_URL}" SE_GRID_URL="--grid-url ${SE_NODE_GRID_URL}" @@ -42,6 +46,7 @@ else fi java ${JAVA_OPTS:-$SE_JAVA_OPTS} \ + ${SE_DRIVER_OPTS} \ -jar /opt/selenium/selenium-server.jar \ ${EXTRA_LIBS} node \ --publish-events tcp://"${SE_EVENT_BUS_HOST}":${SE_EVENT_BUS_PUBLISH_PORT} \ diff --git a/NodeEdge/Dockerfile b/NodeEdge/Dockerfile index 307244dec..83338eeef 100644 --- a/NodeEdge/Dockerfile +++ b/NodeEdge/Dockerfile @@ -13,7 +13,7 @@ USER root # e.g. microsoft-edge-beta=88.0.692.0-1 #============================================ ARG EDGE_VERSION="microsoft-edge-stable" -RUN wget -q -O - https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \ +RUN wget -q -O - https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | tee /etc/apt/trusted.gpg.d/microsoft.gpg >/dev/null \ && echo "deb https://packages.microsoft.com/repos/edge stable main" >> /etc/apt/sources.list.d/microsoft-edge.list \ && apt-get update -qqy \ && apt-get -qqy install ${EDGE_VERSION} \ @@ -26,8 +26,6 @@ RUN wget -q -O - https://packages.microsoft.com/keys/microsoft.asc | apt-key add COPY wrap_edge_binary /opt/bin/wrap_edge_binary RUN /opt/bin/wrap_edge_binary -USER 1200 - #============================================ # Edge webdriver #============================================ @@ -46,7 +44,10 @@ RUN if [ -z "$EDGE_DRIVER_VERSION" ]; \ && rm /tmp/msedgedriver_linux64.zip \ && mv /opt/selenium/msedgedriver /opt/selenium/msedgedriver-$EDGE_DRIVER_VERSION \ && chmod 755 /opt/selenium/msedgedriver-$EDGE_DRIVER_VERSION \ - && sudo ln -fs /opt/selenium/msedgedriver-$EDGE_DRIVER_VERSION /usr/bin/msedgedriver + && ln -fs /opt/selenium/msedgedriver-$EDGE_DRIVER_VERSION /usr/bin/msedgedriver +ENV SE_DRIVER_OPTS="-Dwebdriver.edge.driver="${EDGE_DRIVER_PATH_PROPERTY:-"/usr/bin/msedgedriver"}" "$SE_DRIVER_OPTS + +USER 1200 #============================================ # Dumping Browser information for config diff --git a/NodeFirefox/Dockerfile b/NodeFirefox/Dockerfile index 48d83bdb8..1276bdc6d 100644 --- a/NodeFirefox/Dockerfile +++ b/NodeFirefox/Dockerfile @@ -35,9 +35,20 @@ RUN GK_VERSION=$(if [ ${GECKODRIVER_VERSION:-latest} = "latest" ]; then echo "0. && mv /opt/geckodriver /opt/geckodriver-$GK_VERSION \ && chmod 755 /opt/geckodriver-$GK_VERSION \ && ln -fs /opt/geckodriver-$GK_VERSION /usr/bin/geckodriver +ENV SE_DRIVER_OPTS="-Dwebdriver.gecko.driver="${GECKO_DRIVER_PATH_PROPERTY:-"/usr/bin/geckodriver"}" "$SE_DRIVER_OPTS + +# Workaround for issue launch Firefox Webdriver "Failed to read marionette port" +RUN mkdir -p /home/seluser/.cache /home/seluser/.mozilla /.cache \ + && chmod 777 /home/seluser/.cache /home/seluser/.mozilla /.cache USER 1200 +RUN if ! whoami &> /dev/null; then \ + if [ -w /tmp/passwd ]; then \ + echo "${USER_NAME:-default}:x:$(id -u):0:${USER_NAME:-default} user:/home/seluser:/tmp:/bin/bash" >> /tmp/passwd; \ + fi \ +fi + #============================================ # Dumping Browser information for config #============================================ diff --git a/Standalone/start-selenium-standalone.sh b/Standalone/start-selenium-standalone.sh index f1bf641a8..8cb230e40 100755 --- a/Standalone/start-selenium-standalone.sh +++ b/Standalone/start-selenium-standalone.sh @@ -11,6 +11,10 @@ if [ ! -z "$SE_OPTS" ]; then echo "Appending Selenium options: ${SE_OPTS}" fi +if [ ! -z "$SE_DRIVER_OPTS" ]; then + echo "Appending Selenium Driver Service property: ${SE_DRIVER_OPTS}" +fi + /opt/bin/generate_config echo "Selenium Grid Standalone configuration: " @@ -29,17 +33,11 @@ else echo "Tracing is disabled" fi -CHROME_DRIVER_PATH_PROPERTY=-Dwebdriver.chrome.driver=/usr/bin/chromedriver -EDGE_DRIVER_PATH_PROPERTY=-Dwebdriver.edge.driver=/usr/bin/msedgedriver -GECKO_DRIVER_PATH_PROPERTY=-Dwebdriver.gecko.driver=/usr/bin/geckodriver - java ${JAVA_OPTS:-$SE_JAVA_OPTS} \ - ${CHROME_DRIVER_PATH_PROPERTY} \ - ${EDGE_DRIVER_PATH_PROPERTY} \ - ${GECKO_DRIVER_PATH_PROPERTY} \ + ${SE_DRIVER_OPTS} \ -jar /opt/selenium/selenium-server.jar \ ${EXTRA_LIBS} standalone \ --bind-host ${SE_BIND_HOST} \ --config /opt/selenium/config.toml \ ${SUB_PATH_CONFIG} \ - ${SE_OPTS} \ No newline at end of file + ${SE_OPTS} diff --git a/charts/selenium-grid/ci/customIngressPath-values.yaml b/charts/selenium-grid/ci/customIngressPath-values.yaml new file mode 100644 index 000000000..e7812bc4a --- /dev/null +++ b/charts/selenium-grid/ci/customIngressPath-values.yaml @@ -0,0 +1,52 @@ +ingress: + annotations: + nginx.ingress.kubernetes.io/use-regex: "true" + nginx.ingress.kubernetes.io/rewrite-target: /$2 + nginx.ingress.kubernetes.io/app-root: &gridAppRoot "/selenium" + hostname: "" + paths: + - path: /selenium(/|$)(.*) + pathType: Prefix + backend: + service: + name: '{{ template "seleniumGrid.router.fullname" $ }}' + port: + number: 4444 + - path: /(/?)(session/.*/se/vnc) + pathType: Prefix + backend: + service: + name: '{{ template "seleniumGrid.router.fullname" $ }}' + port: + number: 4444 + +basicAuth: + enabled: false +isolateComponents: true + +hub: + subPath: *gridAppRoot + +components: + subPath: *gridAppRoot + +chromeNode: + enabled: true + extraEnvironmentVariables: + - name: SE_NODE_OVERRIDE_MAX_SESSIONS + value: "true" + - name: SE_NODE_MAX_SESSIONS + value: "5" + startupProbe: + exec: + command: + - bash + - -c + - if [ $(curl --write-out %{http_code} --silent --output /dev/null http://selenium-router:4444/selenium/wd/hub/status) -ne 200 ]; then exit 1; fi + failureThreshold: 15 + periodSeconds: 5 + +edgeNode: + enabled: false +firefoxNode: + enabled: false diff --git a/tests/test.py b/tests/test.py index 18c2b4a57..16dbbbf30 100644 --- a/tests/test.py +++ b/tests/test.py @@ -173,9 +173,6 @@ def standalone_browser_container_matches(container): if use_random_user_id: logger.info("Running tests with a random user ID -> %s" % random_user_id) - if 'firefox' in image.lower(): - logger.info("Firefox has issues when running with a random user ID. Skipping until it gets fixed.") - exit(0) standalone = 'standalone' in image.lower()