gpt4 book ai didi

java - Gitlab ci selenium testing with docker not connecting to RemoteWebDriver

转载 作者:行者123 更新时间:2023-11-30 12:03:19 24 4
gpt4 key购买 nike

我想用 gitlab-ci、docker 自动运行 selenium 测试。

在本地一切正常,但似乎 docker 和 selenium 存在一些连接问题。

作业失败

selenium.test.dashboard.MyTest > myFirstTest FAILED
org.openqa.selenium.remote.UnreachableBrowserException
Caused by: java.net.ConnectException
Caused by: java.net.ConnectException
java.lang.NullPointerException

我尝试更改不同的 url 以连接到 selenium 服务器,我认为可能存在端口问题。但我尝试过的每一种组合最终都得到了相同的结果。

.gitlab-ci.yml

image: gradle:alpine

variables:
GRADLE_OPTS: "-Dorg.gradle.daemon=false"

before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle

stages:
- build
- seleniumTesting


build:
stage: build
script:
- echo $CI_JOB_STAGE
- echo $CI_COMMIT_REF_NAME
- gradle --build-cache war
artifacts:
paths:
- public
cache:
key: "$CI_COMMIT_REF_NAME"
policy: push
paths:
- build
- .gradle


seleniumTestingChrome:
stage: seleniumTesting
script: gradle integrationTest
# services:
# - selenium/standalone-chrome:latest
services:
- name: selenium/standalone-chrome:latest
artifacts:
paths:
- build/reports/tests/
cache:
key: "$CI_COMMIT_REF_NAME"
policy: push
paths:
- build
- .gradle

RemoteWebDriver 的 Java 代码

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName(DesiredCapabilities.chrome().getBrowserName());

try {
// driver = new RemoteWebDriver( new URL("http://selenium_standalone-chrome:4444/wd/hub"), capabilities);
WebDriver driver = new RemoteWebDriver( new URL("http://127.0.0.1:4444/wd/hub"), capabilities);

} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

在运行器上创建容器

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
92f018da4cbe 8017d8c2ba74 "sh -c 'if [ -x /usr…" 20 seconds ago Up 19 seconds runner-Y2QWpCBd-project-4-concurrent-0-build-4
9dfdc838a7af 9e599fb82f84 "/opt/bin/entry_poin…" 40 seconds ago Up 38 seconds 4444/tcp runner-Y2QWpCBd-project-4-concurrent-0-selenium__standalone-chrome-0

docker 在 runner 上记录命令

019-08-30 17:06:02,099 INFO Included extra file "/etc/supervisor/conf.d/selenium.conf" during parsing
2019-08-30 17:06:02,101 INFO supervisord started with pid 7
2019-08-30 17:06:03,106 INFO spawned: 'xvfb' with pid 10
2019-08-30 17:06:03,109 INFO spawned: 'selenium-standalone' with pid 11
17:06:03.826 INFO [GridLauncherV3.parse] - Selenium server version: 3.141.59, revision: e82be7d358
2019-08-30 17:06:03,830 INFO success: xvfb entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
2019-08-30 17:06:03,830 INFO success: selenium-standalone entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
17:06:04.065 INFO [GridLauncherV3.lambda$buildLaunchers$3] - Launching a standalone Selenium Server on port 4444
2019-08-30 17:06:04.200:INFO::main: Logging initialized @1058ms to org.seleniumhq.jetty9.util.log.StdErrLog
17:06:04.804 INFO [WebDriverServlet.<init>] - Initialising WebDriverServlet
17:06:05.050 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444

我确实希望测试在 docker 容器中的 gitlab-ci-runner 上运行。连接到 selenium-server 并使用公共(public)可用 url 执行 selenium 测试

最佳答案

正如@Sascha Frinken 所指出的

连接到 RemoteWebDriver 的 URL 错误。我漏掉了一个下划线。

"http://selenium_standalone-chrome:4444/wd/hub "

对比

"http://selenium__standalone-chrome:4444/wd/hub "

关于java - Gitlab ci selenium testing with docker not connecting to RemoteWebDriver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57811949/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com