1+ import pytest
12from unittest .mock import patch
23import helpers
34
@@ -28,6 +29,20 @@ def test_return_statement_gets_wrapped():
2829 assert _evaluated_expression (captured ) == "(function(){const x = 1; return x})()"
2930
3031
32+ def test_js_raises_on_runtime_exception ():
33+ def fake_cdp (method , ** kwargs ):
34+ return {
35+ "exceptionDetails" : {
36+ "text" : "Uncaught ReferenceError" ,
37+ "exception" : {"description" : "ReferenceError: missing is not defined" },
38+ }
39+ }
40+
41+ with patch ("helpers.cdp" , side_effect = fake_cdp ):
42+ with pytest .raises (RuntimeError , match = "missing is not defined" ):
43+ helpers .js ("missing.value" )
44+
45+
3146def test_wait_for_js_returns_first_truthy_value ():
3247 with patch ("helpers.js" , side_effect = [False , None , {"ready" : True }]), \
3348 patch ("helpers.time.sleep" ) as sleep :
@@ -36,6 +51,15 @@ def test_wait_for_js_returns_first_truthy_value():
3651 assert sleep .call_count == 2
3752
3853
54+ def test_wait_for_js_propagates_js_errors ():
55+ with patch ("helpers.js" , side_effect = RuntimeError ("JavaScript evaluation failed" )), \
56+ patch ("helpers.time.sleep" ) as sleep :
57+ with pytest .raises (RuntimeError , match = "JavaScript evaluation failed" ):
58+ helpers .wait_for_js ("missing.value" , timeout = 1 , interval = 0.01 )
59+
60+ sleep .assert_not_called ()
61+
62+
3963def test_wait_for_selector_uses_visible_predicate ():
4064 with patch ("helpers.wait_for_js" , return_value = True ) as wait :
4165 assert helpers .wait_for_selector ("button[aria-label='Save']" , timeout = 3 , visible = True )
0 commit comments