Skip to content

Commit

Permalink
proof of concept that Self works in 3.8+
Browse files Browse the repository at this point in the history
  • Loading branch information
bandophahita committed Feb 7, 2024
1 parent 89b64d7 commit b0a6013
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions screenpy_selenium/actions/open.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
from __future__ import annotations

import os
from typing import TYPE_CHECKING, TypeVar
from typing import TYPE_CHECKING

from screenpy.pacing import beat
from typing_extensions import Self

from ..abilities import BrowseTheWeb

if TYPE_CHECKING:
from screenpy import Actor

SelfOpen = TypeVar("SelfOpen", bound="Open")


class Open:
"""Go to a specific URL!
Expand Down Expand Up @@ -42,7 +41,7 @@ class Open:
"""

@classmethod
def their_browser_on(cls: type[SelfOpen], location: str | object) -> SelfOpen:
def their_browser_on(cls, location: str | object) -> Self:
"""
Provide a URL to visit.
Expand All @@ -52,21 +51,21 @@ def their_browser_on(cls: type[SelfOpen], location: str | object) -> SelfOpen:
return cls(location=location)

@classmethod
def browser_on(cls: type[SelfOpen], location: str | object) -> SelfOpen:
def browser_on(cls, location: str | object) -> Self:
"""Alias for :meth:`~screenpy_selenium.actions.Open.their_browser_on`."""
return cls.their_browser_on(location=location)

def describe(self: SelfOpen) -> str:
def describe(self) -> str:
"""Describe the Action in present tense."""
return f"Visit {self.url}."

@beat("{} visits {url}")
def perform_as(self: SelfOpen, the_actor: Actor) -> None:
def perform_as(self, the_actor: Actor) -> None:
"""Direct the Actor to visit the specified URL."""
browser = the_actor.ability_to(BrowseTheWeb).browser
browser.get(self.url)

def __init__(self: SelfOpen, location: str | object) -> None:
def __init__(self, location: str | object) -> None:
url = getattr(location, "url", location)
url = f'{os.getenv("BASE_URL", "")}{url}'
self.url = url

0 comments on commit b0a6013

Please sign in to comment.