Python 在gitlab CI中运行plotly dash selenium测试

Python 在gitlab CI中运行plotly dash selenium测试,python,docker,selenium,gitlab-ci,plotly-dash,Python,Docker,Selenium,Gitlab Ci,Plotly Dash,因此,我试图在GitLab ci管道中实现selenium测试。目前,我已经在本地系统上运行了这些测试,镜像了管道中即将发生的测试方法,即,我在本地系统上构建了测试,然后尝试连接到selenium/standalone chrome实例,以使用此命令运行测试 python3 -m pytest --junitxml=report.xml --log-cli-level DEBUG --webdriver Chrome --headless --remote-url http://localhos

因此,我试图在GitLab ci管道中实现selenium测试。目前,我已经在本地系统上运行了这些测试,镜像了管道中即将发生的测试方法,即,我在本地系统上构建了测试,然后尝试连接到selenium/standalone chrome实例,以使用此命令运行测试

python3 -m pytest --junitxml=report.xml --log-cli-level DEBUG --webdriver Chrome --headless --remote-url http://localhost:4444/wd/hub testing/
这在我的本地机器上正常工作。尝试使用gitlab-ci.yml时

stages:
  - test

image: "python"

services:
  - selenium/standalone-chrome

test:
  stage: test
  tags:
    - docker
  services:
    - selenium/standalone-chrome:latest
  script:
    # Set environmental variables
    - DEV_DASHBOARD_CFG='./app/config.json'
    - apt-get update -qy
    - apt-get install -y xvfb zip wget ca-certificates
    - apt-get install -y libnss3-dev libasound2 libxss1 libappindicator3-1 libindicator7 gconf-service libgconf-2-4 libpango1.0-0 xdg-utils fonts-liberation libgbm1
    # Setup the application to run
    - apt-get install -y python-dev python-pip
    - pip install -r requirements.txt
    - cd app/
    - pwd
    - python3 -m pytest --junitxml=report.xml --log-cli-level DEBUG --webdriver Chrome -headless --remote-url http://selenium__standalone-chrome:4444/wd/hub testing/
  artifacts:
    when: always
    reports:
      junit: report.xml
我面临的问题是,chromium web驱动程序似乎存在错误

---------------------------- Captured stdout call -----------------------------
 Dash is running on http://127.0.0.1:8050/
 Dash is running on http://127.0.0.1:8050/
 Dash is running on http://127.0.0.1:8050/
 Dash is running on http://127.0.0.1:8050/
 Dash is running on http://127.0.0.1:8050/
 Dash is running on http://127.0.0.1:8050/
 2021-04-23 14:27:21,034 | dash - INFO: Dash is running on http://127.0.0.1:8050/
  * Serving Flask app "app.app" (lazy loading)
  * Environment: production
    WARNING: This is a development server. Do not use it in a production deployment.
    Use a production WSGI server instead.
  * Debug mode: off
 2021-04-23 14:27:21,051 | _internal - INFO:  * Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
 2021-04-23 14:27:21,164 | dashboard - INFO: Serving layout...
 2021-04-23 14:27:21,166 | app_cache - DEBUG: retrieving from cache: select distinct country from results
 2021-04-23 14:27:21,183 | _internal - INFO: 127.0.0.1 - - [23/Apr/2021 14:27:21] "GET / HTTP/1.1" 200 -
 ------------------------------ Captured log call -------------------------------
 INFO     app.app:dash.py:1714 Dash is running on http://127.0.0.1:8050/
 INFO     werkzeug:_internal.py:113  * Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
 INFO     werkzeug:_internal.py:113 127.0.0.1 - - [23/Apr/2021 14:27:21] "GET / HTTP/1.1" 200 -
 --------------------------- Captured stdout teardown ---------------------------
 2021-04-23 14:27:23,110 | _internal - INFO: 127.0.0.1 - - [23/Apr/2021 14:27:23] "GET /_stop-adc0916c7cdb4b169e4eeb4c3f3f532e HTTP/1.1" 200 -
 ---------------------------- Captured log teardown -----------------------------
 INFO     werkzeug:_internal.py:113 127.0.0.1 - - [23/Apr/2021 14:27:23] "GET /_stop-adc0916c7cdb4b169e4eeb4c3f3f532e HTTP/1.1" 200 -
 _______________________________ test_tab_styles ________________________________
 dash_duo = <dash.testing.composite.DashComposite object at 0x7f14d260f610>
     def test_tab_styles(dash_duo):
 >       dash_duo.start_server(app)
 testing/test_db_tabs.py:28: 
 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
 /usr/local/lib/python3.9/site-packages/dash/testing/composite.py:16: in start_server
     self.server_url = self.server.url
 /usr/local/lib/python3.9/site-packages/dash/testing/browser.py:601: in server_url
     self.wait_for_page()
 /usr/local/lib/python3.9/site-packages/dash/testing/browser.py:341: in wait_for_page
     self.driver.get(self.server_url if url is None else url)
 /usr/local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py:333: in get
     self.execute(Command.GET, {'url': url})
 /usr/local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py:321: in execute
     self.error_handler.check_response(response)
 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
 self = <selenium.webdriver.remote.errorhandler.ErrorHandler object at 0x7f14d260fdc0>
 response = {'status': 500, 'value': '{"value":{"error":"unknown error","message":"unknown error: net::ERR_CONNECTION_REFUSED\\n  (Session info: chrome=90.0.4430.85)","stacktrace":"#0 0x563f07a8ee89 \\u003Cunknown>\\n"}}'}

您的Gitlab运行程序应该可以从Gitlab CI访问您试图运行的应用程序。根据错误,Gitlab runner显然无法连接到应用程序url


因此,请检查并确认Gitlab运行程序是否有权访问主机。

什么是selenium\uuuu standalone-chrome:4444???@LinPy selenium\uuuu standalone-chrome是您访问服务selenium/standalone-chrome时必须使用的工具。斜线变成了双下划线。我想删除上面评论的参考我已经用正确的远程url地址更新了最初的帖子,所以我可以使用curl来curl服务http://selenium__standalone-chrome:4444 但是在测试过程中,我仍然会遇到连接被拒绝的错误。因此,我测试的一部分是,我在脚本curl的开头创建了一个curl请求http://selenium__standalone-chrome:4444 成功并返回selenium的错误网页。从何处运行curl命令?通过Gitlab runner或在您的本地计算机上运行?我正在Gitlab runner中运行脚本的第一步,然后尝试在firefox驱动程序中运行它,尽管我最近在Chrome驱动程序中遇到了一些问题