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

fixed the modal test, resolved #126 Issue #128

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/widgetastic_patternfly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1808,14 +1808,17 @@ class Modal(View):

def __init__(self, parent, id=None, logger=None):
self.id = id
if id:
self.ROOT = ParametrizedLocator(
'.//div[normalize-space(@id)={@id|quote} and '
'contains(@class, "modal") and contains(@class, "fade") '
'and @role="dialog"]')

View.__init__(self, parent, logger=logger)

def __locator__(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In View or Widget when we set ROOT locator should auto-resolve.

I think it will be great if we fallow an approach like

ROOT = ParametrizedLocator("{@locator}")
def __init__(self, parent, id=None, logger=None):
    self.id = id
    if id:
        self.locator = <some_loator_with id>
    else:
        self.locator = <default>

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think implementing __locator__ here is okay, though the pattern @digitronik suggested above does it without implementing the dunder method.

Why its broken in the first place, and why this fix works, is because of the WidgetMetaclass behavior in __new__.

Before the WidgetDescriptor instance is created when the unit test is defining the test view class, WidgetMetaclass is setting __locator__ based on the presence of ROOT in the kwargs. After this, when the WidgetDescriptor resolves into a View instance in the presence of a browser, self.ROOT is modified - but self.__locator__ has already been created automatically based off of the original definition.

"""If id was passed, parametrize it into a locator, otherwise use ROOT"""
if self.id is not None:
return ('//div[normalize-space(@id)="{}" and contains(@class, "modal")'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please continue to use ParametrizedLocator here, its handling the injection of self.id into the string. No need to use format here, that part shouldn't change.

'and contains(@class, "fade") and @role="dialog"]'
.format(self.id))
else:
return self.ROOT

@property
def title(self):
return self.header.title.read()
Expand Down