我可以在没有任何特殊测试框架的情况下编写和执行 Selenium 脚本,但我想使用 Junit 5(因为我们依赖于其他工具)并且org.junit.jupiter.api.extension.ParameterResolutionException
在使用 Junit 4 时我从未见过这样的错误。
目前它是 Junit 5,我用谷歌搜索它以获得某种想法,但无法解决问题。
JUnit 5
使用,Eclipse 4.8
和测试脚本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();
}
}
堆栈跟踪:
org.junit.jupiter.api.extension.ParameterResolutionException:没有为可执行文件 [public login.loginTest(org.openqa.selenium.WebDriver)] 中的参数 [org.openqa.selenium.WebDriver arg0] 注册的 ParameterResolver。在 org.junit.jupiter.engine.execution.ExecutableInvoker.resolveParameter(ExecutableInvoker.java:191)