Core API¶
screenwright.core
¶
Screenplay Engine -- Core Domain.
This package implements the Screenplay pattern: Actors perform Tasks by exercising Abilities through Interactions, and verify outcomes by asking Questions.
Ability
¶
A capability that an Actor possesses.
Subclass this to create specific Abilities
class BrowseTheWeb(Ability): def init(self, driver: WebDriver) -> None: self.driver = driver
@staticmethod
def using(driver: WebDriver) -> BrowseTheWeb:
return BrowseTheWeb(driver)
The Actor retrieves Abilities by type
driver_ability = actor.ability_to(BrowseTheWeb)
Source code in src/screenwright/core/ability.py
__str__()
¶
Human-readable name for narration.
Override to customize. Default: class name with spaces inserted before uppercase letters.
Source code in src/screenwright/core/ability.py
AbilityNotFoundError
¶
Bases: ScreenwrightError
Raised when an Actor does not have a required Ability.
This typically means the Actor was not granted the Ability before attempting an Interaction that requires it.
Source code in src/screenwright/core/exceptions.py
Actor
¶
A named persona who performs actions against the system under test.
An Actor has Abilities (what they can do), remembers Facts (what they know), performs Tasks (high-level goals) and Interactions (atomic actions), and asks Questions (queries about state).
Example
ali = Actor.named("Ali", description="a scrum master") ali.who_can(BrowseTheWeb.using(driver)) ali.attempts_to(Navigate.to("https://example.com")) ali.should_see_that(TextOf(HEADING), is_equal_to("Welcome"))
Source code in src/screenwright/core/actor.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
description
property
¶
The Actor's role description.
name
property
¶
The Actor's name.
ability_to(ability_type)
¶
Retrieve a previously granted Ability by type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ability_type
|
type[T]
|
The class of the Ability to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
T
|
The Ability instance. |
Raises:
| Type | Description |
|---|---|
AbilityNotFoundError
|
If the Actor does not have this Ability. |
Source code in src/screenwright/core/actor.py
attempts_to(*performables)
¶
Perform one or more Tasks or Interactions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
performables
|
Performable
|
The Performables to execute, in order. |
()
|
Source code in src/screenwright/core/actor.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
has_ability_to(ability_type)
¶
Check whether this Actor has a specific Ability.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ability_type
|
type[Ability]
|
The class of the Ability to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the Actor has the Ability. |
Source code in src/screenwright/core/actor.py
named(name, *, description=None, publisher=None)
staticmethod
¶
Create a new Actor with the given name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The Actor's name (e.g., "Ali"). |
required |
description
|
str | None
|
Optional role description (e.g., "a scrum master"). |
None
|
publisher
|
EventPublisher | None
|
Optional EventPublisher for emitting domain events. |
None
|
Returns:
| Type | Description |
|---|---|
Actor
|
A new Actor instance. |
Source code in src/screenwright/core/actor.py
recalls(fact_key)
¶
Retrieve a previously remembered Fact.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fact_key
|
str
|
The key of the Fact to recall. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The stored value. |
Raises:
| Type | Description |
|---|---|
FactNotFoundError
|
If the Actor does not remember this Fact. |
Source code in src/screenwright/core/actor.py
remembers(**facts)
¶
Store Facts that this Actor knows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
facts
|
Any
|
Key-value pairs to remember. |
{}
|
Returns:
| Type | Description |
|---|---|
Actor
|
Self, for fluent chaining. |
Source code in src/screenwright/core/actor.py
should_see_that(question, matcher)
¶
Ask a Question and verify the answer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
question
|
Answerable[T]
|
The Answerable to query. |
required |
matcher
|
Callable[[T], bool] | T
|
Either a callable predicate or an expected value for equality comparison. |
required |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If the matcher/predicate fails. |
Source code in src/screenwright/core/actor.py
who_can(*abilities)
¶
Grant Abilities to this Actor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
abilities
|
Ability
|
One or more Abilities to grant. |
()
|
Returns:
| Type | Description |
|---|---|
Actor
|
Self, for fluent chaining. |
Source code in src/screenwright/core/actor.py
Answerable
¶
Bases: Protocol[T]
Anything an Actor can ask that returns a value.
Questions implement this protocol. The Actor.should_see_that() method accepts Answerables.
Source code in src/screenwright/core/answerable.py
EventPublisher
¶
Bases: Protocol
Output port for publishing domain events.
The core domain calls publish() to emit events. The adapter/collection layer provides the concrete implementation.
Source code in src/screenwright/core/event_publisher.py
publish(event)
¶
FactNotFoundError
¶
Bases: ScreenwrightError
Raised when an Actor does not remember a requested Fact.
Source code in src/screenwright/core/exceptions.py
Interaction
¶
Base class for class-based Interactions.
Interactions are the leaf nodes of the Screenplay action tree. They directly manipulate the system under test through an Ability.
Subclass and implement perform_as(): class Click(Interaction): def init(self, target: Target) -> None: self.target = target
@staticmethod
def on(target: Target) -> Click:
return Click(target)
def perform_as(self, actor: Actor) -> None:
driver = actor.ability_to(BrowseTheWeb).driver
driver.find_element(*self.target.locator).click()
Source code in src/screenwright/core/interaction.py
__str__()
¶
Human-readable name for narration.
Source code in src/screenwright/core/interaction.py
NoActorInSpotlightError
¶
Bases: ScreenwrightError
Raised when the Spotlight is empty but an Actor is needed.
Source code in src/screenwright/core/exceptions.py
NullEventPublisher
¶
An EventPublisher that discards all events.
Used as the default when no publisher is configured, and in unit tests where event collection is not needed.
Source code in src/screenwright/core/event_publisher.py
Performable
¶
Bases: Protocol
Anything an Actor can perform.
Both Tasks and Interactions implement this protocol. The Actor.attempts_to() method accepts Performables.
Source code in src/screenwright/core/performable.py
Question
¶
Bases: Generic[T]
Base class for class-based Questions.
Subclass and implement answered_by(): class TextOf(Question[str]): def init(self, target: Target) -> None: self.target = target
def answered_by(self, actor: Actor) -> str:
driver = actor.ability_to(BrowseTheWeb).driver
return driver.find_element(*self.target.locator).text
Source code in src/screenwright/core/question.py
__str__()
¶
Human-readable name for narration.
Source code in src/screenwright/core/question.py
Scene
dataclass
¶
A single test scenario viewed through the theatre metaphor.
A Scene begins when a scenario starts and ends when it completes. During a Scene, Actors enter the Stage, perform their parts, and exit.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The scenario name. |
feature_name |
str
|
The feature this scene belongs to. |
tags |
list[str]
|
BDD tags associated with this scenario. |
Source code in src/screenwright/core/scene.py
ScreenwrightError
¶
Spotlight
¶
Tracks the currently active Actor.
The Spotlight is managed by the Stage. When a Scene involves multiple Actors, the Spotlight shifts to indicate who is currently acting.
Source code in src/screenwright/core/spotlight.py
current
property
¶
The Actor currently in the Spotlight.
Raises:
| Type | Description |
|---|---|
NoActorInSpotlightError
|
If no Actor is in the Spotlight. |
has_actor
property
¶
Whether any Actor is currently in the Spotlight.
clear()
¶
Stage
¶
The environment in which Actors perform during a test session.
The Stage manages the lifecycle of Actors, determines which Actor is in the Spotlight, and coordinates Scene (scenario) boundaries.
Attributes:
| Name | Type | Description |
|---|---|---|
publisher |
The EventPublisher used to emit domain events. |
Source code in src/screenwright/core/stage.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
actors
property
¶
All Actors currently on Stage.
current_scene
property
¶
The currently active Scene, or None.
actor_named(name, *, description=None)
¶
Get or create an Actor on this Stage.
If an Actor with this name already exists, returns them. Otherwise, creates a new Actor, places them on Stage, and shifts the Spotlight to them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The Actor's name. |
required |
description
|
str | None
|
Optional role description. |
None
|
Returns:
| Type | Description |
|---|---|
Actor
|
The Actor (new or existing). |
Source code in src/screenwright/core/stage.py
clear()
¶
Remove all Actors from the Stage and clear the Spotlight.
Called at the end of each Scene (scenario).
Source code in src/screenwright/core/stage.py
in_the_spotlight()
¶
The Actor currently in the Spotlight.
Raises:
| Type | Description |
|---|---|
NoActorInSpotlightError
|
If no Actor is in the Spotlight. |
new_scene(name, feature_name='', tags=None)
¶
Start a new Scene (test scenario).
Clears any existing Actors from the previous Scene.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The scenario name. |
required |
feature_name
|
str
|
The feature this scenario belongs to. |
''
|
tags
|
list[str] | None
|
BDD tags for the scenario. |
None
|
Returns:
| Type | Description |
|---|---|
Scene
|
The new Scene. |
Source code in src/screenwright/core/stage.py
shine_spotlight_on(actor)
¶
Shift the Spotlight to a specific Actor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
actor
|
Actor
|
The Actor to illuminate. |
required |
Source code in src/screenwright/core/stage.py
Task
¶
Base class for class-based Tasks.
Subclass and implement perform_as(): class Login(Task): def init(self, username: str, password: str) -> None: self.username = username self.password = password
def perform_as(self, actor: Actor) -> None:
actor.attempts_to(
Navigate.to("/login"),
Enter.the_value(self.username).into(USERNAME_FIELD),
Enter.the_value(self.password).into(PASSWORD_FIELD),
Click.on(LOGIN_BUTTON),
)
Source code in src/screenwright/core/task.py
ability
¶
Ability base class -- capabilities that enable Actors to interact with systems.
Ability
¶
A capability that an Actor possesses.
Subclass this to create specific Abilities
class BrowseTheWeb(Ability): def init(self, driver: WebDriver) -> None: self.driver = driver
@staticmethod
def using(driver: WebDriver) -> BrowseTheWeb:
return BrowseTheWeb(driver)
The Actor retrieves Abilities by type
driver_ability = actor.ability_to(BrowseTheWeb)
Source code in src/screenwright/core/ability.py
__str__()
¶
Human-readable name for narration.
Override to customize. Default: class name with spaces inserted before uppercase letters.
Source code in src/screenwright/core/ability.py
actor
¶
Actor -- the central aggregate root of the Screenplay pattern.
Actor
¶
A named persona who performs actions against the system under test.
An Actor has Abilities (what they can do), remembers Facts (what they know), performs Tasks (high-level goals) and Interactions (atomic actions), and asks Questions (queries about state).
Example
ali = Actor.named("Ali", description="a scrum master") ali.who_can(BrowseTheWeb.using(driver)) ali.attempts_to(Navigate.to("https://example.com")) ali.should_see_that(TextOf(HEADING), is_equal_to("Welcome"))
Source code in src/screenwright/core/actor.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
description
property
¶
The Actor's role description.
name
property
¶
The Actor's name.
ability_to(ability_type)
¶
Retrieve a previously granted Ability by type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ability_type
|
type[T]
|
The class of the Ability to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
T
|
The Ability instance. |
Raises:
| Type | Description |
|---|---|
AbilityNotFoundError
|
If the Actor does not have this Ability. |
Source code in src/screenwright/core/actor.py
attempts_to(*performables)
¶
Perform one or more Tasks or Interactions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
performables
|
Performable
|
The Performables to execute, in order. |
()
|
Source code in src/screenwright/core/actor.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
has_ability_to(ability_type)
¶
Check whether this Actor has a specific Ability.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ability_type
|
type[Ability]
|
The class of the Ability to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the Actor has the Ability. |
Source code in src/screenwright/core/actor.py
named(name, *, description=None, publisher=None)
staticmethod
¶
Create a new Actor with the given name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The Actor's name (e.g., "Ali"). |
required |
description
|
str | None
|
Optional role description (e.g., "a scrum master"). |
None
|
publisher
|
EventPublisher | None
|
Optional EventPublisher for emitting domain events. |
None
|
Returns:
| Type | Description |
|---|---|
Actor
|
A new Actor instance. |
Source code in src/screenwright/core/actor.py
recalls(fact_key)
¶
Retrieve a previously remembered Fact.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fact_key
|
str
|
The key of the Fact to recall. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The stored value. |
Raises:
| Type | Description |
|---|---|
FactNotFoundError
|
If the Actor does not remember this Fact. |
Source code in src/screenwright/core/actor.py
remembers(**facts)
¶
Store Facts that this Actor knows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
facts
|
Any
|
Key-value pairs to remember. |
{}
|
Returns:
| Type | Description |
|---|---|
Actor
|
Self, for fluent chaining. |
Source code in src/screenwright/core/actor.py
should_see_that(question, matcher)
¶
Ask a Question and verify the answer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
question
|
Answerable[T]
|
The Answerable to query. |
required |
matcher
|
Callable[[T], bool] | T
|
Either a callable predicate or an expected value for equality comparison. |
required |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If the matcher/predicate fails. |
Source code in src/screenwright/core/actor.py
who_can(*abilities)
¶
Grant Abilities to this Actor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
abilities
|
Ability
|
One or more Abilities to grant. |
()
|
Returns:
| Type | Description |
|---|---|
Actor
|
Self, for fluent chaining. |
Source code in src/screenwright/core/actor.py
answerable
¶
Answerable protocol -- the common interface for Questions.
Answerable
¶
Bases: Protocol[T]
Anything an Actor can ask that returns a value.
Questions implement this protocol. The Actor.should_see_that() method accepts Answerables.
Source code in src/screenwright/core/answerable.py
event_publisher
¶
EventPublisher protocol -- output port for domain event emission.
EventPublisher
¶
Bases: Protocol
Output port for publishing domain events.
The core domain calls publish() to emit events. The adapter/collection layer provides the concrete implementation.
Source code in src/screenwright/core/event_publisher.py
publish(event)
¶
NullEventPublisher
¶
An EventPublisher that discards all events.
Used as the default when no publisher is configured, and in unit tests where event collection is not needed.
Source code in src/screenwright/core/event_publisher.py
exceptions
¶
Domain exceptions for the Screenplay Engine.
AbilityNotFoundError
¶
Bases: ScreenwrightError
Raised when an Actor does not have a required Ability.
This typically means the Actor was not granted the Ability before attempting an Interaction that requires it.
Source code in src/screenwright/core/exceptions.py
FactNotFoundError
¶
Bases: ScreenwrightError
Raised when an Actor does not remember a requested Fact.
Source code in src/screenwright/core/exceptions.py
NoActorInSpotlightError
¶
Bases: ScreenwrightError
Raised when the Spotlight is empty but an Actor is needed.
Source code in src/screenwright/core/exceptions.py
fact
¶
Fact type alias and helpers for Actor memory.
summarize_fact_value(value, max_length=50)
¶
Create a safe summary of a fact value for event emission.
Truncates long strings and avoids exposing sensitive data in full.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
The fact value to summarize. |
required |
max_length
|
int
|
Maximum length of the summary string. |
50
|
Returns:
| Type | Description |
|---|---|
str
|
A truncated string representation. |
Source code in src/screenwright/core/fact.py
interaction
¶
Interaction -- low-level, atomic actions an Actor performs.
Interaction
¶
Base class for class-based Interactions.
Interactions are the leaf nodes of the Screenplay action tree. They directly manipulate the system under test through an Ability.
Subclass and implement perform_as(): class Click(Interaction): def init(self, target: Target) -> None: self.target = target
@staticmethod
def on(target: Target) -> Click:
return Click(target)
def perform_as(self, actor: Actor) -> None:
driver = actor.ability_to(BrowseTheWeb).driver
driver.find_element(*self.target.locator).click()
Source code in src/screenwright/core/interaction.py
__str__()
¶
Human-readable name for narration.
Source code in src/screenwright/core/interaction.py
performable
¶
Performable protocol -- the common interface for Tasks and Interactions.
Performable
¶
Bases: Protocol
Anything an Actor can perform.
Both Tasks and Interactions implement this protocol. The Actor.attempts_to() method accepts Performables.
Source code in src/screenwright/core/performable.py
question
¶
Question -- queries about the observable state of the system.
Question
¶
Bases: Generic[T]
Base class for class-based Questions.
Subclass and implement answered_by(): class TextOf(Question[str]): def init(self, target: Target) -> None: self.target = target
def answered_by(self, actor: Actor) -> str:
driver = actor.ability_to(BrowseTheWeb).driver
return driver.find_element(*self.target.locator).text
Source code in src/screenwright/core/question.py
__str__()
¶
Human-readable name for narration.
Source code in src/screenwright/core/question.py
question(func)
¶
Decorator to create a Question from a function.
The decorated function receives the Actor as its first argument and returns a value:
@question
def current_url(actor: Actor) -> str:
return actor.ability_to(BrowseTheWeb).driver.current_url
Usage
actor.should_see_that(current_url(), is_equal_to("https://example.com"))
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[..., Any]
|
The function to wrap as a Question. |
required |
Returns:
| Type | Description |
|---|---|
Callable[..., _FunctionalQuestion[Any]]
|
A factory function that creates an Answerable Question. |
Source code in src/screenwright/core/question.py
scene
¶
Scene -- a single test scenario execution.
Scene
dataclass
¶
A single test scenario viewed through the theatre metaphor.
A Scene begins when a scenario starts and ends when it completes. During a Scene, Actors enter the Stage, perform their parts, and exit.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The scenario name. |
feature_name |
str
|
The feature this scene belongs to. |
tags |
list[str]
|
BDD tags associated with this scenario. |
Source code in src/screenwright/core/scene.py
spotlight
¶
Spotlight -- tracks the currently active Actor on the Stage.
Spotlight
¶
Tracks the currently active Actor.
The Spotlight is managed by the Stage. When a Scene involves multiple Actors, the Spotlight shifts to indicate who is currently acting.
Source code in src/screenwright/core/spotlight.py
current
property
¶
The Actor currently in the Spotlight.
Raises:
| Type | Description |
|---|---|
NoActorInSpotlightError
|
If no Actor is in the Spotlight. |
has_actor
property
¶
Whether any Actor is currently in the Spotlight.
clear()
¶
stage
¶
Stage -- manages Actor lifecycle and the Spotlight for a test session.
Stage
¶
The environment in which Actors perform during a test session.
The Stage manages the lifecycle of Actors, determines which Actor is in the Spotlight, and coordinates Scene (scenario) boundaries.
Attributes:
| Name | Type | Description |
|---|---|---|
publisher |
The EventPublisher used to emit domain events. |
Source code in src/screenwright/core/stage.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
actors
property
¶
All Actors currently on Stage.
current_scene
property
¶
The currently active Scene, or None.
actor_named(name, *, description=None)
¶
Get or create an Actor on this Stage.
If an Actor with this name already exists, returns them. Otherwise, creates a new Actor, places them on Stage, and shifts the Spotlight to them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The Actor's name. |
required |
description
|
str | None
|
Optional role description. |
None
|
Returns:
| Type | Description |
|---|---|
Actor
|
The Actor (new or existing). |
Source code in src/screenwright/core/stage.py
clear()
¶
Remove all Actors from the Stage and clear the Spotlight.
Called at the end of each Scene (scenario).
Source code in src/screenwright/core/stage.py
in_the_spotlight()
¶
The Actor currently in the Spotlight.
Raises:
| Type | Description |
|---|---|
NoActorInSpotlightError
|
If no Actor is in the Spotlight. |
new_scene(name, feature_name='', tags=None)
¶
Start a new Scene (test scenario).
Clears any existing Actors from the previous Scene.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The scenario name. |
required |
feature_name
|
str
|
The feature this scenario belongs to. |
''
|
tags
|
list[str] | None
|
BDD tags for the scenario. |
None
|
Returns:
| Type | Description |
|---|---|
Scene
|
The new Scene. |
Source code in src/screenwright/core/stage.py
shine_spotlight_on(actor)
¶
Shift the Spotlight to a specific Actor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
actor
|
Actor
|
The Actor to illuminate. |
required |
Source code in src/screenwright/core/stage.py
task
¶
Task -- high-level, business-meaningful goals an Actor performs.
Task
¶
Base class for class-based Tasks.
Subclass and implement perform_as(): class Login(Task): def init(self, username: str, password: str) -> None: self.username = username self.password = password
def perform_as(self, actor: Actor) -> None:
actor.attempts_to(
Navigate.to("/login"),
Enter.the_value(self.username).into(USERNAME_FIELD),
Enter.the_value(self.password).into(PASSWORD_FIELD),
Click.on(LOGIN_BUTTON),
)
Source code in src/screenwright/core/task.py
task(func)
¶
Decorator to create a Task from a function.
The decorated function receives the Actor as its first argument:
@task
def login(actor: Actor, username: str, password: str) -> None:
actor.attempts_to(
Navigate.to("/login"),
Enter.the_value(username).into(USERNAME_FIELD),
)
Usage
actor.attempts_to(login(username="admin", password="secret"))
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[..., Any]
|
The function to wrap as a Task. |
required |
Returns:
| Type | Description |
|---|---|
Callable[..., _FunctionalTask]
|
A factory function that creates a Performable Task. |