@@ -53,6 +53,23 @@ def skip_fail_options(fn):
5353 return fn
5454
5555
56+ def skip_or_fail (response , skip , fail ):
57+ if skip and fail :
58+ raise click .ClickException ("--skip and --fail cannot be used together" )
59+ if str (response .status )[0 ] in ("4" , "5" ):
60+ if skip :
61+ click .echo (
62+ "{} error for {}, skipping" .format (response .status , response .url ),
63+ err = True ,
64+ )
65+ # Exit with a 0 status code
66+ raise SystemExit
67+ elif fail :
68+ raise click .ClickException (
69+ "{} error for {}" .format (response .status , response .url )
70+ )
71+
72+
5673def reduced_motion_option (fn ):
5774 click .option (
5875 "--reduced-motion" ,
@@ -413,7 +430,11 @@ def multi(
413430 continue
414431 try :
415432 take_shot (
416- context , shot , log_console = log_console , skip = skip , fail = fail ,
433+ context ,
434+ shot ,
435+ log_console = log_console ,
436+ skip = skip ,
437+ fail = fail ,
417438 )
418439 except TimeoutError as e :
419440 if fail_on_error :
@@ -445,7 +466,8 @@ def multi(
445466 help = "Wait this many milliseconds before failing" ,
446467)
447468@log_console_option
448- def accessibility (url , auth , output , javascript , timeout , log_console ):
469+ @skip_fail_options
470+ def accessibility (url , auth , output , javascript , timeout , log_console , skip , fail ):
449471 """
450472 Dump the Chromium accessibility tree for the specifed page
451473
@@ -459,7 +481,8 @@ def accessibility(url, auth, output, javascript, timeout, log_console):
459481 page = context .new_page ()
460482 if log_console :
461483 page .on ("console" , console_log )
462- page .goto (url )
484+ response = page .goto (url )
485+ skip_or_fail (response , skip , fail )
463486 if javascript :
464487 _evaluate_js (page , javascript )
465488 snapshot = page .accessibility .snapshot ()
@@ -501,6 +524,7 @@ def accessibility(url, auth, output, javascript, timeout, log_console):
501524@user_agent_option
502525@reduced_motion_option
503526@log_console_option
527+ @skip_fail_options
504528def javascript (
505529 url ,
506530 javascript ,
@@ -512,6 +536,8 @@ def javascript(
512536 user_agent ,
513537 reduced_motion ,
514538 log_console ,
539+ skip ,
540+ fail ,
515541):
516542 """
517543 Execute JavaScript against the page and return the result as JSON
@@ -552,7 +578,8 @@ def javascript(
552578 page = context .new_page ()
553579 if log_console :
554580 page .on ("console" , console_log )
555- page .goto (url )
581+ response = page .goto (url )
582+ skip_or_fail (response , skip , fail )
556583 result = _evaluate_js (page , javascript )
557584 browser_obj .close ()
558585 if raw :
@@ -613,6 +640,7 @@ def javascript(
613640)
614641@click .option ("--print-background" , is_flag = True , help = "Print background graphics" )
615642@log_console_option
643+ @skip_fail_options
616644def pdf (
617645 url ,
618646 auth ,
@@ -627,6 +655,8 @@ def pdf(
627655 scale ,
628656 print_background ,
629657 log_console ,
658+ skip ,
659+ fail ,
630660):
631661 """
632662 Create a PDF of the specified page
@@ -651,7 +681,8 @@ def pdf(
651681 page = context .new_page ()
652682 if log_console :
653683 page .on ("console" , console_log )
654- page .goto (url )
684+ response = page .goto (url )
685+ skip_or_fail (response , skip , fail )
655686 if wait :
656687 time .sleep (wait / 1000 )
657688 if javascript :
@@ -709,6 +740,7 @@ def pdf(
709740@log_console_option
710741@browser_option
711742@user_agent_option
743+ @skip_fail_options
712744def html (
713745 url ,
714746 auth ,
@@ -719,6 +751,8 @@ def html(
719751 log_console ,
720752 browser ,
721753 user_agent ,
754+ skip ,
755+ fail ,
722756):
723757 """
724758 Output the final HTML of the specified page
@@ -741,7 +775,8 @@ def html(
741775 page = context .new_page ()
742776 if log_console :
743777 page .on ("console" , console_log )
744- page .goto (url )
778+ response = page .goto (url )
779+ skip_or_fail (response , skip , fail )
745780 if wait :
746781 time .sleep (wait / 1000 )
747782 if javascript :
0 commit comments