今回は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でワークフローの実行が確認できます。