【发布时间】:2020-10-03 11:27:14
【问题描述】:
我无法让我的 python Selenium 在 github 操作中运行。
过去一年我一直在使用 Circle CI,但最近开始迁移到 github 操作。
为了让 Circle CI 在 chrome 浏览器中运行 selenium,我的 config.yml 中有以下几行:
docker:
# includes chrome browser for selenium testing
- image: circleci/python:3.7.4-browsers
而且似乎不需要安装 chromedriver。
我在我的 github 操作 .yml 文件中使用以下内容:
jobs:
build:
runs-on: ubuntu-latest
services:
selenium:
image: selenium/standalone-chrome
steps:
- uses: actions/checkout@v1
- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 3.7
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pipenv
pipenv install
- name: Prepare Selenium
# https://github.com/marketplace/actions/setup-chromedriver
uses: nanasess/setup-chromedriver@master
- name: Launch browser
run: |
google-chrome --version
export DISPLAY=:99
chromedriver --url-base=/wd/hub &
sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 & # optional, disables headless mode
- name: Run tests
run: pipenv run python manage.py test functional_tests.tests.test_selenium.test_exams -v 2
但是当我尝试运行 python 代码时出现以下错误:
from selenium import webdriver
driver = webdriver.Chrome()
File "/home/runner/.local/share/virtualenvs/lang-EMCZ4oUT/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
File "/home/runner/.local/share/virtualenvs/lang-EMCZ4oUT/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/home/runner/.local/share/virtualenvs/lang-EMCZ4oUT/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/runner/.local/share/virtualenvs/lang-EMCZ4oUT/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/runner/.local/share/virtualenvs/lang-EMCZ4oUT/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
从我在网上看到的内容来看,我应该只需要uses: nanasess/setup-chromedriver@master 而不需要image: selenium/standalone-chrome,但是切换进出没有任何区别,python 测试仍然找不到 chrome 浏览器。
我应该设置一个端口来监听吗?
【问题讨论】:
标签: python selenium selenium-chromedriver github-actions