Skip to main content

A nice way of implementing the Page Object pattern.

Project description

PyPI PyPI - Python Version GitHub Updates https://travis-ci.org/jsfehler/stere.svg?branch=master https://coveralls.io/repos/github/jsfehler/stere/badge.svg?branch=master https://api.codacy.com/project/badge/Grade/e791ab09e14c4483943a26a2fd180577 https://saucelabs.com/buildstatus/jsfehler

Stere is a library for writing Page Objects, designed to work on top of an existing automation library.

Design Philosophy

Many implementations of the Page Object model focus on removing the duplication of element locators inside tests. Stere goes one step further, offering a complete wrapper over the code that drives automation.

The goals of this project are to:

1 - Eliminate implementation code in test functions. Tests should read like a description of behaviour, not Selenium commands.

2 - Reduce the need for hand-written helper methods in Page Objects. Common actions should have universal solutions.

3 - Provide a simple pattern for writing maintainable Page Objects.

No automation abilities are built directly into the project; it completely relies on being hooked into other libraries. However, implementations using Splinter and Appium are available out of the box.

Documentation

https://stere.readthedocs.io/en/latest/

Basic Usage

Fundamentally, a Page Object is just a Python class.

A minimal Stere Page Object should:

1 - Subclass the Page class

2 - Declare Fields and Areas in the __init__ method

As an example, here’s the home page for Wikipedia:

from stere import Page
from stere.areas import Area, RepeatingArea
from stere.fields import Button, Input, Link, Root, Text


class WikipediaHome(Page):
    def __init__(self):
        self.search_form = Area(
            query=Input('id', 'searchInput'),
            submit=Button('xpath', '//*[@id="search-form"]/fieldset/button')
        )

        self.other_projects = RepeatingArea(
            root=Root('xpath', '//*[@class="other-project"]'),
            title=Link('xpath', '//*[@class="other-project-title"]'),
            tagline=Text('xpath', '//*[@class="other-project-tagline"]')
        )

The search form is represented as an Area with two Fields inside it.

A Field represents a single item, while an Area represents a unique collection of Fields.

The query and submit Fields didn’t have to be placed inside an Area. However, doing so allows you to use Area’s perform() method.

The links to other products are represented as a RepeatingArea . A RepeatingArea represents a non-unique collection of Fields on the page. Using the root argument as the non-unique selector, RepeatingArea will find all instances of said root, then build the appropriate number of Areas with all the other Fields inside.

It’s just as valid to declare each of the other products as a separate Area one at a time, like so:

self.commons = Area(
    root=Root('xpath', '//*[@class="other-project"][1]'),
    title=Link('xpath', '//*[@class="other-project-title"]'),
    tagline=Text('xpath', '//*[@class="other-project-tagline"]')
)

self.wikivoyage = Area(
    root=Root('xpath', '//*[@class="other-project"][2]'),
    title=Link('xpath', '//*[@class="other-project-title"]'),
    tagline=Text('xpath', '//*[@class="other-project-tagline"]')
)

Which style you pick depends entirely on how you want to model the page. RepeatingArea does the most good with collections where the number of areas and/or the contents of the areas can’t be predicted, such as inventory lists.

Using a Page Object in a test can be done like so:

def test_search_wikipedia():
    home = WikipediaHome()
    home.search_form.perform('kittens')

License

Distributed under the terms of the MIT license, “Stere” is free and open source software

Issues

If you encounter any problems, please file an issue along with a detailed description.

Thanks

Cross-browser Testing Platform and Open Source <3 Provided by Sauce Labs

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

stere-0.15.0.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

stere-0.15.0-py3-none-any.whl (28.5 kB view details)

Uploaded Python 3

File details

Details for the file stere-0.15.0.tar.gz.

File metadata

  • Download URL: stere-0.15.0.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.1

File hashes

Hashes for stere-0.15.0.tar.gz
Algorithm Hash digest
SHA256 e45deea5758c29975f9bb81822c274984587bbb2632846fb7b8cfd234b8bd358
MD5 882a05b3760e941d8361849a102c366a
BLAKE2b-256 636e8311228a2d77529d65d6ae67534d17732d4c6e8b2e655319e3c4731ec60f

See more details on using hashes here.

Provenance

File details

Details for the file stere-0.15.0-py3-none-any.whl.

File metadata

  • Download URL: stere-0.15.0-py3-none-any.whl
  • Upload date:
  • Size: 28.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.1

File hashes

Hashes for stere-0.15.0-py3-none-any.whl
Algorithm Hash digest
SHA256 009e5a1c685e8884463e39bb16b7a3ed1db2b36936cadbec1be302b352e36ac9
MD5 9e508f48590d3d25db1d5a1c66b30a68
BLAKE2b-256 01d8d104b81962a5103aac183d3b7ba4011f527542f92c8248a01aa010c9a583

See more details on using hashes here.

Provenance

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