저는 pytest
gitlab에서 호스팅하는 개인 프로젝트 용 파이프 라인 CI / CD 를 설정하려고 필사적으로 시도 했습니다.
두 가지 기본 파일로 간단한 프로젝트를 설정하려고했습니다.
test_core.py
단순성을 위해 다른 종속성없이 파일
# coding: utf-8
# !/usr/bin/python3
import pytest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options
def test_basic_headless_selenium_example():
"""Test selenium installation by opening python website.
(inspired by https://selenium-python.readthedocs.io/getting-started.html)
"""
opts = Options()
opts.headless = True
driver = webdriver.Firefox(options=opts)
driver.get("http://www.python.org")
driver.close()
.gitlab-ci.yml
CI / CD 자동 테스트의 경우 파일 :
stages:
- tests
pytest:python3.7:
image: python:3.7
stage: tests
services:
- selenium/standalone-firefox:latest
script:
# - apt-get update && apt-get upgrade --assume-yes
- wget -O ~/FirefoxSetup.tar.bz2 "https://download.mozilla.org/?product=firefox-latest&os=linux64"
- tar xjf ~/FirefoxSetup.tar.bz2 -C /opt/
- ln -s /opt/firefox/firefox /usr/lib/firefox
- export PATH=$PATH:/opt/firefox/
- wget -O ~/geckodriver.tar.gz "https://github.com/mozilla/geckodriver/releases/download/v0.28.0/geckodriver-v0.28.0-linux64.tar.gz"
- tar -zxvf ~/geckodriver.tar.gz -C /opt/
- export PATH=$PATH:/opt/
- pip install selenium pytest
- pytest
내 노트북에서는 pytest
명령이 100 % 잘 작동합니다. 커밋을 gitlab에 푸시하면 필사적으로 오류가 발생합니다.
> raise exception_class(message, screen, stacktrace)
E selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status 255
/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py:242: WebDriverException
=========================== short test summary info ============================
FAILED test_selenium.py::test_basic_headless_selenium_example - selenium.comm...
============================== 1 failed in 1.29s ===============================
Cleaning up file based variables
00:01
ERROR: Job failed: exit code 1
이 예제를 재현 하는 간단한 프로젝트 https://gitlab.com/OlivierLuG/selenium_firefox 를 만들었습니다 . 실패한 파이프 라인은 https://gitlab.com/OlivierLuG/selenium_firefox/-/pipelines/225711127 에서 직접 찾을 수 있습니다.
아무도이 오류를 수정하는 방법에 대한 단서가 있습니까?
마침내 아래 .gitlab-ci.yml
파일을 사용하여 녹색에서 gitlab CI를 ping했습니다 .
나는 yaml 언어의 팬이 아닙니다. 파일을 더 짧게 만들기 위해라는 이름의 공유 코드 블록을 사용했습니다 install_firefox_geckodriver
. 그런 다음이 블록을 호출하는 python 3.7 및 3.8로 2 개의 작업을 구성했습니다. 이러한 종류의 테스트가 작동하도록하는 핵심은 다음과 같습니다. _ 헤드리스 모드에서 실행 (이미 저에게 해당됨) _ 명령 줄로 파이어 폭스 및 geckodriver 설치 _ 파이어 폭스 종속성 설치 _ gitlab 셀레늄 서비스 사용
다음은 내 yaml 파일입니다. 성공적인 파이프 라인은 https://gitlab.com/OlivierLuG/selenium_firefox/-/pipelines/225756742 에서 찾을 수 있습니다.
stages:
- tests
.install_firefox_geckodriver: &install_firefox_geckodriver
- apt-get update && apt-get upgrade --assume-yes
- apt-get install gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils --assume-yes
- wget -nv -O ~/FirefoxSetup.tar.bz2 "https://download.mozilla.org/?product=firefox-latest&os=linux64"
- tar xjf ~/FirefoxSetup.tar.bz2 -C /opt/
- ln -s /opt/firefox/firefox /usr/lib/firefox
- export PATH=$PATH:/opt/firefox/
- wget -nv -O ~/geckodriver.tar.gz "https://github.com/mozilla/geckodriver/releases/download/v0.28.0/geckodriver-v0.28.0-linux64.tar.gz"
- tar -zxvf ~/geckodriver.tar.gz -C /opt/
- export PATH=$PATH:/opt/
pytest:python3.7:
image: python:3.7
stage: tests
services:
- selenium/standalone-firefox:latest
script:
- *install_firefox_geckodriver
- pip install selenium pytest
- pytest
pytest:python3.8:
image: python:3.8
stage: tests
services:
- selenium/standalone-firefox:latest
script:
- *install_firefox_geckodriver
- pip install selenium pytest
- pytest
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다