Actions API
These are the Actions included in ScreenPy.
AttachTheFile
Aliases: AttachAFile
,
AttachFile
,
AttachesTheFile
,
AttachesAFile
,
AttachesFile
- class AttachTheFile(filepath: str, **kwargs: Any)
Attach a file for Narration.
Supports passing arbitrary keyword arguments along to the adapters hooked up to the Narrator’s microphone.
Examples:
the_actor.attempts_to(AttachTheFile(filepath)) the_actor.attempts_to( AttachTheFile(filepath, attachment_type=AttachmentTypes.PNG) )
Debug
- class Debug
Activate a debugger to step through Actions.
In long series of Actions, it can be difficult to drop a debugger in the right place. This Action can be placed anywhere in the list to give you a debugger in the middle of the Action list. This Action uses Python 3.7+’s breakpoint() call if it can, otherwise it will default to pdb.set_trace().
Examples:
the_actor.attempts_to( Click.on_the(SIGN_IN_BUTTON), # ... Debug(), Wait.for_the(SURPRISE_CONFETTI).to_disappear(), # ... )
Eventually
- class Eventually(performable: Performable)
Retry a performable that will eventually (hopefully) succeed.
Eventually
ignores all errors for the duration of its attempt. If the Actor is not able to complete the given Action or Task within the timeout period, aDeliveryError
is raised (from the last caught exception).Examples:
the_actor.should( Eventually( See.the(Text.of_the(WELCOME_BANNER), ContainsTheText("Welcome!")) ), ) the_actor.attempts_to( Eventually(Click.on_the(BUTTON)).trying_every(100).milliseconds() ) the_actor.was_able_to( Eventually(DismissAlert()) .trying_for(5) .seconds() .polling_every(500) .milliseconds(), )
Log
- class Log(question: T_Q)
Log the answer to a Question, or anything.
Probably most useful for debugging a test, or for announcing the answer to a Question for the record.
- Examples::
the_actor.attempts_to(Log(HowManyBirdsAreInTheSky()))
the_actor.attempts_to(Log.the(Number.of(SNAKES_ON_THE_PLANE)))
- classmethod the(question: T_Q) Self
Supply the Question to answer.
MakeNote
Aliases: TakeNote
,
MakesNote
,
TakesNote
- class MakeNote(question: T_Q, key: str | None = None)
Make a note of a value or the answer to a Question.
You can access noted values with Included Directions at any point during a test, except immediately after making the note. See https://screenpy-docs.readthedocs.io/en/latest/cookbook.html#using-makenote.
Examples:
the_actor.attempts_to( MakeNote.of_the(Number.of(BALLOONS)).as_("excitement gauge"), ) the_actor.attempts_to(MakeNote.of_the(items).as_("items list"))
- classmethod of(question: T_Q) Self
Supply the Question to answer and its arguments.
- Aliases:
Pause
Aliases: Sleep
,
Pauses
,
Sleeps
- class Pause(number: float)
Pause the Actor’s Actions for a set amount of time.
This class should only be used when absolutely necessary. Hard waits are the worst of all wait strategies; providing a reason will help explain why pausing is necessary. You must call one of the “…_because” methods to pass a reason for pausing. An
UnableToAct
exception will be raised if no reason was given.Examples:
the_actor.attempts_to( Pause.for_(10).seconds_because("they're being dramatic.") ) the_actor.attempts_to( Pause.for_(500).milliseconds_because("of a moment's hesitation.") )
- second_because(reason: str) Self
Alias for
seconds_because()
.
See
Aliases: Assert
,
Confirm
,
Observe
,
Verify
,
Sees
,
Asserts
,
Confirms
,
Observes
,
Verifies
- class See(question: T_Q, resolution: T_R)
See if a value or the answer to a Question matches the Resolution.
This is a very important Action in ScreenPy; it is the way to perform test assertions. For more information, see the documentation for Questions and Resolutions.
Examples:
the_actor.should( See(TheText.of_the(WELCOME_MESSAGE), ReadsExactly("Welcome!")), ) the_actor.should( See.the(list_of_items, ContainsTheItem("juice extractor")), )
- classmethod the(question: T_Q, resolution: T_R) Self
Supply the Question (or value) and Resolution to test.
SeeAllOf
Aliases: AssertAllOf
,
ConfirmAllOf
,
ObserveAllOf
,
VerifyAllOf
,
SeesAllOf
,
AssertsAllOf
,
ConfirmsAllOf
,
ObservesAllOf
,
VerifiesAllOf
- class SeeAllOf(*tests: T_T)
See if all the provided values or Questions match their Resolutions.
Uses
See
to assert all values or the answers to the Questions match their paired Resolutions:.Examples:
the_actor.should( SeeAllOf( (TheText.of_the(WELCOME_MESSAGE), ReadsExactly("Welcome!")), (the_character_speech_bubble, ContainsTheText("Howdy!")), ) ) the_actor.should( SeeAllOf.the( (Number.of(BALLOONS), IsEqualTo(3)), ) )
- classmethod the(*tests: T_T) Self
Supply any number of Question/value + Resolution tuples to test.
SeeAnyOf
Aliases: AssertAnyOf
,
ConfirmAnyOf
,
ObserveAnyOf
,
VerifyAnyOf
,
SeesAnyOf
,
AssertsAnyOf
,
ConfirmsAnyOf
,
ObservesAnyOf
,
VerifiesAnyOf
- class SeeAnyOf(*tests: T_T)
See if at least one value or Question matches its Resolution.
Uses
See
to assert at least one of the values or the answers to the Questions match their paired Resolutions:.Examples:
the_actor.should( SeeAnyOf( (TheText.of_the(WELCOME_MESSAGE), ReadsExactly("Welcome!")), (the_character_speech_bubble, ContainsTheText("Howdy!")), ) ) the_actor.should( SeeAnyOf.the( (Number.of(BALLOONS), IsEqualTo(4)), ) )
- classmethod the(*tests: T_T) Self
Supply any number of Question/value + Resolution tuples to test.
Silently
Aliases: Quietly
- Silently(duck: T) T
Silence the duck.
Any Performable, Answerable, or Resolvable wrapped in Silently will not be narrated by the Narrator, unless an exception is raised.
- Args:
duck: Performable, Answerable, or Resolvable
- Returns:
Performable, Answerable, or Resolvable
Examples:
the_actor.will(Silently(Click.on(THE_BUTTON))) the_actor.shall( See( Silently(Text.of_the(WELCOME_BANNER)), ContainsTheText("Welcome!") ) ) the_actor.shall( See( Text.of_the(WELCOME_BANNER), Silently(ContainsTheText("Welcome!")) ) )
Either
Aliases: Attempt
,
AttemptTo
,
GoFor
,
Try
TryTo
,
Attempts
,
AttemptsTo
,
GoesFor
,
Tries
,
TriesTo
- class Either(*first: Performable)
Perform one of two branching performances.
Simulates a try/except block while still following Screenplay Pattern.
By default,
Either
catches AssertionErrors, so you can useSee
to decide which path to follow. Use theignoring()
method to ignore other exceptions.Examples:
the_actor.will(Either(DoAction()).or_(DoDifferentAction()) the_actor.will( Either(DoAction()).otherwise(DoDifferentAction()).ignoring( AssertionError, NotImplementedError ) ) # using a custom Task which raises AssertionError the_actor.will( Either(CheckIfOnDomain(URL())).or_(Open.their_browser_on(URL()) )
- or_(*except_performables: Performable) Self
Provide the alternative routine to perform.
- except_(*except_performables: Performable) Self
Provide the alternative routine to perform.
- else_(*except_performables: Performable) Self
Provide the alternative routine to perform.
- otherwise(*except_performables: Performable) Self
Provide the alternative routine to perform.
- alternatively(*except_performables: Performable) Self
Provide the alternative routine to perform.
- failing_that(*except_performables: Performable) Self
Provide the alternative routine to perform.
- ignoring(*ignored_exceptions: type[BaseException]) Self
Set the expception classes to ignore.