Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium refuse to connect if tested application run on port other than 80

Tags:

selenium

I am using selenium server. Its working well to test an application running on port 80.

but if I test an application running on another port than 80, e.g. 5001, the connection is refused.

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities;        
br = webdriver.Remote(command_executor="http://localhost:4444/wd/hub", desired_capabilities=DesiredCapabilities.CHROME)
br.get("http://127.0.0.1:5001/login/")
br.get_screenshot_as_file("/tmp/test.png")

I get the following screenshot: enter image description here

How can I test on port 5001 ?

EDIT

I am running Selenium server as a Docker container with docker-compose:

version: '2'

services:
  selenium:
    image: selenium/standalone-chrome:latest
    ports:
      - 4444:4444
like image 337
Gilles Cuyaubere Avatar asked Jul 05 '18 15:07

Gilles Cuyaubere


People also ask

How can we change default port of selenium hub to a different port?

The Hub will listen to port 4444 by default. You can view the status of the hub by opening a browser window and navigating to http://localhost:4444/grid/console. To change the default port, you can add the optional -port flag with an integer representing the port to listen to when you run the command.

What is the default port ID in selenium?

Step 3: Start Nodes To start nodes open the command prompt and navigate to the directory, where the Selenium Server Standalone jar file is stored. When -role option that is provided is not specified, and it is not the hub, the default port is 5555.

Is selenium 4 backward compatible?

Selenium 4 is fully backward compatible with existing Selenium versions - you can migrate without compromising on the stability of your existing test cases.


1 Answers

You are running Selenium inside a Docker container. If you try to connect to localhost, that points to the Docker container itself.

You have to connect to your host like it is described here: How to access host port from docker container

Use your internal IP address or connect to the special DNS name host.docker.internal which will resolve to the internal IP address used by the host.

like image 71
Jens Dibbern Avatar answered Oct 22 '22 16:10

Jens Dibbern