Connect to Selenium within Docker-container

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Connect to Selenium within Docker-container

Flaz Fourteen
Hi,

That question has been asked on StackOverflow: Connect to Selenium within Docker-container. It's still unanswered (may be it's quite specific...). So let me copy-and-paste the question here:

--------------

I'm developing tests with Selenium. Currently I'm using official selenium/standalone-chrome:3.11.0 image. I'm running only Selenium inside Docker-container. The project itself is compiled on the host machine (tests connect to the container's exposed port):


$ docker run -p 4444:4444 selenium/standalone-chrome:3.11.0

$ curl -v localhost:4444
* Rebuilt URL to: localhost:4444/
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 4444 (#0)
> GET / HTTP/1.1
> Host: localhost:4444
> User-Agent: curl/7.47.0
> Accept: */*
> 
< HTTP/1.1 200 OK
...


But I would like to compile and test the project entirely inside Docker-container. So I created my own image upon selenium/standalone-chrome:3.11.0. My (simplified) Dockerfile looks like this:


FROM selenium/standalone-chrome:3.11.0 RUN sudo apt-get --assume-yes --quiet update RUN sudo apt-get --assume-yes --quiet install curl CMD ["curl", "-v", "localhost:4444"]


As can be seen from the file, I'm trying to connect to port 4444 within container. When I run the image, e.g.:


docker build -t test . && docker run test


I get:


* Rebuilt URL to: localhost:4444/ % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 127.0.0.1... * connect to 127.0.0.1 port 4444 failed: Connection refused * Trying ::1... * Immediate connect fail for ::1: Cannot assign requested address * Trying ::1... * Immediate connect fail for ::1: Cannot assign requested address * Failed to connect to localhost port 4444: Connection refused * Closing connection 0 curl: (7) Failed to connect to localhost port 4444: Connection refused


Why I'm not able to connect to Selenium which is ran inside container from the same container?


--------------

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/8656e43a-95a7-4489-9109-60dd20175969%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Connect to Selenium within Docker-container

Flaz Fourteen

Hi,


I've resolved the issue and posted the answer on StackOverflow. Below is the copy of it.

This topic can be closed :)


------------------------------------


I've found the solution at last (sorry for my stupidity).


Building an image upon selenium/standalone-chrome:3.11.0 is not sufficient. You need to start Selenium (which is located under /opt/selenium) explicitly.


The Dockerfile:


FROM selenium/standalone-chrome:3.11.0

WORKDIR /app

COPY . /app

RUN sudo apt-get --assume-yes --quiet update
RUN sudo apt-get --assume-yes --quiet install curl

CMD ["./acceptance.sh"] 

The acceptance.sh wrapper script:


#!/bin/bash

set -x
set -e

java -jar /opt/selenium/selenium-server-standalone.jar &
sleep 30
curl -v localhost:4444
 

The result:


...
+ set -e
+ sleep 30
+ java -jar /opt/selenium/selenium-server-standalone.jar
15:52:22.157 INFO [GridLauncherV3.launch] - Selenium build info: version: '3.11.0', revision: 'e59cfb3'
15:52:22.165 INFO [GridLauncherV3$1.launch] - Launching a standalone Selenium Server on port 4444
2018-05-13 15:52:22.809:INFO::main: Logging initialized @2474ms to org.seleniumhq.jetty9.util.log.StdErrLog
15:52:23.676 INFO [SeleniumServer.boot] - Welcome to Selenium for Workgroups....
15:52:23.677 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444
+ curl -v localhost:4444
* Rebuilt URL to: localhost:4444/
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 4444 (#0)
> GET / HTTP/1.1
> Host: localhost:4444
> User-Agent: curl/7.47.0
> Accept: */*
> 
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0< HTTP/1.1 200 OK
...
 

Cheers!


------------------------------------



On Friday, May 11, 2018 at 1:32:14 PM UTC+3, Flaz Fourteen wrote:
Hi,

That question has been asked on StackOverflow: <a href="https://stackoverflow.com/questions/50268215/connect-to-selenium-within-docker-container" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fstackoverflow.com%2Fquestions%2F50268215%2Fconnect-to-selenium-within-docker-container\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFRClIOz1oni9XYT3FqQdRsukBfjg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fstackoverflow.com%2Fquestions%2F50268215%2Fconnect-to-selenium-within-docker-container\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFRClIOz1oni9XYT3FqQdRsukBfjg&#39;;return true;">Connect to Selenium within Docker-container. It's still unanswered (may be it's quite specific...). So let me copy-and-paste the question here:

--------------

I'm developing tests with Selenium. Currently I'm using official <a href="https://hub.docker.com/r/selenium/standalone-chrome/tags/" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fhub.docker.com%2Fr%2Fselenium%2Fstandalone-chrome%2Ftags%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNE-5T8gNlYm98U7dRzAtpV5RpSqjA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fhub.docker.com%2Fr%2Fselenium%2Fstandalone-chrome%2Ftags%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNE-5T8gNlYm98U7dRzAtpV5RpSqjA&#39;;return true;">selenium/standalone-chrome:3.11.0 image. I'm running only Selenium inside Docker-container. The project itself is compiled on the host machine (tests connect to the container's exposed port):


$ docker run -p 4444:4444 selenium/standalone-chrome:3.11.0

$ curl -v localhost:4444
* Rebuilt URL to: localhost:4444/
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 4444 (#0)
> GET / HTTP/1.1
> Host: localhost:4444
> User-Agent: curl/7.47.0
> Accept: */*
> 
< HTTP/1.1 200 OK
...


But I would like to compile and test the project entirely inside Docker-container. So I created my own image upon selenium/standalone-chrome:3.11.0. My (simplified) Dockerfile looks like this:


FROM selenium/standalone-chrome:3.11.0 RUN sudo apt-get --assume-yes --quiet update RUN sudo apt-get --assume-yes --quiet install curl CMD ["curl", "-v", "localhost:4444"]


As can be seen from the file, I'm trying to connect to port 4444 within container. When I run the image, e.g.:


docker build -t test . && docker run test


I get:


* Rebuilt URL to: localhost:4444/ % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 127.0.0.1... * connect to 127.0.0.1 port 4444 failed: Connection refused * Trying ::1... * Immediate connect fail for ::1: Cannot assign requested address * Trying ::1... * Immediate connect fail for ::1: Cannot assign requested address * Failed to connect to localhost port 4444: Connection refused * Closing connection 0 curl: (7) Failed to connect to localhost port 4444: Connection refused


Why I'm not able to connect to Selenium which is ran inside container from the same container?


--------------

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/d98f55a1-1cc7-4fb5-ba93-a9a809aac754%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Connect to Selenium within Docker-container

Mohanraj K
Is there any method to find x and y podition of selenium??

On Sun, May 13, 2018, 9:30 PM Flaz Fourteen <[hidden email]> wrote:

Hi,


I've resolved the issue and posted the answer on StackOverflow. Below is the copy of it.

This topic can be closed :)


------------------------------------


I've found the solution at last (sorry for my stupidity).


Building an image upon selenium/standalone-chrome:3.11.0 is not sufficient. You need to start Selenium (which is located under /opt/selenium) explicitly.


The Dockerfile:


FROM selenium/standalone-chrome:3.11.0

WORKDIR /app

COPY . /app

RUN sudo apt-get --assume-yes --quiet update
RUN sudo apt-get --assume-yes --quiet install curl

CMD ["./acceptance.sh"] 

The acceptance.sh wrapper script:


#!/bin/bash

set -x
set -e

java -jar /opt/selenium/selenium-server-standalone.jar &
sleep 30
curl -v localhost:4444
 

The result:


...
+ set -e
+ sleep 30
+ java -jar /opt/selenium/selenium-server-standalone.jar
15:52:22.157 INFO [GridLauncherV3.launch] - Selenium build info: version: '3.11.0', revision: 'e59cfb3'
15:52:22.165 INFO [GridLauncherV3$1.launch] - Launching a standalone Selenium Server on port 4444
2018-05-13 15:52:22.809:INFO::main: Logging initialized @2474ms to org.seleniumhq.jetty9.util.log.StdErrLog
15:52:23.676 INFO [SeleniumServer.boot] - Welcome to Selenium for Workgroups....
15:52:23.677 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444
+ curl -v localhost:4444
* Rebuilt URL to: localhost:4444/
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 4444 (#0)
> GET / HTTP/1.1
> Host: localhost:4444
> User-Agent: curl/7.47.0
> Accept: */*
> 
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0< HTTP/1.1 200 OK
...
 

Cheers!


------------------------------------



On Friday, May 11, 2018 at 1:32:14 PM UTC+3, Flaz Fourteen wrote:
Hi,

That question has been asked on StackOverflow: Connect to Selenium within Docker-container. It's still unanswered (may be it's quite specific...). So let me copy-and-paste the question here:

--------------

I'm developing tests with Selenium. Currently I'm using official selenium/standalone-chrome:3.11.0 image. I'm running only Selenium inside Docker-container. The project itself is compiled on the host machine (tests connect to the container's exposed port):


$ docker run -p 4444:4444 selenium/standalone-chrome:3.11.0

$ curl -v localhost:4444
* Rebuilt URL to: localhost:4444/
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 4444 (#0)
> GET / HTTP/1.1
> Host: localhost:4444
> User-Agent: curl/7.47.0
> Accept: */*
> 
< HTTP/1.1 200 OK
...


But I would like to compile and test the project entirely inside Docker-container. So I created my own image upon selenium/standalone-chrome:3.11.0. My (simplified) Dockerfile looks like this:


FROM selenium/standalone-chrome:3.11.0 RUN sudo apt-get --assume-yes --quiet update RUN sudo apt-get --assume-yes --quiet install curl CMD ["curl", "-v", "localhost:4444"]


As can be seen from the file, I'm trying to connect to port 4444 within container. When I run the image, e.g.:


docker build -t test . && docker run test


I get:


* Rebuilt URL to: localhost:4444/ % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 127.0.0.1... * connect to 127.0.0.1 port 4444 failed: Connection refused * Trying ::1... * Immediate connect fail for ::1: Cannot assign requested address * Trying ::1... * Immediate connect fail for ::1: Cannot assign requested address * Failed to connect to localhost port 4444: Connection refused * Closing connection 0 curl: (7) Failed to connect to localhost port 4444: Connection refused


Why I'm not able to connect to Selenium which is ran inside container from the same container?


--------------

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/d98f55a1-1cc7-4fb5-ba93-a9a809aac754%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


----
Disclaimer:
This email and any attachments to it may be confidential and are intended solely for the use of the individual to whom it is addressed.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CA%2BqnjqFRUWffNhXJdtRbUSLfzq7DptepDU9e6ocH09cQohYxEg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.