SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.49k stars 8.15k forks source link

[🐛 Bug]: #14417

Closed AlexWhitham closed 1 month ago

AlexWhitham commented 1 month ago

What happened?

Running in a docker container on python:3-slim. After the Chrome version changed from major 126 to 127 webdriver wouldn't instantiate. If I change the version back to 126, all goes well.

Chrome and Chrome driver versions are 127.0.6533.119

Docker container: Linux, python

How can we reproduce the issue?

FROM python:3-slim

ENV CHROME_DRIVER_DIR=/usr/bin

RUN apt-get -yq update && apt-get install -yq unzip curl gnupg jq git build-essential

# Install latest Chrome
# Using direct ubuntu deb package because googlechromelabs package
# requires too many extra libraries to be preinstalled and as a result
# chrome still crashes and not working for selenium
# LATEST_CHROME_VERSION=$(curl -s https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions.json | jq -r '.channels.Stable.version')
# https://github.com/GoogleChromeLabs/chrome-for-testing/issues/55
RUN LATEST_CHROME_VERSION_DEB="https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb" \
  && curl -o /tmp/chrome.deb $LATEST_CHROME_VERSION_DEB \
  && apt-get install -yq /tmp/chrome.deb \
  && rm /tmp/chrome.deb \
  && google-chrome --version

# Install latest chromedriver
RUN CHROMEDRIVER_URL=$(curl -s https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json | jq -r '.channels.Stable.downloads.chromedriver[] | select(.platform == "linux64") | .url') \
  && curl -sSL -o /tmp/chromedriver.zip "$CHROMEDRIVER_URL" \
  && unzip /tmp/chromedriver.zip chromedriver-linux64/chromedriver -d "${CHROME_DRIVER_DIR}" \
  && ln -s "${CHROME_DRIVER_DIR}"/chromedriver-linux64/chromedriver "${CHROME_DRIVER_DIR}"/chromedriver \
  && rm /tmp/chromedriver.zip \
  && chromedriver --version

# set display port to avoid crash and dbus env to avoid hanging
ENV DISPLAY=:99
ENV DBUS_SESSION_BUS_ADDRESS=/dev/null

ARG SELENIUM_VERSION
COPY requirements-${SELENIUM_VERSION}.txt /tmp/requirements.txt
COPY selenium-smoke-test.py /tmp/

RUN cd /tmp \
  && pip install --upgrade pip \
  && pip install -r requirements.txt \
  && timeout --foreground --verbose 10 python3 selenium-smoke-test.py --chrome_driver_path "${CHROME_DRIVER_DIR}/chromedriver" --google_chrome_path "$(which google-chrome-stable)"

RUN mkdir /code
WORKDIR /code

--------------

import argparse
import subprocess

import selenium
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service

TEST_URL = "https://www.google.com/"
CHROME_OPTIONS_LIST = [
    "--headless",
    "--no-sandbox",
    "--disable-dev-shm-usage",
    "--window-size=1920,1080",
]

def main(_args):
    chrome_driver_path = _args.chrome_driver_path
    chrome_binary_path = _args.google_chrome_path
    list_versions(chrome_driver_path, chrome_binary_path)

    chrome_options = Options()
    [chrome_options.add_argument(option) for option in CHROME_OPTIONS_LIST]
    chrome_options.binary_location = chrome_binary_path

    selenium_version = int(str(selenium.__version__)[0])

    if selenium_version <= 3:
        driver = webdriver.Chrome(
            executable_path=chrome_driver_path, options=chrome_options
        )
    else:
        service = Service(chrome_driver_path)
        # service = webdriver.ChromeService(
        #     service_args=['--log-level=INFO'], log_output=subprocess.STDOUT
        # )
        driver = webdriver.Chrome(service=service, options=chrome_options)

    driver.maximize_window()
    driver.get(TEST_URL)
    driver.quit()

Relevant log output

