I am going to deploy my website on a server with the use of Docker. My components are:
.Net Core Api
Chrome Driver
Selenium Hub
With the usage of docker-compose I created my container but it could not be run because of this error:
crit: Microsoft.AspNetCore.Hosting.Diagnostics[6]
Application startup exception
OpenQA.Selenium.WebDriverException: An unknown exception was encountered sending an HTTP request to the remote WebDriver server for URL http://localhost:4444/wd/hub/session. The exception message was: Cannot assign requested address (localhost:4444)
This is the docker-compose file:
version: "3"
services:
selenium-hub:
image: selenium/hub
container_name: selenium-hub
ports:
- "4444:4444"
chrome:
image: selenium/standalone-chrome
volumes:
- /dev/shm:/dev/shm
depends_on:
- selenium-hub
environment:
- HUB_HOST=selenium-hub
- HUB_PORT=4444
web:
build: .
ports:
- "8090:80"
And this a piece of code in my project in which I instantiate the driver:
ChromeOptions options = new ChromeOptions();
options.AddArgument("no-sandbox");
options.AddArgument("headless");
driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), options);
In my opinion the problem stem from Uri setting because the container successfully created and selenium-hub is running.
selenium-hub | 08:31:29.415 INFO [Hub.execute] - Started Selenium Hub 4.3.0 (revision a4995e2c09*): http://192.168.80.3:4444