From 8012bcfed62be42bebc69402dd17672408b7ce14 Mon Sep 17 00:00:00 2001 From: Iker Reyes Date: Thu, 16 Jun 2022 08:36:02 +0200 Subject: [PATCH] Set default component_id to "" for OUIA base components Using None as default values fails on the _set_attrs function as None cannot be quoted --- src/widgetastic/ouia/__init__.py | 4 ++-- testing/test_ouia.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/widgetastic/ouia/__init__.py b/src/widgetastic/ouia/__init__.py index 1a4e1fe..f90b6d5 100644 --- a/src/widgetastic/ouia/__init__.py +++ b/src/widgetastic/ouia/__init__.py @@ -30,7 +30,7 @@ class OUIABase: def _set_attrs( self, component_type: str, - component_id: Optional[str] = None, + component_id: str = "", ) -> None: self.component_type = quote(component_type) self.component_id = quote(component_id) @@ -104,7 +104,7 @@ class OUIAGenericWidget(OUIABase, Widget, ClickableMixin): def __init__( self, parent: ViewParent, - component_id: Optional[str] = None, + component_id: str = "", logger: Optional[Logger] = None, component_type: Optional[str] = None, ) -> None: diff --git a/testing/test_ouia.py b/testing/test_ouia.py index 7dda5bc..b590d3e 100644 --- a/testing/test_ouia.py +++ b/testing/test_ouia.py @@ -57,3 +57,13 @@ def test_safety(testing_view): def test_select(testing_view): testing_view.select.choose("first_option") testing_view.select.choose("second_option") + + +def test_widget_without_id(browser): + class TestView(OUIAGenericView): + OUIA_COMPONENT_TYPE = "TestView" + button = Button() + + view = TestView(browser) + assert view.is_displayed + assert view.button.locator == './/*[@data-ouia-component-type="PF/Button"]'