4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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

Last updated at Posted at 2023-10-10

環境

  • 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://storage.googleapis.com/chrome-for-testing-public/$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

参考文献

4
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
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?