Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
abalakh opened this issue May 16, 2018 · 1 comment
Open

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

abalakh opened this issue May 16, 2018 · 1 comment

Comments

@abalakh
Copy link

abalakh commented May 16, 2018

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?

@mfalesni
Copy link
Contributor

mfalesni commented Jun 5, 2018

ROOT defines __locator__

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants