Java docker未连接到RemoteWebDriver的Gitlab ci selenium测试
我想用gitlab ci docker自动运行selenium测试 在本地,一切正常,但似乎docker和selenium存在一些连接问题 这项工作失败了Java docker未连接到RemoteWebDriver的Gitlab ci selenium测试,java,selenium,gitlab-ci,gitlab-ci-runner,dock,Java,Selenium,Gitlab Ci,Gitlab Ci Runner,Dock,我想用gitlab ci docker自动运行selenium测试 在本地,一切正常,但似乎docker和selenium存在一些连接问题 这项工作失败了 selenium.test.dashboard.MyTest > myFirstTest FAILED org.openqa.selenium.remote.UnreachableBrowserException Caused by: java.net.ConnectException C
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();
}
已在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
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在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
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
019-08-30 17:06:02099解析期间包含额外文件“/etc/supervisor/conf.d/selenium.conf”的信息
2019-08-30 17:06:02101信息主管以pid 7启动
2019-08-30 17:06:03106信息衍生:pid为10的“xvfb”
2019-08-30 17:06:03109信息衍生:“selenium standalone”和pid 11
17:06:03.826信息[GridLauncherV3.parse]-Selenium服务器版本:3.141.59,修订版:e82be7d358
2019-08-30 17:06:03830信息成功:xvfb进入运行状态,进程已保持超过0秒(startsecs)
2019-08-30 17:06:03830信息成功:selenium standalone进入运行状态,进程已停止运行超过0秒(startsecs)
17:06:04.065信息[GridLauncherV3.lambda$buildLaunchers$3]-在端口4444上启动独立的Selenium服务器
2019-08-30 17:06:04.200:INFO::main:Logging initialized@1058ms到org.seleniumhq.jetty9.util.log.StdErrLog
17:06:04.804信息[WebDriverServlet.]-初始化WebDriverServlet
17:06:05.050信息[SeleniumServer.boot]-SeleniumServer已启动并在端口4444上运行
我确实希望测试在docker容器中的gitlab ci runner上运行。连接到selenium服务器并使用@Sascha Frinken指出的公共可用url执行selenium测试 连接到RemoteWebDriver的URL错误。我漏掉了一个下划线 “” VS
“”我认为访问selenium服务器的主机名应该是
selenium\uu standalone-chrome
或selenium standalone-chrome
请参见,我似乎忘记了第二个下划线。。。现在它工作了!希望这个例子将来能帮助别人!