Junit 5 - No ParameterResolver registered for parameter
JavaSelenium WebdriverJunit5Junit JupiterSelenium JupiterJava Problem Overview
I can write up and execute Selenium script without any special test framework but I wanted to use Junit 5 (because we have dependency with other tools) and I have never seen such error org.junit.jupiter.api.extension.ParameterResolutionException
while working with Junit 4.
Currently it's Junit 5 and I googled it to get some sort of idea but can not resolve the issue.
Test script using JUnit 5
, Eclipse 4.8
and Selenium
:
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class loginTest {
public WebDriver driver = null;
public loginTest(WebDriver driver) {
this.driver=driver;
}
@BeforeEach
public void setUp() throws Exception {
driver.get("google.com");
System.out.println("Page title is: " + driver.getTitle());
}
@Test
public void test() {
// some action here I have in original script
System.out.println("Page title is: " + driver.getTitle());
}
@AfterEach
public void tearDown() throws Exception {
driver.quit();
}
}
Stack trace:
> org.junit.jupiter.api.extension.ParameterResolutionException: No ParameterResolver registered for parameter [org.openqa.selenium.WebDriver arg0] in executable [public login.loginTest(org.openqa.selenium.WebDriver)]. at org.junit.jupiter.engine.execution.ExecutableInvoker.resolveParameter(ExecutableInvoker.java:191)
Java Solutions
Solution 1 - Java
I had both @Test
and @ParameterizedTest
annotating the same method. I removed the former.
Solution 2 - Java
This error appears when you try to use both @Test
and @ParameterizedTest
in the same test class. Removing @Test
annotation will resolve the issue.
Solution 3 - Java
As Marc Philipp mentioned in his comment, you need to ensure that JUnit Jupiter can instantiate your test class.
For your particular scenario, you'll need to remove your custom constructor that accepts a WebDriver
.
Then you have two options:
- Create the
WebDriver
on your own -- for example, in an@BeforeAll
or@BeforeEach
method. - Use an extension such as Selenium Jupiter to help manage the
WebDriver
for you.
Solution 4 - Java
I also got ParameterResolutionException
with JUnit 5.
org.junit.jupiter.api.extension.ParameterResolutionException:
No ParameterResolver registered for parameter [int[] arg0] in constructor (public my_package.MyClass(int[]))
I had written @Test
methods inside the class I was testing.
This error could be fixed in two ways:
-
Either replacing
import org.junit.jupiter.api.Test
withimport org.junit.Test
, or -
Writing tests in a separate TestClass.
Solution 5 - Java
I had the similar issue I resolved it by removing the @Test
annotation
and introduce annotation @ParameterizedTest
Solution 6 - Java
I got this error because my test needed my Spring Boot server to be running first, so that dependency injection using @Autowired would get executed. I added these annotations:
@Transactional
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Server.class)
public MyTestClass () {
...
}
Solution 7 - Java
For me, I was using
@ParameterizedTest
@CsvSource({
"1st-param1","1st-param2",
"2nd-param1","2nd-param2"
})
public void isCompleted(String param1, String param2) {
Instead of (quotes were wrong):
@ParameterizedTest
@CsvSource({
"1st-param1,1st-param2",
"2nd-param1,2nd-param2"
})
public void isCompleted(String param1, String param2) {
Solution 8 - Java
Annotating test class with @ExtendWith(MockitoExtension.class) worked for me
Solution 9 - Java
In my situation I had 2 parameters. The first parameter was using @AggregateWith, the second parameter should not have been aggregated and was already of the correct type, but JUnit tried to aggregate it as well.
Switching parameter 0 and 1 solved the issue for me (that is, the parameter annotated with @AggregateWith is now at the end).
Solution 10 - Java
I had similar issue as my dependencies where using both junit4 & junit5. I made @Tests
to use from junit4 i.e, import org.junit.Test
. This fixed the cause.
Solution 11 - Java
I think the WebDriver class in your project is not Annotated as a bean and it cannot be injected, i had the same problem and when i changed the injection way from constructor injection into instance variable injection, it throws NoSuchBeanDefinitionException ("No qualifying bean of type '...service.RsRepositoryService' available: "), it does not find the bean that we are trying to inject. Hope this helps someone with this problem :)