LoginSignup
3
1

【Dockerfile】Chromeのバージョンに合わせて、ChromeDriverをインストールする

Posted at

環境

  • Ruby on Rails 7.0.7
  • Capybara 3.39.2
  • Selenium-webdrivers 4.11.0
  • Docker 23.0.5
  • Docker Compose 2.17.3

背景

  • あるとき、E2Eテストがほとんど失敗する現象が起きた
    • ChromeとChromeDriverのバージョン差異が原因
    • DockerfileでChromeとChromeDriverをインストールしている

対応内容

  • DockerfileのChromeDriverインストール部分のURLをバージョン115以降のURLに変更
    • Chromeのバージョンを変数に代入して、差異が起きないように設定

# Chromeをインストール
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
    echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list && \
    apt-get update && apt-get install -y google-chrome-stable
# ChromeDriverをインストール
RUN apt-get update && apt-get install -y unzip graphviz && \
    CHROME_VERSION=$(google-chrome-stable --version | cut -d " " -f3) && \
    echo "Chrome_Version: ${CHROME_VERSION}" && \
    curl -sS -o /root/chromedriver_linux64.zip https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/$CHROME_VERSION/linux64/chromedriver-linux64.zip &&\
    unzip ~/chromedriver_linux64.zip -d ~/ && \
    rm ~/chromedriver_linux64.zip && \
    chown root:root ~/chromedriver-linux64/chromedriver && \
    chmod 755 ~/chromedriver-linux64/chromedriver && \
    mv ~/chromedriver-linux64/chromedriver /usr/bin/chromedriver

参考文献

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1