LoginSignup
5
3

More than 1 year has passed since last update.

いまさらだけどGithub actions上でseleniumを動かしたのでまとめてみた

Posted at

今回はgithub actions上で「seleniumを動かすことだけ」にスポットを当てます。
用意するのはseleniumとgithub actionsワークフロー。

selenium

アクセス先のURLを出力するだけです。

test_selenium.py
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import chromedriver_binary

options = Options()
# ヘッドレスモード(Linux上で動かすとき必ずこのモードにしておく)
options.add_argument('--headless')
driver = webdriver.Chrome(options=options)
driver.get('https://example.com')
print(driver.current_url)

github actionsワークフロー

test_selenium.pyを置いているリポジトリにGithub actionsワークフロー.github/workflows/test_selenium.ymlを作成します。

test_selenium.yml
name: test-selenium
on: 
  push:
    branches:
      - master
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - 
        name: Checkout Repository
        uses: actions/checkout@v2
      - 
        name: Setup Python
        uses: actions/setup-python@v2
      - 
        name: Install Chrome
        run: |
          sudo wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
          sudo apt update
          sudo apt-get install google-chrome-stable
      - 
        name: Install Package
        run: |
          pip install chromedriver-binary==94.*
          pip install selenium
      - 
        name: Test Selenium
        run: python test_selenium.py

commitするとActionsでワークフローの実行が確認できます。

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