我想让无头铬水豚测试在本地和docker中进行CI测试。
我几乎可以正常工作了,但是docker容器中的chromedriver与本地容器之间似乎存在某种冲突。我正在使用webdrivers gem:https://github.com/titusfortner/webdrivers
宝石文件:
gem 'capybara', '2.2.1'
gem 'webdrivers', '~> 4.0'
DockerFile:
FROM jruby:9.1.17
RUN apt-get update
RUN apt-get install -y wget git
# Essentials
RUN apt-get install -y git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev nodejs yarn unzip
# Install Chrome
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list
RUN apt-get update && apt-get -y install google-chrome-stable
# Install Chromedriver
RUN wget -q https://chromedriver.storage.googleapis.com/2.39/chromedriver_linux64.zip
RUN unzip chromedriver_linux64.zip -d /usr/local/bin
RUN rm -f chromedriver_linux64.zip
RUN apt-get clean
WORKDIR /tmp
# Cache Gems
ADD Gemfile .
ADD Gemfile.lock .
# Install correct bundler version and bunde install
RUN gem install bundler -v 1.17.3
RUN bundler _1.17.3_ install --jobs 4 --retry 3
# Copy your app's code into the image
WORKDIR /usr/src/app
ADD . /usr/src/app
当我在本地运行功能测试时,它工作正常:
bundle exec rake spec:features
但是当我运行Docker命令时它失败了:
docker run --rm -it --env RAILS_ENV=test -v ${PWD}:/usr/src/app my_image:latest bundle exec rake spec:features
我收到这样的错误:
Capybara::ElementNotFound:
Unable to find field "username"
但是,当我运行这样的docker命令并尝试删除gemfile安装的chromedriver时:
docker run --rm -it --env RAILS_ENV=test -v ${PWD}:/usr/src/app my_image:latest bundle exec rake webdrivers:chromedriver:remove && bundle exec rake spec:features
测试通过。即使这已登录到终端:shrugs =>
INFO Webdrivers No existing chromedriver to remove.
用于安装Chromedriver的Dockerfile指令将其放在此处:
/usr/local/bin
我不确定GEM会将其安装到何处-应该将chromedriver安装在$HOME/.webdrivers
目录中,但是当我用bash和bash触发容器时,在docker容器中找不到它运行:
find / -name ".webdrivers" -- returns no results
对此我有些困惑,我希望Docker测试能够在本地运行。因此,我尝试从Dockerfile中删除ChromeDriver安装-但是测试只是出错了。
是否有一种方法可以将Dockerfile中绑定的chromedriver设置为PATH,这样我就无需通过Dockerfile安装ChromeDriver,而仅使用Webdrivers gem提供的ChromeDriver?