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

Test user fails when using ElementFilter to look for select elements #3486

Closed
marcuslimdw opened this issue Aug 13, 2024 · 3 comments · Fixed by #3487
Closed

Test user fails when using ElementFilter to look for select elements #3486

marcuslimdw opened this issue Aug 13, 2024 · 3 comments · Fixed by #3487
Labels
bug Something isn't working
Milestone

Comments

@marcuslimdw
Copy link
Contributor

marcuslimdw commented Aug 13, 2024

Description

What I'm trying to do

Write integration tests using nicegui.testing.User for a NiceGUI page that contains a Select element:

async def test_this(nicegui_user: testing.User):  # nicegui_user is a fixture I defined that sets up my app
    await nicegui_user.open("/new/vendors")
    await nicegui_user.should_see("Vendor name")

What I expected

The test runs successfully.

What happened

The test fails on the should_see call with:

self = <nicegui.element_filter.ElementFilter object at 0x13338d7e0>

    def __iter__(self) -> Iterator[T]:
        # pylint: disable=protected-access
        for element in self._scope.descendants():
            if self._kind and not isinstance(element, self._kind):
                continue
            if self._exclude_kinds and isinstance(element, tuple(self._exclude_kinds)):
                continue
    
            if any(marker not in element._markers for marker in self._markers):
                continue
            if any(marker in element._markers for marker in self._exclude_markers):
                continue
    
            if self._contents or self._exclude_content:
                element_contents = [content for content in (
                    element._props.get('text'),
                    element._props.get('label'),
                    element._props.get('icon'),
                    element._props.get('placeholder'),
                    element._props.get('value'),
>                   element._props.get('options', {}).get('message'),
                    element.text if isinstance(element, TextElement) else None,
                    element.content if isinstance(element, ContentElement) else None,
                    element.source if isinstance(element, SourceElement) else None,
                ) if content]
E               AttributeError: 'list' object has no attribute 'get'

../../../../../.venv/lib/python3.10/site-packages/nicegui/element_filter.py:111: AttributeError

For the specific case of a SelectElement, element._props['options'] is a list. If I comment out the ui.select calls, the test passes.

@marcuslimdw marcuslimdw changed the title Test user fails when using ElementFilter to look for Test user fails when using ElementFilter to look for select elements Aug 13, 2024
@falkoschindler
Copy link
Contributor

Thanks for reporting this bug, @marcuslimdw!

@rodja Do you think we still need the line

element._props.get('options', {}).get('message')

after changing ui.notify in PR #3457? get('message') looks like it was meant to handle notifications. But it turns out to be rather fragile.

@falkoschindler falkoschindler added the bug Something isn't working label Aug 13, 2024
@falkoschindler falkoschindler added this to the 1.4.35 milestone Aug 13, 2024
@rodja
Copy link
Member

rodja commented Aug 13, 2024

@falkoschindler, no, the line is needed to find ui.notification elements (and for example dismiss them). I just created #3487 to provide better support for ui.select. This also fixes this issue.

@rodja rodja linked a pull request Aug 14, 2024 that will close this issue
@rodja
Copy link
Member

rodja commented Aug 14, 2024

Should be fixed with #3487 and hence available in next release 1.4.35.

@rodja rodja closed this as completed Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants