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

ChromeDriver 96+ is not compatible with Selenium 3 #1307

Closed
mshabarov opened this issue Dec 13, 2021 · 6 comments
Closed

ChromeDriver 96+ is not compatible with Selenium 3 #1307

mshabarov opened this issue Dec 13, 2021 · 6 comments

Comments

@mshabarov
Copy link
Contributor

The following code getting the shadow root from WebComponent instance won’t work with ChromeDriver 96+ and Selenium 3:
https://github.com/vaadin/flow/blob/375eab86653d5866fb3ea2faba1c4600df976e1b/flow-[…]il/src/main/java/com/vaadin/flow/testutil/TestBenchHelpers.java

WebElement shadowRoot = (WebElement) getCommandExecutor().executeScript("return arguments[0].shadowRoot", webComponent);

because of breaking changes in ChromeDriver to be compliant with w3c spec.
It fails with
java.lang.ClassCastException: class com.google.common.collect.Maps$TransformedEntriesMap cannot be cast to class org.openqa.selenium.WebElement.

Here is an example how to use ChromeDriver 96+ and Selenium 4.1:

WebElement element = driver.findElement(By.css('#container'));
SearchContext context = element.getShadowRoot();
WebElement inside = context.findElement(By.cssSelector("#inside"));

Here is a workaround for ChromeDriver 95 and Selenium 3:

public WebElement expandRootElement(WebElement shadowHost) {
        WebElement returnObj = null;
        Object shadowRoot = ((JavascriptExecutor) driver).executeScript("return arguments[0].shadowRoot", shadowHost);
        if (shadowRoot instanceof WebElement) {
            // ChromeDriver 95
            returnObj = (WebElement) shadowRoot;
        }
        else if (shadowRoot instanceof Map)  {
            // ChromeDriver 96+
            // Based on https://github.com/SeleniumHQ/selenium/issues/10050#issuecomment-974231601
            Map<String, Object> shadowRootMap = (Map<String, Object>) shadowRoot;
            String shadowRootKey = (String) shadowRootMap.keySet().toArray()[0];
            String id = (String) shadowRootMap.get(shadowRootKey);
            RemoteWebElement remoteWebElement = new RemoteWebElement();
            remoteWebElement.setParent((RemoteWebDriver) driver);
            remoteWebElement.setId(id);
            returnObj = remoteWebElement;
        }
        else {
            Assert.fail("Unexpected return type for shadowRoot in expandRootElement()");
        }
        return returnObj;
    }

More information here https://giters.com/SeleniumHQ/selenium/issues/10050

@cdir
Copy link

cdir commented Jan 18, 2022

We need to run our tests with a current Chrome instance. Therefore, it is mandatory that we can run the vaadin testbench with a current Selenium version.

Also mentioned by #1279

@Artur-
Copy link
Member

Artur- commented Jan 18, 2022

This issue should really say "Some workaround used inside the Flow project no longer works with Chrome 96+". As far as I know, all TestBench provided API works fine with Chrome 96. We test with it ourselves every day.

What issue are you experiencing @cdir?

@cdir
Copy link

cdir commented Jan 18, 2022

We had some tests that used the same workaround to get the shadow root. We have already changed the code but it would be much better to use a new Selenium version with a stable support.

We also have several other non-reproducible bugs that we would have hoped would be less with a new selenium version.

For example (happens frequently since a few days):

[SEVERE]: Timed out receiving message from renderer: 600.000

@Artur-
Copy link
Member

Artur- commented Jan 18, 2022

Ok, so #1279 covers upgrading to Selenium 4. Can this be closed then because TestBench cannot fix workarounds done inside executeScript ?

[SEVERE]: Timed out receiving message from renderer: 600.000

At least what I have seen earlier, these have almost always indicated a problem in chrome/chromedriver and not Selenium.

@cdir
Copy link

cdir commented Jan 18, 2022

For this reason, we have already updated Chrome/Chromedriver to the latest version. But since we still get the error, we wanted to go to the latest Selenium version.

Apart from that, is there any reason to stay on such an old Selenium version? I think new versions may be more stable and have additional features, like support for shadow dom.

@Artur-
Copy link
Member

Artur- commented Feb 8, 2022

TestBench 8 is based on Selenium 4. The beta version is part of Vaadin 23 beta today. You should try it out to see if it resolves your problems

@Artur- Artur- closed this as completed Feb 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants