1- import asyncio
21import os
32
43import allure
54import pytest
65from 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' )
239def 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 )
0 commit comments