Skip to content

Commit 5569133

Browse files
thalissonvs3-Tokisaki-Kurumi
authored andcommitted
test: add test for script execution with element and missing argument
1 parent bb5a7f0 commit 5569133

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

tests/test_browser/test_browser_tab.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,18 @@ async def test_execute_script_argument_without_element_raises_exception(self, ta
545545
assert str(exc_info.value) == 'Script contains "argument" but no element was provided'
546546
tab._connection_handler.execute_command.assert_not_called()
547547

548+
@pytest.mark.asyncio
549+
async def test_execute_script_element_without_argument_raises_exception(self, tab):
550+
"""Test execute_script raises exception when element is provided but script doesn't contain 'argument'."""
551+
element = MagicMock()
552+
element._object_id = 'test-object-id'
553+
554+
with pytest.raises(InvalidScriptWithElement) as exc_info:
555+
await tab.execute_script('console.log("test")', element)
556+
557+
assert str(exc_info.value) == 'Script does not contain "argument"'
558+
tab._connection_handler.execute_command.assert_not_called()
559+
548560
@pytest.mark.asyncio
549561
async def test_execute_script_with_element_already_function(self, tab):
550562
"""Test execute_script with element when script is already a function."""

0 commit comments

Comments
 (0)