服务 chromedriver 意外退出。状态代码是:127

问题描述 投票:0回答:1

我在 Gitlab CI 上运行 selenium python 测试时遇到问题。但如果我在本地系统上运行,这些工作正常。 这些测试之前在使用 chrome 和 chrome-driver 版本 114 的 CI 上运行良好,但现在不支持此 url。 https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_114.0.5735.198-1_amd64.deb 我的 CI 如下所示:

erp_test:
  stage: test_Python_3.12
  image: python:3.12
  variables:
    OPERATING_SYSTEM: 'Ubuntu'
  script:
    - python -V
    - pip install -r requirements.txt
    - pip install --upgrade webdriver-manager
  # install google chrome
    - wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
    - sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
    - apt-get update
    - echo $(pwd)
    - mkdir -p /opt/google/
    - cd /opt/google/
    - echo $(pwd)
    - wget -q -O ./chrome-linux64.zip https://storage.googleapis.com/chrome-for-testing-public/125.0.6422.141/linux64/chrome-linux64.zip
    - unzip chrome-linux64.zip
    - rm -f chrome-linux64.zip
    - echo $(ls)
    - echo $(ls -ll /opt/google/chrome-linux64/)
    - echo $(ls -ll /usr/bin/)
    - ln -sf /opt/google/chrome-linux64/chrome /usr/bin/google-chrome
    - echo $(ls -ll /usr/bin/)
    - echo $(whereis google-chrome)
    - pytest tests/test_infor_EAM.py

我在Driver目录下有谷歌浏览器版本125.0.6422.141的chrome驱动程序

我在 Gitlab CI 上遇到以下错误

    @pytest.fixture()
    def setup():
        global driver
        if BROWSER == 'Chrome_Headless':
            chrome_options = Options()
            chrome_options.add_argument('--headless=new')
            chrome_options.add_argument('--window-size=1920,1200')
            chrome_options.add_argument('--no-sandbox')
            chrome_options.add_argument('--disable-dev-shm-usage')
            chrome_linux_64 = Service('./Drivers/chromedriver-linux64')
>           driver = webdriver.Chrome(service=chrome_linux_64, options=chrome_options)
tests/test_infor_EAM.py:21: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/local/lib/python3.12/site-packages/selenium/webdriver/chrome/webdriver.py:45: in __init__
    super().__init__(
/usr/local/lib/python3.12/site-packages/selenium/webdriver/chromium/webdriver.py:55: in __init__
    self.service.start()
/usr/local/lib/python3.12/site-packages/selenium/webdriver/common/service.py:102: in start
    self.assert_process_still_running()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
self = <selenium.webdriver.chrome.service.Service object at 0x7fbcef2249e0>
    def assert_process_still_running(self) -> None:
        """Check if the underlying process is still running."""
        return_code = self.process.poll()
        if return_code:
>           raise WebDriverException(f"Service {self._path} unexpectedly exited. Status code was: {return_code}")
E           selenium.common.exceptions.WebDriverException: Message: Service ./Drivers/chromedriver-linux64 unexpectedly exited. Status code was: 127
/usr/local/lib/python3.12/site-packages/selenium/webdriver/common/service.py:115: WebDriverException
=========================== short test summary info ============================
ERROR tests/test_infor_EAM.py::test_login_infor_eam - selenium.common.exceptions.WebDriverException: Message: Service ./Drivers/chromedriver-linux64 unexpectedly exited. Status code was: 127
=============================== 1 error in 0.26s ===============================

python google-chrome selenium-webdriver selenium-chromedriver
1个回答
0
投票

所以这个问题就解决了。 新方法是提供 as

,而不是提供 chrome 驱动程序的位置

'ChromeDriverManager().install()'

# chrome_linux_64 = Service(executable_path='./Drivers/chromedriver-linux64')
chrome_linux_64 = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=chrome_linux_64, options=chrome_options)
© www.soinside.com 2019 - 2024. All rights reserved.