@@ -181,33 +181,7 @@ def create_asset(
181181 def append_extra_html (self , extra , extra_index , test_index ):
182182 href = None
183183 if extra .get ("format" ) == extras .FORMAT_IMAGE :
184- content = extra .get ("content" )
185- try :
186- is_uri_or_path = content .startswith (("file" , "http" )) or isfile (
187- content
188- )
189- except ValueError :
190- # On Windows, os.path.isfile throws this exception when
191- # passed a b64 encoded image.
192- is_uri_or_path = False
193- if is_uri_or_path :
194- if self .self_contained :
195- warnings .warn (
196- "Self-contained HTML report "
197- "includes link to external "
198- "resource: {}" .format (content )
199- )
200- html_div = html .a (html .img (src = content ), href = content )
201- elif self .self_contained :
202- src = "data:{};base64,{}" .format (extra .get ("mime_type" ), content )
203- html_div = html .img (src = src )
204- else :
205- content = b64decode (content .encode ("utf-8" ))
206- href = src = self .create_asset (
207- content , extra_index , test_index , extra .get ("extension" ), "wb"
208- )
209- html_div = html .a (html .img (src = src ), href = href )
210- self .additional_html .append (html .div (html_div , class_ = "image" ))
184+ self ._append_image (extra , extra_index , test_index )
211185
212186 elif extra .get ("format" ) == extras .FORMAT_HTML :
213187 self .additional_html .append (html .div (raw (extra .get ("content" ))))
@@ -235,6 +209,9 @@ def append_extra_html(self, extra, extra_index, test_index):
235209 elif extra .get ("format" ) == extras .FORMAT_URL :
236210 href = extra .get ("content" )
237211
212+ elif extra .get ("format" ) == extras .FORMAT_VIDEO :
213+ self ._append_video (extra , extra_index , test_index )
214+
238215 if href is not None :
239216 self .links_html .append (
240217 html .a (
@@ -276,6 +253,52 @@ def append_log_html(self, report, additional_html):
276253 log .append ("No log output captured." )
277254 additional_html .append (log )
278255
256+ def _make_media_html_div (
257+ self , extra , extra_index , test_index , base_extra_string , base_extra_class
258+ ):
259+ content = extra .get ("content" )
260+ try :
261+ is_uri_or_path = content .startswith (("file" , "http" )) or isfile (content )
262+ except ValueError :
263+ # On Windows, os.path.isfile throws this exception when
264+ # passed a b64 encoded image.
265+ is_uri_or_path = False
266+ if is_uri_or_path :
267+ if self .self_contained :
268+ warnings .warn (
269+ "Self-contained HTML report "
270+ "includes link to external "
271+ f"resource: { content } "
272+ )
273+
274+ html_div = html .a (
275+ raw (base_extra_string .format (extra .get ("content" ))), href = content
276+ )
277+ elif self .self_contained :
278+ src = f"data:{ extra .get ('mime_type' )} ;base64,{ content } "
279+ html_div = raw (base_extra_string .format (src ))
280+ else :
281+ content = b64decode (content .encode ("utf-8" ))
282+ href = src = self .create_asset (
283+ content , extra_index , test_index , extra .get ("extension" ), "wb"
284+ )
285+ html_div = html .a (class_ = base_extra_class , target = "_blank" , href = href )
286+ return html_div
287+
288+ def _append_image (self , extra , extra_index , test_index ):
289+ image_base = '<img src="{}"/>'
290+ html_div = self ._make_media_html_div (
291+ extra , extra_index , test_index , image_base , "image"
292+ )
293+ self .additional_html .append (html .div (html_div , class_ = "image" ))
294+
295+ def _append_video (self , extra , extra_index , test_index ):
296+ video_base = '<video controls><source src="{}" type="video/mp4"></video>'
297+ html_div = self ._make_media_html_div (
298+ extra , extra_index , test_index , video_base , "video"
299+ )
300+ self .additional_html .append (html .div (html_div , class_ = "video" ))
301+
279302 def _appendrow (self , outcome , report ):
280303 result = self .TestResult (outcome , report , self .logfile , self .config )
281304 if result .row_table is not None :
0 commit comments