Joonas' Note
GitHub Actions에서 Chrome WebDriver 테스트 오류 해결법 (pytest) 본문
- CI + Chrome WebDriver + pytest
- 오류 1
- 해결 1-1
- 해결 1-2
- 해결 1-3
- 오류 2 + 해결
- 전체 보기
작년 말에 GitHub에 액션(Actions)이라는 기능이 추가되었다.

이제 GitHub에서는 자체적으로 CI 기능을 제공한다. 그 전에는 Travis-CI 아니면 CircleCI에서 빌드 & 테스트를 하고, 그 상태를 위 같은 배지 이미지로 표시했는데, 이제 직접 제공하면서 더 간편해졌다.
환경 변수를 암호화해서 Travis-CI에서 빌드하는 그런 기능까지 있는지는 써보면서 확인을 해봐야겠다. (aws나 google api key 때문에.. 이거 암호화하는 거 꼭 필요함..)
CI + Chrome WebDriver + pytest
배포 전에는 미리 배포 환경으로 테스트하면서 종종 사용하는데, 이번에는 문제가 생겼다.

분명 Windows 10에서는 Chrome WebDriver 사용하는 selenium 코드들이 잘 작동했는데, CI에서 빌드를 실패했다.
정확히는 "여러 실패"를 했다. 왜였을까? (스샷이 스포일러..)

먼저, 워크플로우(workflow)로 기본 파이썬 패키지 yml 파일을 사용했다.
그리고 테스트 코드는 아래와 같다. (글을 위해서 따로 작성함)
import os
from selenium import webdriver
def test_driver():
chrome_driver = os.path.join('chromedriver')
chrome_options = webdriver.ChromeOptions()
driver = webdriver.Chrome(chrome_driver, options=chrome_options)
driver.implicitly_wait(3)
driver.quit()
assert driver is not None
여기에서 전체 코드를 확인할 수 있다.
이 코드를 pytest가 실행하면서 오류가 났는데,

오류 메시지:
> raise exception_class(message, screen, stacktrace)
E selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
E (unknown error: DevToolsActivePort file doesn't exist)
E (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
/opt/hostedtoolcache/Python/3.7.6/x64/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py:242: WebDriverException
=========================== short test summary info ============================
FAILED test_main.py::test_driver - selenium.common.exceptions.WebDriverExcept...
============================== 1 failed in 3.16s ===============================
Chrome 시작에 실패했다. [자세히]
오류 1
빌드하는 branch에 chromedriver.exe가 없어서 실행을 못한 것일 수도 있다.
이건 해결방법이 많다.
해결 1-1
https://chromedriver.chromium.org/downloads 에서 chromedriver.exe를 다운받아서 repo에 같이 포함하여 commit을 하면 된다. 그럼 빌드할 때 있으므로 해결.
해결 1-2
repo에 exe 파일을 포함시키는게 마음에 걸린다. 그럼, 빌드할때만 설치받아서 하는 방법이 있다.
- name: Download chromedriver
run: |
wget -q -O tmp.zip https://chromedriver.storage.googleapis.com/81.0.4044.69/chromedriver_linux64.zip
unzip tmp.zip && rm tmp.zip
yml 파일에서 테스트 전에 위 step을 추가한다. 링크는 해결1-1의 다운로드 페이지에서 직접 링크를 복사했다. 파일 받고 압축을 풀면 chromedriver.exe가 들어있다.
해결 1-3
이러한 action을 이미 누가 만들어서 서버에 올려두었다 ^^
아래 step을 테스트 전에 끼워서 쓰면 된다.
- name: Setup Chromedriver
uses: nanasess/setup-chromedriver@v1.0.1
오류 2 + 해결
이번엔 다른 오류이다. 그런데 완전히 같은 에러 로그 메시지다. [자세히]
이번에도 Chrome 시작에 실패했는데, 빌드 환경은 Linux/Ubuntu였다. ci 환경이 docker라 그런지 모르겠는데, selenium(chrome driver)를 Headless 모드로 실행해야 에러가 나지 않는다.
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless') # headless
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--disable-gpu')
driver = webdriver.Chrome(chrome_driver, options=chrome_options)
전체 보기
이 글에서 나온 selenium 오류들을 아래 링크에서 모두 확인할 수 있다.
- https://github.com/joonas-yoon/ci-test/actions?query=workflow%3A%22Test+selenium%22
- https://github.com/joonas-yoon/ci-test/tree/selenium
joonas-yoon/ci-test
Contribute to joonas-yoon/ci-test development by creating an account on GitHub.
github.com
'개발' 카테고리의 다른 글
brew로 gtest 설치하기 (0) | 2020.06.04 |
---|---|
macOSX에서 Qt 5 빌드 중 에러 해결법 (0) | 2020.06.04 |
Semantic-UI로 무한 로딩 바 만들기 (0) | 2020.01.15 |
PHP4 to PHP5.4 or higher (0) | 2019.11.06 |
(3 in 5)^2 퍼즐 / Rubik's Race / 루빅스 레이스 (0) | 2019.11.01 |