Skip to content

Commit

Permalink
adding the ability to adjust the duration of ActionChains
Browse files Browse the repository at this point in the history
  • Loading branch information
bandophahita committed Mar 1, 2024
1 parent 5c602c8 commit a304db5
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 6 deletions.
6 changes: 4 additions & 2 deletions screenpy_selenium/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@
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
from .resolutions import * # noqa: F403
from .target import Target

__all__ = [
"Target",
"TargetingError",
"BrowsingError",
"Chainable",
"settings",
"Target",
"TargetingError",
]

__all__ += abilities.__all__ + actions.__all__ + questions.__all__ + resolutions.__all__
3 changes: 2 additions & 1 deletion screenpy_selenium/actions/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion screenpy_selenium/actions/double_click.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down
3 changes: 2 additions & 1 deletion screenpy_selenium/actions/move_mouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down
3 changes: 2 additions & 1 deletion screenpy_selenium/actions/right_click.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down
24 changes: 24 additions & 0 deletions screenpy_selenium/configuration.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit a304db5

Please sign in to comment.