Issue
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)
Solution
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.
Answered By - Sam Brannen
Answer Checked By - Terry (JavaFixing Volunteer)