1+ import datetime
2+ import os
13import pytest
4+ import allure
5+ import glob
6+ from Library .store import Store
27
38
49@pytest .fixture (autouse = True )
510def before_each ():
611 print ('*-* Before each INITIALIZATION' )
7- yield
12+ try :
13+ yield
14+ for driver in Store .drivers :
15+ root_dir = os .path .dirname (os .path .abspath (__file__ )).replace ("/Tests" , "" )
16+ config_path = root_dir + '/reports/screenshots/img%s.png' % datetime .datetime .now ().strftime ("%Y%m%d-%H%M%S" )
17+ driver .save_screenshot (config_path )
18+ name = 'img%s.png' % datetime .datetime .now ().strftime ("%Y%m%d-%H%M%S" )
19+ allure .attach (config_path , name = name , attachment_type = "PNG" )
20+ except Exception as e :
21+ print (e )
822 print ('*-* After each END' )
923
1024
1125@pytest .fixture (scope = 'module' , autouse = True )
1226def before_module ():
1327 print ('*-* Before module INITIALIZATION' )
1428 yield
29+ for driver in Store .drivers :
30+ driver .quit ()
1531 print ('*-* After module END' )
1632
1733
@@ -21,27 +37,32 @@ def pytest_configure(config):
2137 This hook is called for every plugin and initial conftest
2238 file after command line options have been parsed.
2339 """
24- print ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ pytest_configure" )
40+ print ("*-* pytest_configure" )
41+ root_dir = os .path .dirname (os .path .abspath (__file__ )).replace ("/Tests" , "" )
42+ config_path = root_dir + '/reports/screenshots/*.png'
43+ for CleanUp in glob .glob (config_path ):
44+ print (CleanUp )
45+ os .remove (CleanUp )
2546
2647
2748def pytest_sessionstart (session ):
2849 """
2950 Called after the Session object has been created and
3051 before performing collection and entering the run test loop.
3152 """
32- print ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ pytest_sessionstart" )
53+ print ("*-* pytest_sessionstart" )
3354
3455
3556def pytest_sessionfinish (session , exitstatus ):
3657 """
3758 Called after whole test run finished, right before
3859 returning the exit status to the system.
3960 """
40- print ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ pytest_sessionfinish" )
61+ print ("*-* pytest_sessionfinish" )
4162
4263
4364def pytest_unconfigure (config ):
4465 """
4566 called before test process is exited.
4667 """
47- print ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ pytest_unconfigure" )
68+ print ("*-* pytest_unconfigure" )
0 commit comments