[英]Running plotly dash selenium tests in gitlab CI
So I'm attempting to implement selenium tests within a GitLab ci pipeline.所以我试图在 GitLab ci 管道中实施 selenium 测试。 Currently, I've run these tests on my local system mirroring the testing method that is going to happen within the pipeline ie I have my tests build on my local system then attempt to connect to the selenium/standalone-chrome instance to run tests with this command
目前,我已经在我的本地系统上运行这些测试,以反映将在管道内发生的测试方法,即我在我的本地系统上构建我的测试,然后尝试连接到 selenium/standalone-chrome 实例以运行测试这个命令
python3 -m pytest --junitxml=report.xml --log-cli-level DEBUG --webdriver Chrome --headless --remote-url http://localhost:4444/wd/hub testing/
This functions correctly on my local machine.这在我的本地机器上正常运行。 When attempting to use the gitlab-ci.yml
尝试使用 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
This issue I'm facing is that it seems that there is an error with the chromium web driver.我面临的这个问题是 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"}}'}
I've been experiencing the exact same problems and error messages above while trying to implement some plotly dash tests in gitlab CI.在尝试在 gitlab CI 中实施一些 plotly 破折号测试时,我遇到了与上述完全相同的问题和错误消息。 Finally got it working, and the main difference with the OP is the use of docker compose with these containers instead of scripting it directly in gitlab.ci.yml:
终于让它工作了,与 OP 的主要区别是使用 docker 与这些容器组合,而不是直接在 gitlab.ci.yml 中编写脚本:
entrypoint: pytest -v --remote --log-cli-level DEBUG
, and network_mode: host
entrypoint: pytest -v --remote --log-cli-level DEBUG
和network_mode: host
image: selenium/standalone-chrome
and network_mode: host
image: selenium/standalone-chrome
和network_mode: host
Previous to the above setup, I had created a docker.network and exposed port 8050 on the dash-test container and port 4444 on the selenium-grid container.在上述设置之前,我创建了一个 docker.network 并在 dash-test 容器上公开了端口 8050,在 selenium-grid 容器上公开了端口 4444。 That's when I got the
ERR_CONNECTION_REFUSED
error.那是我收到
ERR_CONNECTION_REFUSED
错误的时候。 I suspect that the issue with this setup (and might be what's happening in gitlab ci) is this:我怀疑此设置的问题(可能是 gitlab ci 中发生的问题)是这样的:
--remote-url http://selenium-grid:4444/wd/hub
so selenium tests start running --remote-url http://selenium-grid:4444/wd/hub
访问 selenium-grid,因此 selenium 测试开始运行http://localhost:8050/
hardcoded (ps dash maintainers, this should definitely changed and made configurable) which is inaccessible to the selenium-grid container when the tests run.http://localhost:8050/
硬编码(ps dash 维护者,这应该明确更改并使其可配置),当测试运行时,selenium-grid 容器无法访问它。 On modifying the docker-compose file to use network_mode: host
, that made it accessible as the containers were now using the host's.network.network_mode: host
时,这使得它可以访问,因为容器现在正在使用主机的 .network。 docker-compose.yaml: docker-compose.yaml:
version: '3.7'
services:
dash-test:
image: "dash-test"
build:
context: ..
dockerfile: docker/Dockerfile
target: test
entrypoint: pytest -v --remote --log-cli-level DEBUG -k bsly001
network_mode: host
depends_on:
selenium-grid:
condition: service_healthy
mem_limit: 4096m
volumes:
- ../config:/app/config
- ../dash_playground:/app/dash_playground
- ../qa_reports:/app/qa_reports
selenium-grid:
image: selenium/standalone-chrome
shm_size: 2gb
network_mode: host
healthcheck:
test: /opt/bin/check-grid.sh --host 0.0.0.0 --port 4444
interval: 5s
timeout: 30s
retries: 30
Your Gitlab runner should have access to the application you are trying to run from the Gitlab CI.您的 Gitlab 运行程序应该可以访问您尝试从 Gitlab CI 运行的应用程序。 As per the error its clear that Gitlab runner its not able to connect to the application url.
根据错误,很明显 Gitlab 运行程序无法连接到应用程序 url。
So please check and confirm whether the Gitlab runner have access to the host machine.所以请检查并确认Gitlab runner是否可以访问宿主机。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.