Skip to content

[RFE] Add ability to define DEFAULT_LOCATOR for widget #97

@abalakh

Description

@abalakh

With views and ROOT approach, we have a lot of situations when only 1 widget of kind is present in single view. Or different use case - we have widgets, which in 99% cases have the same locator, e.g. some .//div[contains(@class, "progress progress-striped")].
For such cases it's very handy to be able not to specify any locator at all and have some default one used instead:

class MyView(View):
    progress = ProgressBar()

But to be able to do that, i have to override widget's __init__ each time with smth like that:

        def __init__(self, parent, locator=None, logger=None):
        """Provide common progress bar locator if it wasn't specified."""
        Widget.__init__(self, parent, logger=logger)
        if not locator:
            locator = './/div[contains(@class, "progress progress-striped")]'
        self.locator = locator

It would be really nice to have such ability out of the box.

My suggestion - we could define some class attr for widget, e.g. DEFAULT_LOCATOR and slightly update GenericLocatorWidget with smth like:

-    def __init__(self, parent, locator, logger=None):
+    def __init__(self, parent, locator=None, logger=None):
         Widget.__init__(self, parent, logger=logger)
+        if not locator:
+            locator = getattr(self, 'DEFAULT_LOCATOR', None)
         self.locator = locator

This way i could optionally specify class attr DEFAULT_LOCATOR for my widget and i wouldn't have to override entire method each time:

class ProgressBar(GenericLocatorWidget):
    DEFAULT_LOCATOR = './/div[contains(@class, "progress progress-striped")]'
    # ...

Thoughts, other ideas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions