无法在 Testcontainers 中使用 Chrome 驱动程序使用 Selenium 打开任何 URL

菲尔特

我正在尝试在 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 文件中没有特殊设置

如果我理解我看到的所有例子,这应该是:

  1. 通过 testcontainers 在 docker 容器内打开测试。
  2. 在该容器内为 Chrome 创建驱动程序。
  3. 导航到给定的网站(在上面的示例中,google.com)
  4. 通过,因为 true = true

但是,无论我在代码方面如何更改,我都会遇到以下错误:

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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Selenium在OSX High Sierra上无法使用Chrome驱动程序

无法使用Selenium Web驱动程序2.33和Firefox 22打开网页

无法使用Selenium Web驱动程序以InPrivate模式打开Edge

无法使用Selenium Web驱动程序上传文件

在python 3中使用Selenium Chrome驱动程序将文本插入文本框

即使使用Webdriver-manager更新了驱动程序,由于版本问题,Chrome浏览器仍无法打开

无法在 @Test Junit Selenium Web 驱动程序中使用定位器

无法在python中使用Selenium Web驱动程序获取文本

无法使用Firefox驱动程序打开网站

在C#中使用Selenium Web驱动程序,FirefoxWebDriver Navagate()。GoTo(URL)失败

Selenium Webdriver和Chrome驱动程序-无法运行Chrome驱动程序

Aws Lambda Ruby Crawler selenium chrome 驱动程序:“未知错误:无法在 chrome 中发现打开的窗口”

Selenium Chrome驱动程序无法选择或输入登录

如何在前台打开Chrome驱动程序(使用Selenium Webdriver)。默认情况下,它在没有焦点的背景下打开

无法在由硒铬驱动程序控制的Chrome窗口中的Chrome Dev工具中使用控制台

Chrome无法使用Selenium Python打开配置文件

在切换情况下,无法使用Selenium Web驱动程序在其他浏览器中运行URL

如何找到使用Selenium Web驱动程序(用于Chrome)从PHP下载的文件的路径和名称?

Selenium Chrome驱动程序和Travis CI不能一起使用

使用Selenium Chrome驱动程序自动“另存为PDF”时缺少元素

如何通过单击使用 selenium chrome 驱动程序下载 PDF

Selenium(Python)-等待使用Chrome Web驱动程序完成下载过程

如何查找Selenium网格上的节点正在使用的Chrome驱动程序版本

将 Chrome 驱动程序与 Selenium Webdriver 一起使用时出现 SocketException

如何使用Selenium和Chrome驱动程序在.net中的隐藏字段中键入文本

为什么我不能使用Selenium Chrome驱动程序

如何使用 selenium、chrome 驱动程序和 python 关闭新建的选项卡

使用带有Chrome驱动程序的Selenium Python拍摄整个网页的屏幕截图

Nightwatch.js 使用 Chrome 驱动程序、Selenium 进行日志配置