Splinter Integration

Stere contains Fields designed specifically for when Splinter is connected. Each implements a specific performer method.

All Fields designed for Splinter also inherit the following convenience methods:

Example:

class Inventory(Page):
    def __init__(self):
        self.price = Link('css', '.priceLink')


assert Inventory().price.is_present(wait_time=6)

Fields

Button

class stere.fields.Button

Convenience Class on top of Field, it implements click() as its performer.

Checkbox

class stere.fields.Checkbox

By default, the Checkbox field works against HTML inputs with type=”checkbox”.

Can be initialized with the default_checked argument. If True, the Field assumes the checkbox’s default state is checked.

It implements opposite() as its performer.

Input

class stere.fields.Input

A simple wrapper over Field, it implements fill() as its performer.

The default_value argument can be provided, which will be used if fill() is called with no arguments.

self.quantity = Dropdown('id', 'qty', default_value='555')

Money

class stere.fields.Money

Money has methods for handling Fields where the text is a form of currency.

Locator Strategies

These represent the way a locator can be searched for.

By default, the strategies available with Splinter are:

  • css
  • xpath
  • tag
  • name
  • text
  • id
  • value

These strategies can be overridden with a custom strategy (ie: You can create a custom css strategy with different behaviour).

Custom Locator Strategies

Custom strategies can be defined using the @strategy decorator on top of a Class.

Any class can be decorated with @strategy, as long as the _find_all and _find_all_in_parent methods are implemented.

In the following example, the ‘data-test-id’ strategy is defined. It wraps Splinter’s find_by_xpath method to simplify the locator required on the Page Object.

from stere.strategy import strategy


@strategy('data-test-id')
class FindByDataTestId():
    def _find_all(self):
        """Find from page root."""
        return self.browser.find_by_xpath(f'.//*[@data-test-id="{self.locator}"]')

    def _find_all_in_parent(self):
        """Find from inside parent element."""
        return self.parent_locator.find_by_xpath(f'.//*[@data-test-id="{self.locator}"]')

With this implemented, Fields can now be defined like so:

my_button = Button('data-test-id', 'MyButton')

Support for data-* attributes is also available via the add_data_star_strategy function:

from stere.strategy import add_data_star_strategy


add_data_star_strategy('data-test-id')

This will automatically add the desired data-* attribute to the valid Splinter strategies.