The Ops Community ⚙️

Ricardo Del Rayo
Ricardo Del Rayo

Posted on • Originally published at

Executing Selenium test with python(pytest) using GitHub Actions
You can find the working project Here.

First we are going to create some example tests.
I'll be using selenium with python(pytest).

So for this example ill be creating 2 files one will be called and the second one will be in GitHub

import pytest
from import Options
from import Service
from import ChromeDriverManager
from webdriver_manager.utils import ChromeType
from selenium import webdriver

def setup(request):
    chrome_service = Service(ChromeDriverManager(chrome_type=ChromeType.GOOGLE).install())

    chrome_options = Options()
    options = [
    for option in options:

    request.cls.driver = webdriver.Chrome(service=chrome_service, options=chrome_options)

    yield request.cls.driver
Enter fullscreen mode Exit fullscreen mode

Now lets create the second file where the actual tests are. in GitHub

import pytest

class TestExampleOne:
    def test_title(self):
        assert self.driver.title == " - Delrayo Tech"

    def test_title_blog(self):

Enter fullscreen mode Exit fullscreen mode

For running with GithubActions we have to create the following file structure on the repo.

  • -.github
  • --workflows
  • ---test01.yaml

test01.yaml in GitHub

# .github/workflows/test01.yaml
name: test01
    runs-on: ubuntu-latest
      - name: Check out this repo
        uses: actions/checkout@v2
     #Setup Python   
      - name: Set up Python
        uses: actions/setup-python@v2
          python-version: '3.9'
      - name: Install software
        run: sudo apt-get install -y chromium-browser
      - name: Install the necessary packages
        run: pip install requests webdriver-manager selenium pytest
      - name: Run the PytTest script
        run: pytest -rA
Enter fullscreen mode Exit fullscreen mode

Now we just have to go to the actions section on github, select the workflow named test01 and click on the button run workflow.

GitHub Actions

You can configure this workflow to execute on different triggers modifying


Enter fullscreen mode Exit fullscreen mode

With any of these options.

Test Pass with GitHub Actions

You can find the working project Here.

Top comments (0)