Areas

Areas represent groupings of Fields on a Page.

The following Area objects are available:

  • Area: A non-hierarchical, unique group of Fields.
  • RepeatingArea: A hierarchical, non-unique group of Areas. They require a Root Field.
class stere.areas.Area

A collection of unique objects on a page.

Area takes any number of the following object types:
  • Field
  • Area
  • Repeating

Example:

>>> from stere.areas import Area
>>> from stere.fields import Button
>>>
>>> class Album(Page):
>>>     def __init__(self):
>>>         self.genres = Area(
>>>             jazz=Button('css', '.genreJazz'),
>>>             metal=Button('css', '.genreMetal'),
>>>             rock=Button('xpath', '//div[@id="genreRock"]'),
>>>         )
>>>
>>> def test_album_genres():
>>>     album = Album()
>>>     album.genres.rock.click()
perform()

For every Field in an Area, “do the right thing” by calling the Field’s perform() method.

Fields that require an argument can either be given sequentially or with keywords.

Parameters:
  • args – Arguments that will sequentially be sent to Fields in this Area.
  • kwargs – Arguments that will be sent specifically to the Field with a matching name.

Example

Given the following Page Object:

>>> from stere.areas import Area
>>> from stere.fields import Button, Input
>>>
>>> class Login():
>>>     def __init__(self):
>>>         self.form = Area(
>>>             username=Input('id', 'app-user'),
>>>             password=Input('id', 'app-pwd'),
>>>             submit=Button('id', 'app-submit')
>>>         )

Any of the following styles are valid:

>>> def test_login():
>>>     login = Login()
>>>     login.my_area.perform('Sven', 'Hoek')
>>> def test_login():
>>>     login = Login()
>>>     login.my_area.perform(username='Sven', password='Hoek')
>>> def test_login():
>>>     login = Login()
>>>     login.my_area.perform('Sven', password='Hoek')
workflow()

Set the current workflow for an Area.

Designed for chaining before a call to perform().

Parameters:value (str) – The name of the workflow to set.
Returns:The calling Area
Return type:Area

Example:

>>> my_area.workflow('Foobar').perform()
class stere.areas.RepeatingArea

Represents multiple identical Areas on a page.

A root argument is required, which is expected to be a non-unique Field on the page.

A collection of Areas are built from every instance of the root that is found. Every other Field provided in the arguments is populated inside each Area.

In the following example, there’s a table with 15 rows. Each row has two cells. The sixth row in the table should have an item with the name “Banana” and a price of “$7.00”

>>> from stere.areas import RepeatingArea
>>> from stere.fields import Root, Link, Text
>>>
>>> class Inventory(Page):
>>>     def __init__(self):
>>>         self.inventory_items = RepeatingArea(
>>>             root=Root('xpath', '//table/tr'),
>>>             name=Link('xpath', './td[1]'),
>>>             price=Text('xpath', './td[2]'),
>>>         )
>>> inventory = Inventory()
>>> assert 15 == len(inventory.areas)
>>> assert "Banana" == inventory.areas[5].name
>>> assert "$7.00" == inventory.areas[5].price
areas

Find all instances of the root, then return a list of Areas: one for each root.

Returns:list-like collection of every Area that was found.
Return type:Areas

Example

>>> def test_stuff():
>>>     listings = MyPage().my_repeating_area.areas
>>>     listings[0].my_input.fill('Hello world')
class stere.areas.Areas

Searchable collection of Areas.

Behaves like a list.

containing()

Search for Areas where the Field’s value matches the expected value and then returns an Areas object with all matches.

Parameters:
  • field_name (str) – The name of the Field object.
  • field_value (str) – The value of the Field object.
Returns:

A new Areas object with matching results

Return type:

Areas

Example

>>> class Inventory(Page):
>>>     def __init__(self):
>>>         self.items = RepeatingArea(
>>>             root=Root('xpath', '//my_xpath_string'),
>>>             description=Text('xpath', '//my_xpath_string')
>>>         )
>>>
>>> def test_stuff():
>>>     # Ensure 10 items have a price of $9.99
>>>     inventory = Inventory()
>>>     found_areas = inventory.items.areas.containing(
>>>         "price", "$9.99")
>>>     assert 10 == len(found_areas)
contain()

Check if a Field in any Area contains a specific value.

Parameters:
  • field_name (str) – The name of the Field object.
  • field_value (str) – The value of the Field object.
Returns:

True if matching value found, else False

Return type:

bool

Example

>>> class Inventory(Page):
>>>     def __init__(self):
>>>         self.items = RepeatingArea(
>>>             root=Root('xpath', '//div[@id='inventory']'),
>>>             description=Text('xpath', './td[1]')
>>>         )
>>>
>>> def test_stuff():
>>>     inventory = Inventory()
>>>     assert inventory.items.areas.contain(
>>>         "description", "Bananas")

Reusing Areas

Sometimes an identical Area may be present on multiple pages. Areas do not need to be created inside a page object, they can be created outside and then called from inside a page.

header = Area(
    ...
)

class Items(Page):
    def __init__(self, *args, **kwargs):
        self.header = header

Subclassing Areas

If an Area appears on many pages and requires many custom methods, it may be better to subclass the Area instead of embedding the methods in the Page Object:

class Header(Area):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def my_custom_method(self, *args, **kwargs):
        ...


class Main(Page):
    def __init__(self, *args, **kwargs):
        self.header = Header()


class Other(Page):
    def __init__(self, *args, **kwargs):
        self.header = Header()