vscode-java-test
vscode-java-test copied to clipboard
org.openqa.selenium.WebDriverException: Driver isn't initialized. This extension can only be used in combination with the DriverParameterResolver
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?
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
@fabb you trying run 'gradle test' or something else ? if also getting error, then error caused not by java test runner
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.
@fabb Thank you for the information, I'll take a look and update you when I have any progress.
Hi @fabb
Is that possible for you to share a sample project which can repro the issue?
I‘ll try to reproduce it in an example project, could take me a while as I‘m swamped currently.
That will be great. Thanks a lot
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.
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.
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

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.
Thank you a lot for your fast response!