Skip to content

Commit c43932a

Browse files
committed
Update actions to run browser tests and capture reports
1 parent 8e86f3a commit c43932a

4 files changed

Lines changed: 64 additions & 4 deletions

File tree

.github/workflows/actions-test.yml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Unit Tests
1+
name: Reporterplus marketplace actions test
22

33
on:
44
pull_request:
@@ -23,8 +23,27 @@ jobs:
2323
with:
2424
python-version: ${{ matrix.python-version }}
2525

26-
- name: 🧪 Run tests with coverage
26+
- name: 🧪 Run selenium test and generate report using marketplace plugin
2727
uses: reporterplus/pytest-html-plus-action@v1
2828
with:
29-
pytest-args: "--cov=pytest_html_plus tests/ --cov-fail-under=75 --cov-report=term --reruns 1"
30-
29+
pytest-args: "--cov=pytest_html_plus tests/e2e/test_selenium.py --cov-report=term --reruns 1"
30+
html-output: "report_output_selenium"
31+
capture-screenshots: "all"
32+
test-path: "tests/browser/test_selenium.py"
33+
34+
- name: 🧪 Run selenium test and generate report using marketplace plugin
35+
uses: reporterplus/pytest-html-plus-action@v1
36+
with:
37+
pytest-args: "--cov=pytest_html_plus --cov-report=term --reruns 1"
38+
html-output: "report_output_playwright"
39+
capture-screenshots: "all"
40+
test-path: "tests/browser/test_playwright.py"
41+
42+
- name: Upload reports
43+
uses: actions/upload-artifact@v4
44+
with:
45+
name: reports-${{ github.job }}-${{ github.run_number }}-${{ matrix.python-version }}
46+
path: |
47+
report_output_playwright/
48+
report_output_selenium/
49+

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ pytest-cov = "^6.2.1"
4747
playwright = "^1.53.0"
4848
pytest-playwright = "^0.7.0"
4949
pytest-xdist = "^3.8.0"
50+
selenium>=4.8.0
51+
webdriver-manager>=3.8.5
5052

5153
[build-system]
5254
requires = ["poetry-core"]

tests/browser/test_playwright.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
def test_example_com(page):
2+
# `page` is provided by pytest-playwright
3+
page.goto("https://example.com")
4+
assert "Example Domainn" in page.content()

tests/browser/test_selenium.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# tests/test_example_selenium.py
2+
import os
3+
from selenium import webdriver
4+
from selenium.webdriver.chrome.service import Service
5+
from selenium.webdriver.chrome.options import Options
6+
from webdriver_manager.chrome import ChromeDriverManager
7+
import time
8+
9+
10+
def make_driver(request):
11+
chrome_options = Options()
12+
# headless mode
13+
chrome_options.add_argument("--headless=new")
14+
chrome_options.add_argument("--no-sandbox")
15+
chrome_options.add_argument("--disable-dev-shm-usage")
16+
chrome_options.add_argument("--disable-gpu")
17+
chrome_options.add_argument("--window-size=1280,1024")
18+
svc = Service(ChromeDriverManager().install())
19+
drv = webdriver.Chrome(service=svc, options=chrome_options)
20+
request.node.page_for_screenshot = drv
21+
22+
# using webdriver-manager to install the chromedriver binary
23+
service = Service(ChromeDriverManager().install())
24+
driver = webdriver.Chrome(service=service, options=chrome_options)
25+
return driver
26+
27+
def test_example_dot_com_screenshot(request):
28+
driver = make_driver(request)
29+
try:
30+
url = "https://example.com"
31+
driver.get(url)
32+
time.sleep(10)
33+
assert "Example Domainn" in driver.page_source
34+
finally:
35+
driver.quit()

0 commit comments

Comments
 (0)