Skip to content

Commit 21acebe

Browse files
authored
Update Github actions (#1)
1 parent 2bfd766 commit 21acebe

File tree

5 files changed

+31
-45
lines changed

5 files changed

+31
-45
lines changed

.github/workflows/pytest.yml

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
1-
name: Python package
1+
name: Pytest
22

3-
on: [push]
3+
on: [ push ]
44

55
jobs:
66
build:
77

88
runs-on: ubuntu-latest
99
strategy:
1010
matrix:
11-
python-version: [3.8]
11+
python-version: [ 3.8 ]
1212

1313
steps:
14-
- name: Install dependencies
15-
run: |
16-
python -m pip install --upgrade pip
17-
pip install flake8 pytest
18-
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
19-
- name: Test with pytest
20-
env:
21-
TOKEN: ${{ secrets.TOKEN }}
22-
SELENIUM_HUB_HOST: 'http://localhost:4444/wd/hub'
23-
GITHUB_RUN: True
24-
run: |
25-
pytest
14+
- uses: actions/checkout@v2
15+
- name: Set up Python ${{ matrix.python-version }}
16+
uses: actions/setup-python@v2
17+
with:
18+
python-version: ${{ matrix.python-version }}
19+
- name: Install dependencies
20+
run: |
21+
python -m pip install --upgrade pip
22+
pip install flake8 pytest
23+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
24+
- name: Install browsers
25+
run: python -m playwright install
26+
- name: Test with pytest
27+
env:
28+
GITHUB_RUN: True
29+
run: |
30+
pytest

execute_tests.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
source venv/bin/activate
33
echo "-> Installing dependencies"
44
pip install -r requirements.txt --quiet
5-
echo "-> Installing Playwright browsers"
6-
python3.7 -m playwright install
75

86
echo "-> Removing old Allure results"
97
rm -r allure-results/* || echo "No results"

page_objects/base_page.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,3 @@ def is_element_hidden(self, locator: str) -> bool:
5151
return True
5252
except TError:
5353
return False
54-

tests/conftest.py

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,17 @@
1-
import asyncio
21
import os
32

43
import allure
54
import pytest
65
from playwright import sync_playwright
76

87

9-
# Will mark all the tests as async
10-
def pytest_collection_modifyitems(items):
11-
for item in items:
12-
item.add_marker(pytest.mark.asyncio)
13-
14-
15-
@pytest.fixture(scope="session")
16-
def event_loop():
17-
loop = asyncio.get_event_loop()
18-
yield loop
19-
loop.close()
20-
21-
228
@pytest.fixture(scope='session')
239
def page():
2410
with sync_playwright() as play:
25-
if os.getenv('DOCKER_RUN'):
11+
if os.getenv('DOCKER_RUN') or os.getenv('GITHUB_RUN'):
2612
browser = play.chromium.launch(headless=True, args=['--no-sandbox'])
2713
else:
28-
browser = play.firefox.launch(headless=False)
14+
browser = play.chromium.launch(headless=False)
2915
page = browser.newPage()
3016
global PAGE
3117
PAGE = page
@@ -44,11 +30,7 @@ def pytest_runtest_makereport():
4430
if test_result.when in ["setup", "call"]:
4531
xfail = hasattr(test_result, 'wasxfail')
4632
if test_result.failed or (test_result.skipped and xfail):
47-
loop = asyncio.get_event_loop()
48-
screenshot = loop.run_until_complete(get_screenshot())
49-
allure.attach(screenshot, name='screenshot', attachment_type=allure.attachment_type.PNG)
50-
51-
52-
def get_screenshot():
53-
global PAGE
54-
return PAGE.screenshot()
33+
global PAGE
34+
if PAGE:
35+
allure.attach(PAGE.screenshot(), name='screenshot', attachment_type=allure.attachment_type.PNG)
36+
allure.attach(PAGE.content(), name='html_source', attachment_type=allure.attachment_type.HTML)

tests/test_shop.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010

1111
@allure.story('Shop')
1212
class TestShop:
13+
@staticmethod
1314
@allure.title('Order T-Shirt')
14-
def test_order_t_shirt(self, page):
15+
def test_order_t_shirt(page):
1516
shop_page = ShopPage(page)
1617
registration_page = RegistrationPage(page)
1718
with step('Open site'):
@@ -31,9 +32,10 @@ def test_order_t_shirt(self, page):
3132
with step('Check at least 1 order present'):
3233
assert shop_page.is_order_present(), 'Order missed'
3334

35+
@staticmethod
3436
@allure.title('Negative to check attachments')
35-
@pytest.mark.skipif(os.getenv('GITHUB_RUN'), reason='To avoid build failing')
36-
def test_negative(self, page):
37+
@pytest.mark.skipif(os.getenv('GITHUB_RUN') is not None, reason='GitHub actions')
38+
def test_negative(page):
3739
shop_page = ShopPage(page)
3840
with step('Open site'):
3941
shop_page.open_site()

0 commit comments

Comments
 (0)