Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    SelectItem and Playwright testing

    Has anyone managed to write a Playwright test to test a SelectItem?
    I've just started using Playwright and have a few working tests but am struggling with getting Playwright to input via a SelectItem.
    Playwright's get_by_label doesn't work, I think because the SelectItem label's html doesn't include the "for" tag to link it to the control it's labelling (and Isomorphic explain why it doesn't in https://forums.smartclient.com/forum...-screen-reader).
    I tried using SelectItem's setID and my id does appear in the HTML but not as the id field, which is still autogenerated (e.g. id="isc_JS").
    I also tried setting an attribute with key "data-testid", because that's what Playwright uses for get_by_test_id, but it doesn't appear in html.

    To be clear, I'm not suggesting SmartGWT isn't working correctly, I'm just looking for help with using Playwright to test screens with SelectItems.

    My SmartGWT version is SmartClient Version: v13.0p_2022-06-09/PowerEdition Deployment (built 2022-06-09)
    Last edited by rodp; 24 Mar 2023, 04:28. Reason: Corrected - attribute "data-testid" doesn't make it to html

    #2
    Hi rodp,

    You want to use SCLocators to identify elements, because SmartGWT has to use different DOM structures in different browsers and with different settings, in order to work around browser bugs and also for performance reasons.

    Although we haven't tried it, it appears that Playwright does support the concept of custom locators. We would recommend talking to ChatGPT about how to do the integration, as ChatGPT is aware of both Playwright and SmartGWT. Just be aware that it sometimes makes things up!

    Another option would be to have our consulting team set up the integration and get you started with a few working tests. Most if not all of this work would qualify for our special Feature Sponsorship (lower) rate if the goal of the project was to produce documentation & sample code for how to test using Playwright.

    Background:

    https://smartclient.com/smartgwtee-l...edTesting.html

    Comment


      #3
      I worked it out. For a SelectItem with title "Business" and a ValueMap containing "A" the following Python code works:
      Code:
      page.locator('tr:has-text("Business\u00A0:")').locator("td:has(table.selectItemControl)").click()
      page.get_by_role("option").filter(has_text="A").click()
      .locator('tr:has-text("Business\u00A0:")') finds the row containing title "Business :" - \u00A0 is the Unicode no break space character.
      Within the row, .locator("td:has(table.selectItemControl)") finds the selectItemControl class. There is only one on my form's row.
      Clicking the SelectItem control displays the list of options, page.get_by_role("option").filter(has_text="A").click() selects option A

      Comment


        #4
        rodp, not sure if you saw our previous message, but this in not a supported or even supportable solution.

        The DOM rendered by SmartClient varies by browser, browser version, SmartClient version, settings on components, skin, and other factors. This means that code like you've written in Playwright could break when we do a minor bugfix. And if it did, we would not attempt to "fix" the problem, because the test itself is invalid.

        Our documentation explains the right approach at length - as we also explained above.

        To be clear for any other reader: no one should copy this approach. It is not supported. Refer to Isomorphic's posts and to the docs to learn the correct approach.

        Comment

        Working...
        X