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 fields.

The Area object takes any number of Fields as arguments. Each Field must be unique on the Page and only present in one Area.

Example:

>>> from stere.areas import Area
>>> from stere.fields import Button
>>>
>>> class Album(Page):
>>>     def __init__(self):
>>>         self.tracks = Area(
>>>             first_track=Button('xpath', '//my_xpath_string'),
>>>             second_track=Button('xpath', '//my_xpath_string'),
>>>             third_track=Button('xpath', '//my_xpath_string'),
>>>         )
>>>
>>> def test_stuff():
>>>     album = Album()
>>>     album.tracks.third_track.click()
perform()

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

Every Field that implements perform() must return True or False. If True, assume the argument has been used. If False, assume the argument is still available.

Parameters:args – Array that should be equal to the number of Fields in the Area that take an argument.

Example

>>> from stere.areas import Area
>>> from stere.fields import Button, Input
>>>
>>> class Login():
>>>     def __init__(self):
>>>         self.form = Area(
>>>             username=Input('xpath', '//my_xpath_string'),
>>>             password=Input('xpath', '//my_xpath_string'),
>>>             submit=Button('xpath', '//my_xpath_string')
>>>         )
>>>
>>>
>>> def test_login():
>>>     login = Login()
>>>     login.my_area.perform('Sven', 'Hoek')
class stere.areas.RepeatingArea

Represents a collection of Fields that appear multiple times on a Page.

The RepeatingArea objects requires a Root Field in the arguments, but otherwise takes any number of Fields as arguments. The other Fields will use the Root as a parent.

Example:

>>> from stere.areas import RepeatingArea
>>> from stere.fields import Root, Input
>>>
>>> class MyPage():
>>>     def __init__(self):
>>>         self.my_repeating_area = RepeatingArea(
>>>             root=Root('xpath', '//my_xpath_string'),
>>>             my_input=Input('xpath', '//my_xpath_string')
>>>         )
areas()

Find all instances of the root, then return an array of Areas for each root.

Returns:Collection of every Area that was found.
Return type:list
Raises:ValueError – If no Areas were found.

Example:

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

Searches the RepeatingArea for a single Area where the Field’s value matches the expected value and then returns the entire Area object.

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

Area

Example

>>> class Inventory():
>>>     def __init__(self):
>>>         self.items = RepeatingArea(
>>>             root=Root('xpath', '//my_xpath_string'),
>>>             description=Text('xpath', '//my_xpath_string')
>>>         )
>>>
>>> def test_stuff():
>>>     inventory = Inventory()
>>>     found_area = inventory.items.area_with(
>>>         "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()