Search code examples
dockernginx-reverse-proxyvncselenoid

VNC is Getting disconnected in Selenoid


I am using Selenoid for automation. I am able to run the tests on Selenoid, However, when I click on the running browser sessions, I am not able to see the live execution. ie. the VNC is getting disconnected. Happens with manual sessions as well.

Please refer screenshot with the console output :

Screenshot of Browser

Setup:

Using Nginx to access Selenoid in a remote machine (CentOS). Port 8081 hosts selenoid and port 8080 hosts selenoid-ui. And the browser image is selenoid/vnc_firefox:86.0.

Docker setup

This is how I have started the containers

docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v ${HOME}:/root -e OVERRIDE_HOME=${HOME} aerokube/cm:latest-release selenoid start --port 8081 --vnc
docker run -it --rm -d --name selenoid-ui --link selenoid --network selenoid -p 8080:8080 aerokube/selenoid-ui:latest --selenoid-uri http://examplefqdn.com:8081
docker run --name nginx6 -d -v /etc/ssl_temp:/etc/ssl_temp -p 80:80 -p 443:443 -p 8443:8443 nginx

Below is what I have tried with my Nginx.conf.

server {
  listen 80;
  listen 443 ssl;
  listen 8443 ssl;
  proxy_set_header Host $host;
  proxy_set_header X-Forwarded-For $remote_addr;
  server_name example.com;
  ssl_certificate /etc/ssl_temp/selenoid.pem;
  ssl_certificate_key /etc/ssl_temp/example.com.key;
  location /  {
   proxy_pass http://example.com:8080;
   proxy_connect_timeout      70;
   proxy_read_timeout 86400s;
   proxy_send_timeout 86400s;
   }
   location /browser {
   proxy_pass http://example.com:8081;
   proxy_connect_timeout      70;
   proxy_read_timeout 86400s;
   proxy_send_timeout 86400s;
   }
   location /ws {
   proxy_pass http://example.com:5900;
   proxy_http_version 1.1;

   proxy_set_header Connection 'upgrade';
   chunked_transfer_encoding off;

   proxy_set_header Upgrade $http_upgrade;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   proxy_set_header Host $host;

   proxy_buffering off;
   proxy_cache off;

   proxy_connect_timeout 600;
   proxy_read_timeout 86400s;
   proxy_send_timeout 86400s;
   }
} 

Below is my capabilities config:

DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setBrowserName("firefox");
        capabilities.setVersion("76 .0");
        capabilities.setCapability("enableVNC", true);
        capabilities.setCapability("enableVideo", true);
        capabilities.setCapability("enableLog", true);
        capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

        RemoteWebDriver driver = new RemoteWebDriver(
                URI.create("https://example.com/wd/hub").toURL(), capabilities);

Following is my browsers.json

{
        "chrome": {
                "default": "86.0",
                "versions": {
                        "86.0": {
                                "image": "selenoid/vnc:chrome_86.0",
                                "port": "4444",
                                "path": "/",
                                "volumes": ["/etc/ssl_temp:/etc/ssl_temp"]
                        }
                }
        },
        "firefox": {
                "default": "60.0",
                "versions": {
                        "60.0": {
                                "image": "selenoid/vnc:firefox_60.0",
                                "port": "4444",
                                "path": "/wd/hub",
                                "volumes": ["/etc/ssl_temp:/etc/ssl_temp"]
                        },
                        "65.0": {
                                "image": "selenoid/vnc:firefox_65.0",
                                "port": "4444",
                                "path": "/wd/hub",
                                "volumes": ["/etc/ssl_temp:/etc/ssl_temp"]
                        },
                        "86.0": {
                                "image": "selenoid/vnc_firefox:86.0",
                                "port": "4444",
                                "path": "/wd/hub",
                                "volumes": ["/etc/ssl_temp:/etc/ssl_temp"]
                        }
                }
        }
}

Any help is much appreciated. Thanks in advance.


Solution

  • location /ws { proxy_pass example.com:5900;

    This should also go to port 8080.