Skip to content

[Playwright] Date time and forms and some component widget migration#104

Merged
digitronik merged 2 commits into
RedHatQE:feature-playwrightfrom
digitronik:date_time_forms
Oct 17, 2025
Merged

[Playwright] Date time and forms and some component widget migration#104
digitronik merged 2 commits into
RedHatQE:feature-playwrightfrom
digitronik:date_time_forms

Conversation

@digitronik

@digitronik digitronik commented Oct 16, 2025

Copy link
Copy Markdown
Member

Summary by Sourcery

Migrate widgetastic_patternfly5 components and tests to Playwright’s current API by updating locators, element interactions, and assertions, adjust test fixtures and CI workflow to improve stability.

Enhancements:

  • Standardize component methods to use browser.fill, .click(), element.press, browser.text, .text_content(), .is_visible(), .attributes(), and Select.select_option
  • Refine locator expressions in CalendarMonth and other widgets for more precise element targeting

CI:

  • Update GitHub Actions workflow to ignore specific unstable tests (slider, switch, title, ouia)

Tests:

  • Update tests to replace .is_displayed() with .is_visible() and .text with .text_content(), remove redundant parent locators, and add slight delays for popover stability
  • Set browser context viewport to 1920x1080 in conftest and remove deprecated TESTVIEW ROOT locator

@sourcery-ai

sourcery-ai Bot commented Oct 16, 2025

Copy link
Copy Markdown

Reviewer's Guide

This PR migrates core widget components and tests from Selenium-style interactions to Playwright-friendly APIs by refactoring locator expressions, replacing element actions and property accessors with browser helper methods, and standardizing text and visibility handling across the codebase.

Sequence diagram for refactored form select fill and read methods

sequenceDiagram
    participant User
    participant FormSelect
    participant Browser
    User->>FormSelect: fill(value)
    FormSelect->>Browser: __element__().select_option(label=value)
    User->>FormSelect: read()
    FormSelect->>Browser: text("option:checked")
    Browser-->>FormSelect: selected option text
Loading

Sequence diagram for calendar month year setter (Playwright migration)

sequenceDiagram
    participant User
    participant BaseCalendarMonth
    participant Browser
    User->>BaseCalendarMonth: set year(value)
    BaseCalendarMonth->>Browser: fill(str(value), YEAR_INPUT_LOCATOR)
    BaseCalendarMonth->>Browser: click(".//body")
Loading

Sequence diagram for pagination go_to_page method (Playwright migration)

sequenceDiagram
    participant User
    participant Pagination
    participant Browser
    User->>Pagination: go_to_page(value)
    Pagination->>Pagination: _current_page.fill(value)
    Pagination->>Browser: _current_page.__element__().press("Enter")
Loading

Class diagram for refactored widget components (Playwright migration)

classDiagram
    class BaseCalendarMonth {
        +CALENDAR_HEADER
        +MONTH_SELECT_LOCATOR
        +_month_select_widget
        +YEAR_INPUT_LOCATOR
        +DATE_LOCATOR
        +PREV_BUTTON_LOCATOR
        +NEXT_BUTTON_LOCATOR
        +TABLE
        +SELECTED_DATE_LOCATOR
        +year
        +month
        +day
    }
    class BaseDualListSelector {
        +_available
        +_chosen
        +_left_list
        +_right_list
        +_left_title
        +_right_title
        +_left_elements
        +_right_elements
        +read(selected_only)
        +reset_selected(left_items)
    }
    class BaseClipboardCopy {
        +is_editable()
        +is_inline
        +text
    }
    class FormSelect {
        +fill(value)
        +read()
        +__repr__()
        +all_enabled_options
        +_select_element
        +__element__()
    }
    class Pagination {
        +is_enabled()
        +set_per_page(count)
        +go_to_page(value)
        +__iter__()
        +_last
        +_options
        +_next
        +_current_page
        +current_page
    }
Loading

File-Level Changes

Change Details Files
Refactor CalendarMonth locators and interactions to use Playwright helpers
  • replaced f-string based XPath locators with direct expressions
  • replaced send_keys with browser.fill and root_browser.click to set year
  • used Select widget’s read method for month property
src/widgetastic_patternfly5/components/date_and_time/calendar_month.py
Simplify DualListSelector element references
  • removed unnecessary parent parameter on element lookups
  • switched element text access to browser.text and text_content
  • streamlined read() to use list comprehensions with browser.text
