[英]Gitlab CI - Django functional tests - splinter
我想在github上使用Django框架在我的项目上运行一些自动化测试。 因此我正在使用Django功能测试。 虽然在我的本地电脑上执行测试工作正常,我的管道总是失败与这些测试。
我假设,chromedriver工作不正常,经过对互联网的一些研究,我发现,我需要安装chrome作为浏览器,所以我修改了我的requirements.txt for pip,如下所示:
applescript==2018.11.19
astroid==2.1.0
autopep8==1.4.3
chromedriver==2.24.1
decorator==4.3.0
detect==2018.11.19
Django==2.1.3
flake8==3.6.0
google-chrome==2018.11.19
google-chrome-cli==2018.11.19
isort==4.3.4
lazy-object-proxy==1.3.1
mccabe==0.6.1
only==2018.11.20
psutil==5.4.8
public==2018.11.20
pycodestyle==2.4.0
pyflakes==2.0.0
pylint==2.2.1
pytz==2018.7
runcmd==2018.11.20
selenium==3.141.0
six==1.11.0
splinter==0.10.0
temp==2018.11.20
urllib3==1.24.1
wrapt==1.10.11
.gitlab-ci.yml
image: python:latest
before_script:
- pip install virtualenv
- virtualenv --python=python3 venv/
- source venv/bin/activate
- pip install -r requirements.txt
- cd src/
- python manage.py migrate
stages:
- quality
- tests
flake8:
stage: quality
script:
- flake8 ./
test:
stage: tests
script:
- python manage.py test
test_functional.py
def setUp(self):
# LINUX x64
executable_path = {'executable_path': settings.CHROMEDRIVER_PATH_LINUX64}
# chrome
self.browser_chrome = Browser('chrome', **executable_path)
[..]
有了这个,已经安装了一个chrome浏览器,但是现在我收到了这个错误:
selenium.common.exceptions.WebDriverException:
Message: Service /builds/mitfahrzentrale/mitfahrzentrale/venv/chromedriver unexpectedly exited.
Status code was: 127
为了将chromedriver用于gitlab,我需要修改什么?
我不认为google-chrome
软件包可以满足您的需求。 查看其源代码 ,它是MacOS上Chrome浏览器周围的一组AppleScript命令的Python包装器,肯定不会在Linux上安装浏览器。
作为参考,这里是我们与Django和Selenium一起使用的(剥离的)Gitlab CI管道,用于在Firefox和Chrome上运行测试:
stages:
- test
.test:
coverage: '/TOTAL.*\s+(\d+%)$/'
test-linux_x86_64:
extends: .test
image: python:3.7.1-stretch
stage: test
tags:
- linux_x86_64
script:
- apt -qq update
- DEBIAN_FRONTEND=noninteractive apt -qq -y install xvfb firefox-esr chromium chromedriver
# download geckodriver as no distro offers a package
- apt install -qq -y jq # I don't want to parse JSON with regexes
- curl -s https://api.github.com/repos/mozilla/geckodriver/releases/latest | jq -r '.assets[].browser_download_url | select(contains("linux64"))' | xargs -n1 curl -sL | tar -xz -C /usr/local/bin
- chmod +x /usr/local/bin/geckodriver
# prepare Django installation
- python -m venv /opt/testing
# bundled pip and setuptools are outdated
- /opt/testing/bin/pip install --quiet --upgrade pip setuptools
- /opt/testing/bin/pip install --quiet -r requirements.txt
- xvfb-run /opt/testing/bin/python manage.py test
一些说明:
xvfb
用于在虚拟显示器中运行浏览器; 现代浏览器能够以无头模式运行(添加 - --headless
控制器选项),使虚拟显示不必要。 如果您不需要支持旧的浏览器版本,则可以省略xvfb
安装和xvfb-run
用法。 测试将在容器中以root
身份运行; 起初,我们得到了错误
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/chromium is no longer running, so ChromeDriver is assuming that Chrome has crashed.) E (Driver info: chromedriver=2.41,platform=Linux 4.15.10-300.fc27.x86_64 x86_64)
如果你面对这个,你需要将额外的标志--no-sandbox
传递给Chrome,因为它拒绝以root
身份运行而没有它:
chrome_options = webdriver.ChromeOptions() chrome_options.add_argument('--no-sandbox') ds = DesiredCapabilities.CHROME ds['loggingPrefs'] = {'browser': 'ALL'} driver = webdriver.Chrome(desired_capabilities=ds, options=chrome_options)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.