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

SelectElement: various getText()-methods are not implemented properly #5646

Closed
Slava569845 opened this issue Oct 12, 2023 · 9 comments
Closed
Assignees
Labels

Comments

@Slava569845
Copy link

Slava569845 commented Oct 12, 2023

Hello, we're using Vaadin 23 and doing selenium-tests quite a lot. We recently found, that extracting a simple text from a simple Select-item is quite cumbersome with provided SelectElement. I have build a small test case (maven project, attached) demonstrating the issue:

Production view:

@Route("demo")
public class SelectDemo extends VerticalLayout
{
    public SelectDemo()
    {
        Select<String> select = new Select<>();
        select.setItems("1", "2", "3");
        select.setValue("2");
        add(select);
    }
}

Selenium test:

@Test
public void test()
{
    driver.navigate().to("http://localhost:8090/demo");
    SelectElement selectElement = $(SelectElement.class).waitForFirst();
    LOGGER.info("Items.getText: {}", selectElement.getItems().stream().map(SelectElement.ItemElement::getText).collect(Collectors.toList()));
    LOGGER.info("Items.getPropertyString(textContent): {}", selectElement.getItems().stream().map(i -> i.getPropertyString("textContent")).collect(Collectors.toList()));
    LOGGER.info("getSelectedItem().getText(): {}", selectElement.getSelectedItem().getText());
    LOGGER.info("getSelectedText(): {}", selectElement.getSelectedText());
}

Output:

[main] INFO de.akdb.SelectDemoSeleniumTest - Items.getText: [, , ]
[main] INFO de.akdb.SelectDemoSeleniumTest - Items.getPropertyString(textContent): [1, 2, 3]
[main] INFO de.akdb.SelectDemoSeleniumTest - getSelectedItem().getText(): 
[main] INFO de.akdb.SelectDemoSeleniumTest - getSelectedText(): 

Basically various getText methods are not working as one would intuitively expect them to and we have to resort to dubios workaround getPropertyString("textContent"), which may depend on the implementation and thus Vaadin version i'm afraid.

@Slava569845
Copy link
Author

selectelement.zip

@mshabarov mshabarov added bug Something isn't working and removed bug Something isn't working labels Oct 31, 2023
@mshabarov mshabarov transferred this issue from vaadin/testbench Oct 31, 2023
@mshabarov
Copy link
Contributor

@rolfsmeds @yuriy-fix the API described above is a part of Select component TestBench extension, so I transferred the issue there.

@bwajtr bwajtr self-assigned this Nov 9, 2023
@bwajtr
Copy link
Contributor

bwajtr commented Nov 9, 2023

I managed to reproduce the issue with the provided project (slightly modified so it uses bonigarcia WebDriverManager to setup the WebDriver), but only when testing using Firefox. When running the test using Chrome or Safari the texts retrieval from Selects works as expected.

I've used the following version of the driver:

[main] INFO io.github.bonigarcia.wdm.WebDriverManager - Using geckodriver 0.33.0 (resolved driver for Firefox 119)

Reproduced with Vaadin 23.3.26

@bwajtr
Copy link
Contributor

bwajtr commented Nov 10, 2023

I've tested the issue, and all the various ways to get the text of the selected item are actually relying on calling org.openqa.selenium.WebElement.getText() to get the rendered (visible) text of the element.

This Selenium API method does not work correctly when using FirefoxDriver where it always returns an empty string if the element is a custom webcomponent. I mean any webcomponent... not only Vaadin webcomponents. So this is not a Vaadin-specific issue. And the problem is unfortunately not in TestBench, but in Selenium itself.

However, that means that this problem does not affect only SelectElement but all the Vaadin TestBench Element classes.

The issue has already been reported to various places, and it seems that it's being actively worked on in recent hours:

An issue was reported against webdriverio:
webdriverio/webdriverio#11360
... However, they suggested that this is a geckodriver (FirefoxDriver) issue:
mozilla/geckodriver#2097
... and they found that it might be a problem in Firefox itself:
https://bugzilla.mozilla.org/show_bug.cgi?id=1824664
... so - if I got it right - something has been reverted, but not released yet and the work continues in Selenium:
SeleniumHQ/selenium#13132

I think it makes sense to wait now for fix of the mentioned bugs before trying to do any workarounds in the TestBench code.

The immediate workaround which I can advice now is not to use Firefox for TestBench testing until the issue is resolved ,and switch for example to ChromeDriver, where this issue does not exist.

@bwajtr
Copy link
Contributor

bwajtr commented Nov 13, 2023

I've put together simple project where it's demonstrated that the Firefox Selenium driver does not work correctly and returns empty strings when calling WebElement.getText() for webcomponents. Use this project to test if the issue was fixed already or not:

https://github.com/bwajtr/selenium-firefox-gettext-webcomponents

@bwajtr
Copy link
Contributor

bwajtr commented Nov 13, 2023

Current state:

  1. Wait for [🐛 Bug]: "Get Text" atom returns an empty string for elements within a closed ShadowDOM SeleniumHQ/selenium#13132 to be fixed
  2. Wait for a new version of geckodriver/selenium is released
  3. Retest using the following project (bump library versions there first): https://github.com/bwajtr/selenium-firefox-gettext-webcomponents

If the mentioned bug is not fixed for a long time, then we will have to introduce some workarounds in TestBench how to getText() from webcomponents when FirefoxDriver is used.

@bwajtr
Copy link
Contributor

bwajtr commented Nov 22, 2023

The problem has been fixed in Firefox and the fix will be available in Firefox 122. I have tested with the nightly build of Firefox 122 and the issue is no longer reproducible with it.

Current status of this issue:

  1. Wait for Firefox 122 to be released -> install on your machine
  2. Retest using the following project (version bump is not needed in the project): https://github.com/bwajtr/selenium-firefox-gettext-webcomponents
  3. If all tests pass then close this issue

@TatuLund
Copy link
Contributor

NotificationElement#getText is also not not working with Firefox, you can run IT's here to see https://github.com/TatuLund/ColorPicker/blob/master/src/test/java/org/vaadin/addons/tatu/FirefoxColorPickerIT.java the same tests work ok for Chrome.

@DiegoCardoso
Copy link
Contributor

I tested this with the project provided by @bwajtr and also tested NotificationElement#getText in Firefox, and both work.

Closing as no longer reproducible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants