Skip to main content

Screenplay pattern base for Python automated UI test suites.

Project description

ScreenPy

TITLE CARD:
                                  "ScreenPy"
TITLE DISAPPEARS.
                                                                      FADE IN:
INT. DOCUMENTATION - NIGHT

Illuminated by the computer's glow, AUDIENCE sits reading the documentation
for a Python library they haven't seen before. AUDIENCE is visibly startled
as a dulcet voice begins to speak.

                              NARRATOR (V.O.)
            ScreenPy is a library that provides the base for an
            automated test suite using Screenplay Pattern.

                              AUDIENCE
            Wha- who are you? Where are you? And... what is
            Screenplay Pattern?!

                              NARRATOR (V.O.)
            It's a composition-based architecture pattern,
            encouraging automated test writers to write more
            maintainable test suites. It allows test writers to
            use Gherkin-style language in Python to create
            descriptive UI tests.

                              AUDIENCE
                              (reluctantly)
            Ignoring how you avoided answering my first questions,
            how do I get started?

                              NARRATOR (V.O.)
            I thought you'd never ask...

                                                                      FADE OUT

QuickStart

from selenium.webdriver import Firefox

from screenpy.actions.click import Click
from screenpy.actions.open import Open
from screenpy.actors.actor import Actor
from screenpy.abilities.browse_the_web import BrowseTheWeb
from screenpy.given_when_then import given, when, then
from screenpy.questions.text import Text
from screenpy.resolutions import ReadsExactly
from screenpy.target import Target

# This would normally go in your tasks/start.py
class Start(object):
    """Test case start points"""
    def perform_as(self, actor):
        actor.attempts_to(Open.browser_on(self.location))
    @staticmethod
    def on_the_screenpy_repo():
        return Start("https://github.com/perrygoy/screenpy")
    def __init__(self, location):
        self.location = location

# These two would normally go in your user_interface/some_page.py
AUTHOR_LINK = Target.the("Repository author link").located_by("a[rel=author]")
USER_NAME = Target.the("GitHub user's name").located_by("span.vcard-fullname")

# This would normally go in your questions/user_name.py
class UserName(object):
    """Questions about the user name"""
    def answered_by(self, the_actor):
        return Text.of(USER_NAME).viewed_by(the_actor)
    @staticmethod
    def text():
        return UserName()

perry = Actor.named("Perry").who_can(BrowseTheWeb.using(Firefox()))

given(perry).was_able_to(Start.on_the_screenpy_repo())
when(perry).attempts_to(Click.on(AUTHOR_LINK).then_wait_for(USER_NAME))
then(perry).should_see_the((UserName.text(), ReadsExactly("Perry Goy")),)
perry.exit_stage_right()

You may think to yourself, man, that's a lot of setup for a simple quickstart. And you're definitely right! There are a lot of moving parts to a Screenplay Pattern test suite. If you want to know more, please check out the Read The Docs documentation!

Allure Integration

ScreenPy utilizes Allure to document the action. If you would like to see an allure report of your Screenplay Suite, run the test using PyTest like so:

python -m pytest features --allure_dir allure_report
allure serve allure_report

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

screenpy-0.1.3.tar.gz (14.3 kB view hashes)

Uploaded Source

Built Distribution

screenpy-0.1.3-py3-none-any.whl (20.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page