RedHatQE / RedHatQE/widgetastic.core

[RFE] Add ability to define DEFAULT_LOCATOR for widget

Open
#97 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
37
Forks
46
PR merge metrics
No merged PRs in 30d

Description

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?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the GenericLocatorWidget constructor described in the issue and inspect how Widget initialization and locator assignment currently work. Add support for an optional DEFAULT_LOCATOR class attribute, then verify that widgets can omit a locator while an explicitly supplied locator still takes precedence.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.