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 conftest.py and the second one will be test_web01.py
import pytest
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.utils import ChromeType
from selenium import webdriver
@pytest.fixture()
def setup(request):
chrome_service = Service(ChromeDriverManager(chrome_type=ChromeType.GOOGLE).install())
chrome_options = Options()
options = [
"--headless",
"--disable-gpu",
"--window-size=1920,1200",
"--ignore-certificate-errors",
"--disable-extensions",
"--no-sandbox",
"--disable-dev-shm-usage"
]
for option in options:
chrome_options.add_argument(option)
request.cls.driver = webdriver.Chrome(service=chrome_service, options=chrome_options)
yield request.cls.driver
request.cls.driver.close()
Now lets create the second file where the actual tests are.
import pytest
@pytest.mark.usefixtures("setup")
class TestExampleOne:
def test_title(self):
self.driver.get('https://www.delrayo.tech')
assert self.driver.title == "DelRayo.tech - Delrayo Tech"
def test_title_blog(self):
self.driver.get('https://www.delrayo.tech/blog')
print(self.driver.title)
For running with GithubActions we have to create the following file structure on the repo.
- -.github
- --workflows
- ---test01.yaml
# .github/workflows/test01.yaml
name: test01
on:
workflow_dispatch:
jobs:
test01:
runs-on: ubuntu-latest
steps:
- name: Check out this repo
uses: actions/checkout@v2
#Setup Python
- name: Set up Python
uses: actions/setup-python@v2
with:
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
Now we just have to go to the actions section on github, select the workflow named test01 and click on the button run workflow.
You can configure this workflow to execute on different triggers modifying
on:
workflow_dispatch:
With any of these options.
You can find the working project Here.
Top comments (0)