src/widgetastic_patternfly5/components/dual_list_selector.py
testing/components/test_dual_list_selector.py
Standardize text retrieval and visibility checks
  • replaced el.text and get_property('textContent') with browser.text or el.text_content().strip
  • replaced is_displayed() with is_visible() in components and tests
src/widgetastic_patternfly5/components/navigation.py
src/widgetastic_patternfly5/components/pagination.py
testing/components/test_modal.py
testing/components/test_card.py
testing/components/test_popover.py
Update FormSelect and Pagination to Playwright API
  • use element().select_option and browser.text('option:checked') in FormSelect
  • use element().press('Enter') instead of send_keys for pagination navigation
  • improved pagination controls to use is_visible()
src/widgetastic_patternfly5/components/forms/form_select.py
src/widgetastic_patternfly5/components/pagination.py
Fix readonly detection in ClipboardCopy
  • use browser.attributes to check for 'readonly' attribute instead of get_attribute
src/widgetastic_patternfly5/components/clipboard_copy.py
Adjust tests, fixtures, and CI configuration
  • replace .text with .text_content().strip() in test assertions
  • set default viewport in browser_context fixture
  • update pytest command to ignore specific flaky tests
testing/conftest.py
.github/workflows/tests.yaml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • I see many manual conversions from element.text or get_property to browser.text or text_content; consider centralizing text retrieval in a helper or in the base widget to ensure consistency instead of updating each usage individually.
  • The workaround of clicking on the body after filling the year input feels brittle; it might be more robust to trigger a blur event or wait for the field’s change event rather than relying on an extra click.
  • The CI workflow is now ignoring several test files—please confirm that skipping those tests is intentional and document the rationale to avoid masking potential regressions.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- I see many manual conversions from element.text or get_property to browser.text or text_content; consider centralizing text retrieval in a helper or in the base widget to ensure consistency instead of updating each usage individually.
- The workaround of clicking on the body after filling the year input feels brittle; it might be more robust to trigger a blur event or wait for the field’s change event rather than relying on an extra click.
- The CI workflow is now ignoring several test files—please confirm that skipping those tests is intentional and document the rationale to avoid masking potential regressions.

## Individual Comments

### Comment 1
<location> `testing/components/test_dual_list_selector.py:27-28` </location>
<code_context>

 def test_available(view):
-    view.dual_list_selector._available.is_displayed()
+    view.dual_list_selector._available.is_visible()


</code_context>

<issue_to_address>
**suggestion (testing):** Consider adding assertions to verify the expected state after visibility checks.

The test should assert the result of is_visible() to confirm the component's state is as expected.

```suggestion
def test_available(view):
    assert view.dual_list_selector._available.is_visible()
```
</issue_to_address>

### Comment 2
<location> `testing/components/test_popover.py:46` </location>
<code_context>

 def test_popover_close(popover):
     popover.close()
+    time.sleep(0.5)
     assert not popover.is_displayed
</code_context>

<issue_to_address>
**suggestion (testing):** Consider replacing time.sleep with a more robust wait mechanism.

Explicitly wait for popover.is_displayed to become False instead of using time.sleep to reduce test flakiness.
</issue_to_address>

### Comment 3
<location> `src/widgetastic_patternfly5/components/clipboard_copy.py:23-26` </location>
<code_context>
    @property
    def is_editable(self):
        if self.is_inline:
            return False
        if "readonly" in self.browser.attributes(self.text):
            return False
        else:
            return True

</code_context>

<issue_to_address>
**suggestion (code-quality):** We've found these issues:

- Replace if statement with if expression ([`assign-if-exp`](https://docs.sourcery.ai/Reference/Default-Rules/refactorings/assign-if-exp/))
- Simplify boolean if expression ([`boolean-if-exp-identity`](https://docs.sourcery.ai/Reference/Default-Rules/refactorings/boolean-if-exp-identity/))
- Remove unnecessary casts to int, str, float or bool ([`remove-unnecessary-cast`](https://docs.sourcery.ai/Reference/Default-Rules/refactorings/remove-unnecessary-cast/))

```suggestion
        return "readonly" not in self.browser.attributes(self.text)
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread testing/components/test_dual_list_selector.py Outdated
Comment thread testing/components/test_popover.py
Comment thread src/widgetastic_patternfly5/components/clipboard_copy.py Outdated
Comment thread .github/workflows/tests.yaml

@mshriver mshriver left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Possible simplification of locator string, see individual comment that is non-blocking.

@digitronik digitronik merged commit 88d8e93 into RedHatQE:feature-playwright Oct 17, 2025
10 of 11 checks passed
@digitronik digitronik deleted the date_time_forms branch October 17, 2025 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants