diff --git a/screenpy_selenium/actions/enter.py b/screenpy_selenium/actions/enter.py index 88692e2..33d69b8 100644 --- a/screenpy_selenium/actions/enter.py +++ b/screenpy_selenium/actions/enter.py @@ -107,9 +107,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: @@ -132,7 +132,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 c2d9667..cdeed65 100644 --- a/tests/test_actions.py +++ b/tests/test_actions.py @@ -1,3 +1,4 @@ +import logging from unittest import mock import pytest @@ -411,11 +412,11 @@ def test_exception(self, Tester) -> 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: @@ -427,6 +428,32 @@ def new_method(self): 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: