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

org.openqa.selenium.WebDriverException: Driver isn't initialized. This extension can only be used in combination with the DriverParameterResolver #661

Open
fabb opened this issue Mar 20, 2019 · 11 comments
Labels

Comments

@fabb
Copy link

fabb commented Mar 20, 2019

I'm trying to run junit5 selenium tests with the Java Test Runner. I always get this error message:

org.openqa.selenium.WebDriverException: Driver isn't initialized. This extension can only be used in combination with the DriverParameterResolver

I guess this is related to the webDriver parameter that the test method expects:

void testMyPage(final WebDriver driver) {...}

I googled for DriverParameterResolver but found absolutely nothing. Is it possible to run selenium tests with this extension, and if yes, how?

@jdneo
Copy link
Member

jdneo commented Mar 25, 2019

Hi @fabb,

Is it possible to share a sample project which can repro your problem with us? This can help us investigate the problem. I tried a project which contains junit5 selenium test but cannot repro the error your reported.

Thanks

@SupinePandora43
Copy link

@fabb you trying run 'gradle test' or something else ? if also getting error, then error caused not by java test runner

@fabb
Copy link
Author

fabb commented Mar 26, 2019

I found a likely reason for the problem. My project uses an @ExtendWith annotation (from jupiter) for injecting the webdriver and other stuff into test classes:

public class DriverParameterResolver implements ParameterResolver, AfterEachCallback {...}

@ExtendWith({ScreenshotExtension.class, DriverParameterResolver.class})
@BrowserUtil({PostProcessSetup.class, BrowserConfig.class})
public abstract class AbstractEndToEndTest {
}

class MyTest extends AbstractEndToEndTest {
    void testMyPage(final WebDriver driver) {...}
}

It seems like the Java Test Runner does not correctly apply those annotations when running tests.

@jdneo
Copy link
Member

jdneo commented Mar 27, 2019

@fabb Thank you for the information, I'll take a look and update you when I have any progress.

@jdneo
Copy link
Member

jdneo commented May 17, 2019

Hi @fabb

Is that possible for you to share a sample project which can repro the issue?

@fabb
Copy link
Author

fabb commented May 17, 2019

I‘ll try to reproduce it in an example project, could take me a while as I‘m swamped currently.

@jdneo
Copy link
Member

jdneo commented May 17, 2019

That will be great. Thanks a lot

@fabb
Copy link
Author

fabb commented Jun 16, 2019

I could reduce the project enough to also trigger a similar error in IntelliJ. It seems to be connected to auto-activated profiles in the pom. I have this section in my pom:

    <profiles>
        <profile>
            <id>mac</id>
            <activation>
                <os>
                    <family>mac</family>
                </os>
            </activation>
            <properties>
                <driver.platform>mac</driver.platform>
                <driver.arch>64</driver.arch>
            </properties>
        </profile>
        <profile>
            <id>linux</id>
            <activation>
                <os>
                    <family>unix</family>
                    <arch>amd64</arch>
                </os>
            </activation>
            <properties>
                <driver.platform>linux</driver.platform>
                <driver.arch>64</driver.arch>
            </properties>
        </profile>
        <profile>
            <id>win32</id>
            <activation>
                <os>
                    <family>windows</family>
                    <arch>x86</arch>
                </os>
            </activation>
            <properties>
                <driver.platform>windows</driver.platform>
                <driver.arch>32</driver.arch>
                <driver.extension>.exe</driver.extension>
            </properties>
        </profile>
        <profile>
            <id>win64</id>
            <activation>
                <os>
                    <family>windows</family>
                    <arch>amd64</arch>
                </os>
            </activation>
            <properties>
                <driver.platform>windows</driver.platform>
                <driver.arch>64</driver.arch>
                <driver.extension>.exe</driver.extension>
            </properties>
        </profile>
        <profile>
            <id>download-drivers</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.github.webdriverextensions</groupId>
                        <artifactId>webdriverextensions-maven-plugin</artifactId>
                        <version>3.1.3</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>install-drivers</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <installationDirectory>${project.basedir}${file.separator}drivers</installationDirectory>
                            <drivers>
                                <driver>
                                    <name>geckodriver</name>
                                    <platform>${driver.platform}</platform>
                                    <bit>${driver.arch}</bit>
                                    <version>${geckodriver.version}</version>
                                </driver>
                            </drivers>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

I will upload my project shortly, yet need to kick a few private things out first.

@fabb
Copy link
Author

fabb commented Jun 16, 2019

Ok, here you go: https://github.com/fabb/vscode-java-test-bug

The bug really seems to be related to the <activation> setting in the profiles in pom.xml.

@jdneo jdneo added the bug label Jun 17, 2019
@jdneo
Copy link
Member

jdneo commented Jun 17, 2019

Hi @fabb,

Thank you for the sample project you have provided, which is very useful! I can now repro the issue now and here are my findings so far.

Root Cause

The Test Runner does not honor the section:

<systemPropertyVariables>
    <buildDirectory>${project.build.directory}</buildDirectory>
    <webdriver.gecko.driver>
        ${driver.folder}geckodriver-${driver.platform}-${driver.arch}bit${driver.extension}
    </webdriver.gecko.driver>
    <webdriver.firefox.logfile>/dev/null</webdriver.firefox.logfile>
</systemPropertyVariables>

Workaround

For now, there is a workaround which is to manually pass the properties into the JVM. You can add a new setting into your workspace:

{
    "java.test.config": {
        "vmargs": [
            "-Dwebdriver.gecko.driver=D:\\work\\Java\\test-runner-bug-proj\\issue-661\\drivers\\geckodriver-windows-64bit.exe", 
            "-Dwebdriver.firefox.logfile=/dev/null"
        ]
    }
}

Open the Setting page and click Edit in settings.json

image

Then paste the setting into there, just notice that the path webdriver.gecko.driver should be different from yours.

Follow-up

I'll keep investigating how to resolve it automatically.

@fabb
Copy link
Author

fabb commented Jun 17, 2019

Thank you a lot for your fast response!

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

3 participants