LoginSignup
9
3

More than 1 year has passed since last update.

rubyのDockerイメージでseleniumを使えるようにするメモ

Last updated at Posted at 2022-05-19

概要

  • CircleCIで circleci/ruby:X.Y.Z-node-browsers の最新のrubyに対応したものがなかった
    • 最新rubyの ruby:X.Y.Z-buster にしたらseleniumが動かない
  • ruby:X.Y.Z-buster でseleniumを使えるようにした
  • とりあえず動くように差分のメモ

.circleci/config.ymlの差分

imageを変更する

before

- image: circleci/ruby:X.Y.Z-node-browsers

after

- image: ruby:X.Y.Z-buster

環境設定を追加

上で設定したrubyイメージのenvironmentにSELENIUM_DRIVERを追加。

after

environment:
  SELENIUM_DRIVER: selenium_driver

Chromeを入れる

Chromeの導入だけでなく関連パッケージがさらに必要になる。

before

- run:
  command: |
    sudo apt-get update --allow-releaseinfo-change
    sudo apt-get install -y libappindicator1 fonts-liberation
    export CHROME_BIN=/usr/bin/google-chrome
    wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
    sudo dpkg -i google-chrome*.deb

after

- run:
  command: |
    apt-get update --allow-releaseinfo-change
    apt-get install -y sudo unzip --no-install-recommends
    sudo apt-get update --allow-releaseinfo-change
    CHROME_DRIVER_VERSION=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE` && \
    wget -N http://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip -P ~/ && \
    unzip ~/chromedriver_linux64.zip -d ~/ && \
    rm ~/chromedriver_linux64.zip && \
    chown root:root ~/chromedriver && \
    chmod 755 ~/chromedriver && \
    mv ~/chromedriver /usr/bin/chromedriver && \
    sh -c 'wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -' && \
    sh -c '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

Node.jsを入れる

元々のイメージに入っていたものがないので、config.ymlに追加する。
Chromeの設定の下にでも追加。
command の最初URLの setup_16.x は使用しているNode.jsのバージョンによって変更する。

after

- run:
  command: |
    curl -sL https://deb.nodesource.com/setup_16.x | bash - \
        && curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
        && echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
        && apt-get update -qq \
        && apt-get install -y nodejs yarn --no-install-recommends

ここまで書けばCI上でseleniumを使ったテストが実行できるはず。

9
3
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
9
3