7.355 ChromeDriver 127.0.6533.119 (bdef6783a05f0b3f885591e7d2c7b2aec1a89dea-refs/branch-heads/6533@{#1999})
7.383 Google Chrome 127.0.6533.119 
7.386 Creating driver instance
7.387 Selenium version 4
7.605 Starting ChromeDriver 127.0.6533.119 (bdef6783a05f0b3f885591e7d2c7b2aec1a89dea-refs/branch-heads/6533@{#1999}) on port 58889
7.605 Only local connections are allowed.
7.605 Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
7.618 ChromeDriver was started successfully.
7.680 [1724161347.412][INFO]: [44c4b3b1eb309c0ded7c60af221eeb9c] COMMAND InitSession {
7.680    "capabilities": {
7.680       "alwaysMatch": {
7.680          "browserName": "chrome",
7.680          "browserVersion": null,
7.680          "goog:chromeOptions": {
7.680             "args": [ "--headless", "--no-sandbox", "--disable-dev-shm-usage", "--window-size=1920,1080" ],
7.680             "binary": "/usr/bin/google-chrome-stable",
7.680             "extensions": [  ]
7.680          },
7.680          "pageLoadStrategy": "normal"
7.680       },
7.680       "firstMatch": [ {
7.680       } ]
7.680    }
7.680 }
7.681 [1724161347.413][INFO]: Populating Preferences file: {
7.681    "alternate_error_pages": {
7.681       "enabled": false
7.681    },
7.681    "autofill": {
7.681       "enabled": false
7.681    },
7.681    "browser": {
7.681       "check_default_browser": false
7.681    },
7.681    "distribution": {
7.681       "import_bookmarks": false,
7.681       "import_history": false,
7.681       "import_search_engine": false,
7.681       "make_chrome_default_for_user": false,
7.681       "skip_first_run_ui": true
7.681    },
7.681    "dns_prefetching": {
7.681       "enabled": false
7.681    },
7.681    "profile": {
7.681       "content_settings": {
7.681          "pattern_pairs": {
7.681             "https://*,*": {
7.681                "media-stream": {
7.681                   "audio": "Default",
7.681                   "video": "Default"
7.681                }
7.681             }
7.681          }
7.681       },
7.681       "default_content_setting_values": {
7.681          "geolocation": 1
7.681       },
7.681       "default_content_settings": {
7.681          "geolocation": 1,
7.681          "mouselock": 1,
7.681          "notifications": 1,
7.681          "popups": 1,
7.681          "ppapi-broker": 1
7.681       },
7.681       "password_manager_enabled": false
7.681    },
7.681    "safebrowsing": {
7.681       "enabled": false
7.681    },
7.681    "search": {
7.681       "suggest_enabled": false
7.681    },
7.681    "translate": {
7.681       "enabled": false
7.681    }
7.681 }
7.681 [1724161347.413][INFO]: Populating Local State file: {
7.681    "background_mode": {
7.681       "enabled": false
7.681    },
7.681    "ssl": {
7.681       "rev_checking": {
7.681          "enabled": false
7.681       }
7.681    }
7.681 }
7.682 [1724161347.414][INFO]: ChromeDriver supports communication with Chrome via pipes. This is more reliable and more secure.
7.682 [1724161347.414][INFO]: Use the --remote-debugging-pipe Chrome switch instead of the default --remote-debugging-port to enable this communication mode.
7.682 [1724161347.414][INFO]: Launching chrome: /usr/bin/google-chrome-stable --allow-pre-commit-input --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-dev-shm-usage --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --enable-automation --enable-logging --headless --log-level=0 --no-first-run --no-sandbox --no-service-autorun --password-store=basic --remote-debugging-port=0 --test-type=webdriver --use-mock-keychain --user-data-dir=/tmp/.org.chromium.Chromium.vdJffZ --window-size=1920,1080 data:,
7.918 [1724161347.650][INFO]: resolved localhost to ["::1","127.0.0.1"]
17.20 timeout: sending signal TERM to command ‘python3’

Operating System

Linux

Selenium version

3 and 4

What are the browser(s) and version(s) where you see this issue?

Major version 127 and up

What are the browser driver(s) and version(s) where you see this issue?

Major version 127 and up

Are you using Selenium Grid?

No response

github-actions[bot] commented 1 month ago

@AlexWhitham, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

diemol commented 1 month ago

I don't see how this is a Selenium issue. Can you please elaborate?

AlexWhitham commented 1 month ago

The Selenium webdriver won't instantiate. It works with Chrome major version 126 but not 127. As I understand it, because it is a Selenium webdriver - it is a Selenium issue, no? Also Chrome and Chrome driver instantiate correctly with no issues

diemol commented 1 month ago

Aside from the link I shared in the other issue, what else have you tried to understand the root cause? Have you tried the options I shared in the link?

AlexWhitham commented 1 month ago

I tried to set versions of Chrome and Chrome driver to ensure the problem is occurring only starting from 127. I tried 128 as well and I got the same result. I did use the options but it didn't help.

AlexWhitham commented 1 month ago

Because there is no error, if I remove the timeout it just keeps running forever, I have no way to understand what is going on.

diemol commented 1 month ago

What happens when you run that code outside of a Docker container?

AlexWhitham commented 1 month ago

Well it needs to be run in a container, but I will give it a go locally

VietND96 commented 1 month ago

7.682 [1724161347.414][INFO]: Launching chrome: /usr/bin/google-chrome-stable --allow-pre-commit-input --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-dev-shm-usage --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --enable-automation --enable-logging --headless --log-level=0 --no-first-run --no-sandbox --no-service-autorun --password-store=basic --remote-debugging-port=0 --test-type=webdriver --use-mock-keychain --user-data-dir=/tmp/.org.chromium.Chromium.vdJffZ --window-size=1920,1080 data:,

Can you update argument --headless to --headless=new ?

AlexWhitham commented 1 month ago

Thank you @VietND96 just tried that, didn't help

AlexWhitham commented 1 month ago

It did work locally @diemol ... I am going to explode. I guess I need a different container setup. Thanks!

diemol commented 1 month ago

What was the issue?

AlexWhitham commented 1 month ago

Not sure yet, but I guess the container itself is the issue, since it is working locally

AlexWhitham commented 1 month ago

The issue was ENV DISPLAY=:99 🤦🏼‍♀️

github-actions[bot] commented 2 weeks ago

This issue has been automatically locked since there has not been any recent activity since it was closed. Please open a new issue for related bugs.