@@ -16,25 +16,25 @@ def _reduce_colors(image_bytes: bytes) -> bytes:
1616 return output_io .getvalue ()
1717
1818
19- def step (title : str , * , attach_screenshot : bool = True ):
19+ def _add_screenshot (page , name : str ) -> None :
20+ screenshot_bytes = page .screenshot (full_page = True , scale = "css" )
21+ reduced_bytes = _reduce_colors (screenshot_bytes )
22+ allure .attach (
23+ reduced_bytes ,
24+ name = name ,
25+ attachment_type = allure .attachment_type .PNG ,
26+ )
27+
28+
29+ def step (title : str ):
2030 def decorator (func ):
2131 @wraps (func )
2232 def wrapper (self , * args , ** kwargs ):
2333 with allure .step (title ):
2434 try :
2535 return_value = func (self , * args , ** kwargs )
2636 except Exception :
27- if attach_screenshot :
28- screenshot_bytes = self .page .screenshot (
29- full_page = True ,
30- scale = "css" ,
31- )
32- reduced_bytes = _reduce_colors (screenshot_bytes )
33- allure .attach (
34- reduced_bytes ,
35- name = "Screenshot on failure" ,
36- attachment_type = allure .attachment_type .PNG ,
37- )
37+ _add_screenshot (self .page , name = "Screenshot on failure" )
3838 raise
3939
4040 coverage = kwargs .get ("coverage" )
@@ -45,14 +45,8 @@ def wrapper(self, *args, **kwargs):
4545 attachment_type = allure .attachment_type .TEXT ,
4646 )
4747
48- if attach_screenshot :
49- screenshot_bytes = self .page .screenshot (full_page = True , scale = "css" )
50- reduced_bytes = _reduce_colors (screenshot_bytes )
51- allure .attach (
52- reduced_bytes ,
53- name = "Screenshot" ,
54- attachment_type = allure .attachment_type .PNG ,
55- )
48+ if os .getenv ("SCREENSHOT_ALL_STEPS" , "false" ).lower () == "true" :
49+ _add_screenshot (self .page , name = "Screenshot" )
5650
5751 return return_value
5852
0 commit comments