diff --git a/screenpy_selenium/actions/enter.py b/screenpy_selenium/actions/enter.py index fcdba36..f2ced64 100644 --- a/screenpy_selenium/actions/enter.py +++ b/screenpy_selenium/actions/enter.py @@ -111,9 +111,9 @@ def then_press(self: SelfEnter, *keys: str) -> SelfEnter: def describe(self: SelfEnter) -> str: """Describe the Action in present tense.""" - return f'Enter "{self.text_to_log}" into the {self.target}.' + return f"Enter {self.text_to_log!r} into the {self.target}." - @beat('{} enters "{text_to_log}" into the {target}.') + @beat("{} enters '{text_to_log}' into the {target}.") def perform_as(self: SelfEnter, the_actor: Actor) -> None: """Direct the Actor to enter the text into the element.""" if self.target is None: @@ -137,7 +137,7 @@ def perform_as(self: SelfEnter, the_actor: Actor) -> None: ) raise DeliveryError(msg) from e - @beat(' Enter "{text_to_log}" into the {target}!') + @beat(" Enter '{text_to_log}' into the {target}!") def add_to_chain( self: SelfEnter, the_actor: Actor, the_chain: ActionChains ) -> None: diff --git a/tests/test_actions.py b/tests/test_actions.py index b443858..033dfe8 100644 --- a/tests/test_actions.py +++ b/tests/test_actions.py @@ -1,5 +1,6 @@ from __future__ import annotations +import logging from typing import cast from unittest import mock @@ -419,11 +420,11 @@ def test_exception(self, Tester: Actor) -> None: def test_describe(self) -> None: assert ( - Enter("blah").into(TARGET).describe() == f'Enter "blah" into the {TARGET}.' + Enter("blah").into(TARGET).describe() == f"Enter 'blah' into the {TARGET}." ) assert ( Enter.the_secret("blah").into(TARGET).describe() - == f'Enter "[CENSORED]" into the {TARGET}.' + == f"Enter '[CENSORED]' into the {TARGET}." ) def test_subclass(self) -> None: @@ -435,6 +436,32 @@ def new_method(self) -> bool: assert SubEnter.the_text("blah").new_method() is True + def test_beat_logging( + self, Tester: Actor, caplog: pytest.LogCaptureFixture + ) -> None: + target, element = get_mocked_target_and_element() + text = 'Speak "Friend" and Enter' + caplog.set_level(logging.INFO) + Enter.the_text(text).into_the(target).perform_as(Tester) + + assert [r.msg for r in caplog.records] == [ + f"Tester enters 'Speak \"Friend\" and Enter' into the {target}." + ] + + def test_beat_logging_chain( + self, Tester: Actor, caplog: pytest.LogCaptureFixture + ) -> None: + chain = get_mocked_chain() + target, element = get_mocked_target_and_element() + text = "Hello, Champion City." + + caplog.set_level(logging.INFO) + Enter.the_text(text).into_the(target).add_to_chain(Tester, chain) + + assert [r.msg for r in caplog.records] == [ + f" Enter 'Hello, Champion City.' into the {target}!" + ] + class TestEnter2FAToken: def test_can_be_instantiated(self) -> None: