1- from pathlib import Path
1+ import os
22
33import pytest
44from playwright .sync_api import sync_playwright
5- from slugify import slugify
5+ from py . xml import html # type: ignore
66
77from config .constants import URL
88
1111def login_logout ():
1212 # perform login and browser close once in a session
1313 with sync_playwright () as p :
14- browser = p .chromium .launch (headless = False )
15- context = browser .new_context ()
16- context .set_default_timeout (80000 )
14+ browser = p .chromium .launch (headless = False , args = [ "--start-maximized" ] )
15+ context = browser .new_context (no_viewport = True )
16+ context .set_default_timeout (120000 )
1717 page = context .new_page ()
1818 # Navigate to the login URL
1919 page .goto (URL )
@@ -27,25 +27,24 @@ def login_logout():
2727
2828@pytest .hookimpl (tryfirst = True )
2929def pytest_html_report_title (report ):
30- report .title = "Automation_DOCGEN "
30+ report .title = "Automation_DocGen "
3131
3232
33+ # Add a column for descriptions
34+ def pytest_html_results_table_header (cells ):
35+ cells .insert (1 , html .th ("Description" ))
36+
37+
38+ def pytest_html_results_table_row (report , cells ):
39+ cells .insert (1 , html .td (report .description if hasattr (report , "description" ) else "" ))
40+
41+
42+ # Add logs and docstring to report
3343@pytest .hookimpl (hookwrapper = True )
3444def pytest_runtest_makereport (item , call ):
35- pytest_html = item .config .pluginmanager .getplugin ("html" )
3645 outcome = yield
37- screen_file = ""
3846 report = outcome .get_result ()
39- extra = getattr (report , "extra" , [])
40- if report .when == "call" :
41- if report .failed and "page" in item .funcargs :
42- page = item .funcargs ["page" ]
43- screenshot_dir = Path ("screenshots" )
44- screenshot_dir .mkdir (exist_ok = True )
45- screen_file = str (screenshot_dir / f"{ slugify (item .nodeid )} .png" )
46- page .screenshot (path = screen_file )
47- xfail = hasattr (report , "wasxfail" )
48- if (report .skipped and xfail ) or (report .failed and not xfail ):
49- # add the screenshots to the html report
50- extra .append (pytest_html .extras .png (screen_file ))
51- report .extra = extra
47+ report .description = str (item .function .__doc__ )
48+ os .makedirs ("logs" , exist_ok = True )
49+ extra = getattr (report , 'extra' , [])
50+ report .extra = extra
0 commit comments