diff --git a/screenpy_selenium/__init__.py b/screenpy_selenium/__init__.py index 6599584..312a1b8 100644 --- a/screenpy_selenium/__init__.py +++ b/screenpy_selenium/__init__.py @@ -19,6 +19,7 @@ from . import abilities, actions, questions, resolutions from .abilities import * # noqa: F403 from .actions import * # noqa: F403 +from .configuration import settings from .exceptions import BrowsingError, TargetingError from .protocols import Chainable from .questions import * # noqa: F403 @@ -26,10 +27,11 @@ from .target import Target __all__ = [ - "Target", - "TargetingError", "BrowsingError", "Chainable", + "settings", + "Target", + "TargetingError", ] __all__ += abilities.__all__ + actions.__all__ + questions.__all__ + resolutions.__all__ diff --git a/screenpy_selenium/actions/chain.py b/screenpy_selenium/actions/chain.py index 75dcdfb..3a554e6 100644 --- a/screenpy_selenium/actions/chain.py +++ b/screenpy_selenium/actions/chain.py @@ -9,6 +9,7 @@ from selenium.webdriver.common.action_chains import ActionChains from ..abilities import BrowseTheWeb +from ..configuration import settings from ..protocols import Chainable if TYPE_CHECKING: @@ -41,7 +42,7 @@ def describe(self) -> str: def perform_as(self, the_actor: Actor) -> None: """Choreograph the Actions and direct the Actor to perform the chain.""" browser = the_actor.ability_to(BrowseTheWeb).browser - the_chain = ActionChains(browser) + the_chain = ActionChains(browser, settings.CHAIN_DURATION) for action in self.actions: if not isinstance(action, Chainable): diff --git a/screenpy_selenium/actions/double_click.py b/screenpy_selenium/actions/double_click.py index 1a4186c..fb2847e 100644 --- a/screenpy_selenium/actions/double_click.py +++ b/screenpy_selenium/actions/double_click.py @@ -8,6 +8,7 @@ from selenium.webdriver.common.action_chains import ActionChains from ..abilities import BrowseTheWeb +from ..configuration import settings if TYPE_CHECKING: from screenpy.actor import Actor @@ -69,7 +70,7 @@ def describe(self) -> str: def perform_as(self, the_actor: Actor) -> None: """Direct the Actor to double-click on the element.""" browser = the_actor.ability_to(BrowseTheWeb).browser - the_chain = ActionChains(browser) # type: ignore[arg-type] + the_chain = ActionChains(browser, settings.CHAIN_DURATION) self._add_action_to_chain(the_actor, the_chain) the_chain.perform() diff --git a/screenpy_selenium/actions/move_mouse.py b/screenpy_selenium/actions/move_mouse.py index 0bac49a..5428bc3 100644 --- a/screenpy_selenium/actions/move_mouse.py +++ b/screenpy_selenium/actions/move_mouse.py @@ -9,6 +9,7 @@ from selenium.webdriver.common.action_chains import ActionChains from ..abilities import BrowseTheWeb +from ..configuration import settings if TYPE_CHECKING: from screenpy.actor import Actor @@ -118,7 +119,7 @@ def describe(self) -> str: def perform_as(self, the_actor: Actor) -> None: """Direct the Actor to move the mouse.""" browser = the_actor.ability_to(BrowseTheWeb).browser - the_chain = ActionChains(browser) # type: ignore[arg-type] + the_chain = ActionChains(browser, settings.CHAIN_DURATION) self._add_action_to_chain(the_actor, the_chain) the_chain.perform() diff --git a/screenpy_selenium/actions/right_click.py b/screenpy_selenium/actions/right_click.py index 73f9f20..b08fb99 100644 --- a/screenpy_selenium/actions/right_click.py +++ b/screenpy_selenium/actions/right_click.py @@ -8,6 +8,7 @@ from selenium.webdriver.common.action_chains import ActionChains from ..abilities import BrowseTheWeb +from ..configuration import settings if TYPE_CHECKING: from screenpy import Actor @@ -73,7 +74,7 @@ def describe(self) -> str: def perform_as(self, the_actor: Actor) -> None: """Direct the Actor to right-click on the element.""" browser = the_actor.ability_to(BrowseTheWeb).browser - the_chain = ActionChains(browser) # type: ignore[arg-type] + the_chain = ActionChains(browser, settings.CHAIN_DURATION) self._add_action_to_chain(the_actor, the_chain) the_chain.perform() diff --git a/screenpy_selenium/configuration.py b/screenpy_selenium/configuration.py new file mode 100644 index 0000000..4292cd9 --- /dev/null +++ b/screenpy_selenium/configuration.py @@ -0,0 +1,24 @@ +"""Define settings for the StdOutAdapter.""" + +from pydantic_settings import SettingsConfigDict +from screenpy.configuration import ScreenPySettings + + +class ScreenPySeleniumSettings(ScreenPySettings): + """Settings for the ScreenPySelenium. + + To change these settings using environment variables, use the prefix + ``SCREENPY_SELENIUM_``, like so:: + + SCREENPY_SELENIUM_CHAIN_DURATION=50 # sets the indent char to 50 + """ + + _tool_path = "screenpy_selenium" + model_config = SettingsConfigDict(env_prefix="SCREENPY_SELENIUM_") + + CHAIN_DURATION: int = 10 + """Whether or not to use indentation in logging.""" + + +# initialized instance +settings = ScreenPySeleniumSettings()