Questions

Questions are asked by an actor about the current state of the page or application. They are the first half (the “actual value”) of ScreenPy’s test assertions (the other half, Resolutions, is next).

Asking Questions

Typically, you will not be asking a question without an expected answer. This is how you do test assertions in ScreenPy:

from screenpy.questions import Text
from screenpy.resolutions import ReadsExactly

from ..user_interface.homepage import WELCOME_MESSAGE

Perry.should_see_the((Text.of_the(WELCOME_MESSAGE), ReadsExactly("Welcome!")), )

We’ll talk about Resolutions next, but that call to should_see_the() is taking in our question. Behind the curtain, our actor is investigating the current state of the application (using their ability to BrowseTheWeb) to find out what the text actually says at the locator described by WELCOME_MESSAGE. They take that answer and compare it to the expected answer passed in by the resolution. If they match, a comedy! Our test passes. If they do not match, a tragedy! Our test fails.

Writing New Questions

It is very likely that you may want to write additional questions, and you are encouraged to do so! The only prescribed method for a question class is an asked_by method that takes in an actor. This method will do the work of getting the answer to the question. For example, you may want to take a look at the asked_by() method of the Text class.

A base class for Questions is provided to ensure the required methods are defined: screenpy.questions.base_question.BaseQuestion

Provided Questions

List

class screenpy.questions.list.List(target: screenpy.target.Target)

Asks for a list of elements, viewed by an Actor. This question is meant to be instantiated using its static of() or of_all() methods. Typical invocations might look like:

List.of(SEARCH_RESULTS)

List.of_all(IMAGES)

It can then be passed along to the Actor to ask the question.

Number

class screenpy.questions.number.Number(target: screenpy.target.Target)

Asks how many of a certain element are on the page, viewed by an Actor. This question is meant to be instantiated via its static of() method. A typical invocation might look like:

Number.of(SEARCH_RESULTS)

It can then be passed along to the Actor to ask the question.

Text

class screenpy.questions.text.Text(target: screenpy.target.Target, multi: bool = False)

Asks what text appears in an element or elements, viewed by an Actor. This question is meant to be instantiated using its static of() or of_all() methods. Typical invocations might look like:

Text.of(THE_WELCOME_HEADER)

Text.of_all(SEARCH_RESULTS)

It can then be passed along to the Actor to ask the question.

Selected

class screenpy.questions.selected.Selected(target: screenpy.target.Target, multi: bool = False)

Answers questions about what options are selected in dropdowns, multi-select fields, etc, viewed by an Actor. This question is meant to be instantiated using its static option_from or option_from methods. Typical invocations might look like:

Selected.option_from(THE_STATE_DROPDOWN)

Selected.options_from(INDUSTRIES)

It can then be passed along to the Actor to ask the question.