Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
name: Python package
name: Pytest

on: [push]
on: [ push ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
python-version: [ 3.8 ]

steps:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Test with pytest
env:
TOKEN: ${{ secrets.TOKEN }}
SELENIUM_HUB_HOST: 'http://localhost:4444/wd/hub'
GITHUB_RUN: True
run: |
pytest
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Install browsers
run: python -m playwright install
- name: Test with pytest
env:
GITHUB_RUN: True
run: |
pytest
2 changes: 0 additions & 2 deletions execute_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
source venv/bin/activate
echo "-> Installing dependencies"
pip install -r requirements.txt --quiet
echo "-> Installing Playwright browsers"
python3.7 -m playwright install

echo "-> Removing old Allure results"
rm -r allure-results/* || echo "No results"
Expand Down
1 change: 0 additions & 1 deletion page_objects/base_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,3 @@ def is_element_hidden(self, locator: str) -> bool:
return True
except TError:
return False

30 changes: 6 additions & 24 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@
import asyncio
import os

import allure
import pytest
from playwright import sync_playwright


# Will mark all the tests as async
def pytest_collection_modifyitems(items):
for item in items:
item.add_marker(pytest.mark.asyncio)


@pytest.fixture(scope="session")
def event_loop():
loop = asyncio.get_event_loop()
yield loop
loop.close()


@pytest.fixture(scope='session')
def page():
with sync_playwright() as play:
if os.getenv('DOCKER_RUN'):
if os.getenv('DOCKER_RUN') or os.getenv('GITHUB_RUN'):
browser = play.chromium.launch(headless=True, args=['--no-sandbox'])
else:
browser = play.firefox.launch(headless=False)
browser = play.chromium.launch(headless=False)
page = browser.newPage()
global PAGE
PAGE = page
Expand All @@ -44,11 +30,7 @@ def pytest_runtest_makereport():
if test_result.when in ["setup", "call"]:
xfail = hasattr(test_result, 'wasxfail')
if test_result.failed or (test_result.skipped and xfail):
loop = asyncio.get_event_loop()
screenshot = loop.run_until_complete(get_screenshot())
allure.attach(screenshot, name='screenshot', attachment_type=allure.attachment_type.PNG)


def get_screenshot():
global PAGE
return PAGE.screenshot()
global PAGE
if PAGE:
allure.attach(PAGE.screenshot(), name='screenshot', attachment_type=allure.attachment_type.PNG)
allure.attach(PAGE.content(), name='html_source', attachment_type=allure.attachment_type.HTML)
8 changes: 5 additions & 3 deletions tests/test_shop.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

@allure.story('Shop')
class TestShop:
@staticmethod
@allure.title('Order T-Shirt')
def test_order_t_shirt(self, page):
def test_order_t_shirt(page):
shop_page = ShopPage(page)
registration_page = RegistrationPage(page)
with step('Open site'):
Expand All @@ -31,9 +32,10 @@ def test_order_t_shirt(self, page):
with step('Check at least 1 order present'):
assert shop_page.is_order_present(), 'Order missed'

@staticmethod
@allure.title('Negative to check attachments')
@pytest.mark.skipif(os.getenv('GITHUB_RUN'), reason='To avoid build failing')
def test_negative(self, page):
@pytest.mark.skipif(os.getenv('GITHUB_RUN') is not None, reason='GitHub actions')
def test_negative(page):
shop_page = ShopPage(page)
with step('Open site'):
shop_page.open_site()
Expand Down