[英]Gitlab ci selenium testing with docker not connecting to RemoteWebDriver
I want to run automatically selenium tests with gitlab-ci, docker.我想用 gitlab-ci、docker 自动运行 selenium 测试。
Locally everything works fine, but it seems like, there are some connection issues with docker and selenium.在本地一切正常,但似乎 docker 和 selenium 存在一些连接问题。
The job is failing with工作失败
selenium.test.dashboard.MyTest > myFirstTest FAILED
org.openqa.selenium.remote.UnreachableBrowserException
Caused by: java.net.ConnectException
Caused by: java.net.ConnectException
java.lang.NullPointerException
I tried to change different url's to connect to selenium server and I thought there is maybe a port issue.我尝试更改不同的 url 以连接到 selenium 服务器,我认为可能存在端口问题。 But every combination which I tried ended up with the same result.
但是我尝试过的每种组合都得到了相同的结果。
.gitlab-ci.yml .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
Java code for RemoteWebDriver 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();
}
created container on runner在 runner 上创建容器
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 logs command on runner 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
I do expect that the test is running on the gitlab-ci-runner in a docker container.我确实希望测试在 docker 容器中的 gitlab-ci-runner 上运行。 Connects to the selenium-server and executes the selenium test with a public available url
连接到 selenium-server 并使用公共可用的 url 执行 selenium 测试
As pointed out by @Sascha Frinken 正如@Sascha Frinken所指出的
The URL to connect to the RemoteWebDriver was wrong. 连接到RemoteWebDriver的URL错误。 I missed one underscore.
我错过了一个下划线。
" http://selenium_standalone-chrome:4444/wd/hub " “ http:// selenium_standalone-chrome:4444 / wd / hub ”
VS VS
" http://selenium__standalone-chrome:4444/wd/hub " “ http:// selenium__standalone-chrome:4444 / wd / hub ”
there is topic in gitlab https://docs.gitlab.com/ee/ci/services/#accessing-the-services , which states gitlab https://docs.gitlab.com/ee/ci/services/#accessing-the-services 中有一个主题,其中指出
Everything after the colon (:) is stripped.
Slash (/) is replaced with double underscores (__) and the primary alias is created.
Slash (/) is replaced with a single dash (-) and the secondary alias is created (requires GitLab Runner v1.1.0 or higher).
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.