我正在尝试在 Testcontainers 内的 JUnit 测试中使用 Selenium 在一个项目上设置 UI 测试框架,使用 IntelliJ IDE 进行开发。我正在使用 OpenJDK 12.0.1
我有我能想到的最基本的测试,但是在尝试获取任何网站(维基百科、谷歌等)时,我不断收到空指针异常
我在这里遗漏了一些重要的东西吗?
这是我设置的测试:
public class SimpleTest {
@Rule
public BrowserWebDriverContainer chrome = new BrowserWebDriverContainer()
.withCapabilities(new ChromeOptions());
@Test
public void simplePlainSeleniumTest() {
RemoteWebDriver driver = chrome.getWebDriver();
driver.get("https://google.com");
assertTrue("This should always pass", true);
}
}
在我的 gradle 文件中,我正在导入以下内容:
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.141.59'
compile group: 'org.seleniumhq.selenium', name: 'selenium-remote-driver', version: '3.141.59'
testCompile group: 'org.testcontainers', name: 'selenium', version: '1.11.3'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.2.0'
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.2.0'
test {
useJUnitPlatform()
}
我的 testcontainers.properties 文件中没有特殊设置
如果我理解我看到的所有例子,这应该是:
但是,无论我在代码方面如何更改,我都会遇到以下错误:
selenium.SimpleTest > simplePlainSeleniumTest() FAILED
java.lang.NullPointerException at SimpleTest.java:34
第 34 行是: driver.get("https://google.com");
您正在使用不支持规则的 JUnit Jupiter。Testcontainers 中有单独的 Jupiter 支持,请参见以下页面:https ://www.testcontainers.org/test_framework_integration/junit_5/
基本上,你需要添加org.testcontainers:junit-jupiter:1.11.3
依赖,注释您的测试类@Testcontainers
和替换@Rule
用@Container
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句