[英]unable to run selenium test cases on docker container
I have set up a Selenium grid and selenium chrome node as docker continers and also created an container for my test suite. 我已经将Selenium网格和Selenium chrome节点设置为docker容器,还为我的测试套件创建了一个容器。 But once i try to run the test cases it is failing providing the below error message 但是一旦我尝试运行测试用例,它将无法提供以下错误消息
org.openqa.selenium.remote.UnreachableBrowserException:
Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '3.141.5', revision: 'd54ebd709a', time: '2018-11-06T11:42:16'
System info: host: '267891a44849', ip: '172.17.0.3', os.name: 'Linux', os.arch: 'amd64', os.version: '4.9.184-linuxkit', java.version: '11.0.4'
Driver info: driver.version: RemoteWebDriver
Caused by: java.net.ConnectException: Failed to connect to localhost/127.0.0.1:4444
Caused by: java.net.ConnectException: Connection refused (Connection refused)
created an docker image for my automation code through docker file 通过docker文件为我的自动化代码创建了docker映像
created an docker network 创建了一个码头网络
created an hub on docker using selenium grid 使用硒网格在Docker上创建了一个中心
linked node to this hub 链接到该集线器的节点
and tried to run the code 并尝试运行代码
My Dockerfile to create image for automation code 我的Dockerfile为自动化代码创建映像
FROM node AS chrome
USER root
WORKDIR /home/app
RUN apt-get install unzip && \
wget https://chromedriver.storage.googleapis.com/77.0.3865.40/chromedriver_linux64.zip && \
unzip chromedriver_linux64.zip && \
chmod +x /home/app/chromedriver
FROM maven:3.6.2-jdk-11-slim
COPY src /home/app/src
COPY pom.xml /home/app
COPY Dockerfile /home/app
WORKDIR /home/app
COPY --from=chrome /home/app/chromedriver /home/app
RUN chmod u+x chromedriver
ENTRYPOINT mvn clean test
Also I can see docker hub and node up for selenium 我也可以看到docker hub和硒节点
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e95780aac878 selenium/node-chrome "/opt/bin/entry_poin…" 29 hours ago Up 29 hours selenium-node
7e23e59006fb selenium/hub "/opt/bin/entry_poin…" 29 hours ago Up 29 hours 0.0.0.0:4446->4444/tcp selenium-hub
And my SetUp.java contians code as below 和我的SetUp.java contians代码如下
String nodeURL= "http://localhost:4446/wd/hub";
ChromeOptions remoteOptions = new ChromeOptions();
driver=new RemoteWebDriver(new URL(nodeURL), remoteOptions);
but on executing 但是执行
$ docker run --rm -e SELENIUM_HUB=selenium-node --network grid <my automaiotn code image>
I am getting below error 我低于错误
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running Parallel01IT
inside after
Failed scenarios:
/home/app/src/test/java/features/NonRes.feature:49
1 Scenarios (1 failed)
3 Steps (1 failed, 2 skipped)
2m0.810s
org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:26:55.152Z'
System info: host: '61da76b392d3', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '4.9.184-linuxkit', java.version: '1.8.0_212'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:566)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:209)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:132)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:145)
org.openqa.selenium.remote.UnreachableBrowserException:
Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:26:55.152Z'
System info: host: '61da76b392d3', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '4.9.184-linuxkit', java.version: '1.8.0_212'
Driver info: driver.version: RemoteWebDriver
Caused by: java.net.SocketTimeoutException: connect timed out
But When I run the same test cases from my local [my laptop] on those docker selenium grid containers it is working fine However running the same test case as a docker container is failing. 但是,当我在那些docker硒网格容器上从本地[我的笔记本电脑]运行相同的测试用例时, 它工作正常,但是,与docker容器运行相同的测试用例失败。
Run the chromedriver
with a headless
option. 使用headless
选项运行chromedriver
。 I have faced the same problem before and this resolved it. 我之前也遇到过同样的问题,这已经解决了。
chrome_options.add_argument("--headless")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.