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

FluentTest not able to instantiate WebDriver instance, problem with (absence of) Capabilities #2071

Open
jlannoy opened this issue Dec 15, 2023 · 1 comment

Comments

@jlannoy
Copy link

jlannoy commented Dec 15, 2023

Trying to reuse old tests with the last version of FluentLenium, we encountered a blocking error.

org.openqa.selenium.WebDriverException: Browser failed to start, test [ ... ] execution interrupted.
Caused by: [ Index 0 out of bounds for length 0]
Build info: version: '4.9.0', revision: 'd7057100a6'
System info: os.name: 'Mac OS X', os.arch: 'aarch64', os.version: '13.4.1', java.version: '19.0.2'
Driver info: driver.version: unknown

Further :

Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
	at io.fluentlenium.configuration.DefaultWebDriverFactories$ChromeWebDriverFactory.newInstance(DefaultWebDriverFactories.java:64)

Looking deeply at what happens, it comes from the DefaultWebDriverFactories.

    /**
     * Chrome WebDriver factory.
     */
    @FactoryPriority(64)
    @DefaultFactory
    public static class ChromeWebDriverFactory extends ReflectiveWebDriverFactory {

        /**
         * Creates a new chrome WebDriver factory.
         */
        public ChromeWebDriverFactory() {
            super("chrome", "org.openqa.selenium.chrome.ChromeDriver");
        }

        @Override
        protected WebDriver newInstance(Class<? extends WebDriver> webDriverClass, ConfigurationProperties configuration, Object... args) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {

            Capabilities oCaps = (Capabilities) args[0];
            ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions = chromeOptions.merge(oCaps);

            return super.newInstance(webDriverClass, configuration, chromeOptions);
        }
    }

The (Capabilities) args[0]; fails because when we are using default FluentTest configuration, the newInstance function is called from ReflectiveWebDriverFactory with a null array of args, that array being the third constructor parameter from the driver factory...

            DesiredCapabilities defaultCapabilities = newDefaultCapabilities();
            if (defaultCapabilities != null) {
                defaultCapabilities.merge(capabilities);
                capabilities = defaultCapabilities;
            }

            if (capabilities != null && !capabilities.asMap().isEmpty()) {
                ArrayList<Object> argsList = new ArrayList<>(Arrays.asList(args));
                argsList.add(0, capabilities);
                try {
                    return newInstance(webDriverClass, configuration, argsList.toArray());
                } catch (NoSuchMethodException e) { // NOPMD EmptyCatchBlock
                    // Ignore capabilities.
                }
            }
            return newInstance(webDriverClass, configuration, args);

The args on the last line here is a local attribute of a WebDriver factory, which are taken form the third+ arguments of the factory constructor. super("chrome", "org.openqa.selenium.chrome.ChromeDriver");... Which doesn't exist, leading in an empty array.

How to reproduce?

The Basic FluentLenium test on the quickstart page will simply fail the same way, in a new empty project.

Current fix

To fix our tests, we override a method to have default (unused) capabilities and skip the line looking at the empty array :

   @Override
    public Capabilities getCapabilities() {
        return new MutableCapabilities(Map.of("cloud:options", Map.of("name", this.getClass().getSimpleName())));
    }

I don't know if the WebDriverFactories should simply pay attention to the fact that the args array can be empty. I would assume something as change in a recent version of FluentLenium.

@jlannoy
Copy link
Author

jlannoy commented Mar 6, 2024

Thank you for reporting the issue, and your current fix ; I came here looking for the same one...

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

No branches or pull requests

1 participant