可以连接到在容器上运行的App Service上的Selenium/Selenium/Selenium/standalone-Chrome docker容器
我已经在本地测试了一个docker,其中我拥有硒/独立的奇异容器和一个具有自动化UI测试的dotnet核心。使用Docker组成文件中的主机名设置,我可以成功地连接并运行自动测试。
现在,我正在尝试将它们部署到容器的Azure Web应用程序中,但是Dotnet Core应用程序正在提出一个错误,说它无法连接到其他容器:
2022-04-29T19:22:26.175504823Z Unhandled exception. OpenQA.Selenium.WebDriverException: An unknown exception was encountered sending an HTTP request to the remote WebDriver server for URL http://chrome:4444/wd/hub/session. The exception message was: Name or service not known
2022-04-29T19:22:26.175552225Z ---> System.Net.Http.HttpRequestException: Name or service not known
2022-04-29T19:22:26.175558125Z ---> System.Net.Sockets.SocketException (0xFFFDFFFF): Name or service not known
2022-04-29T19:22:26.175562626Z at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
2022-04-29T19:22:26.175566926Z --- End of inner exception stack trace ---
2022-04-29T19:22:26.175571026Z at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
2022-04-29T19:22:26.175575226Z at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean allowHttp2, CancellationToken cancellationToken)
2022-04-29T19:22:26.175579526Z at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
2022-04-29T19:22:26.175583826Z at System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
2022-04-29T19:22:26.175588027Z at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
2022-04-29T19:22:26.175592327Z at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
2022-04-29T19:22:26.175596627Z at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
2022-04-29T19:22:26.175601027Z at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)
2022-04-29T19:22:26.175605227Z at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
2022-04-29T19:22:26.175615128Z --- End of inner exception stack trace ---
2022-04-29T19:22:26.175619328Z at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
2022-04-29T19:22:26.175623528Z at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
2022-04-29T19:22:26.175639629Z at OpenQA.Selenium.WebDriver.StartSession(ICapabilities desiredCapabilities)
2022-04-29T19:22:26.175643929Z at OpenQA.Selenium.WebDriver..ctor(ICommandExecutor executor, ICapabilities capabilities)
2022-04-29T19:22:26.175648529Z at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
2022-04-29T19:22:26.175652229Z at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(Uri remoteAddress, ICapabilities desiredCapabilities, TimeSpan commandTimeout)
2022-04-29T19:22:26.175656029Z at SparefootScrape.Program.StartDriver() in /src/Program.cs:line 99
2022-04-29T19:22:26.175659630Z at SparefootScrape.Program.Main(String[] args) in /src/Program.cs:line 39
2022-04-29T19:22:26.176521765Z at SparefootScrape.Program.<Main>(String[] args)
我还尝试了Localhost,而不是使用我使用的“ Chrome”值docker撰写文件中的主机名,但也无效。
有技巧吗?
这是我的Docker-Compose:
version: "1.0"
services:
scrape:
image: "xxxxxx.azurecr.io/yyyyy:4.0"
stdin_open: true # docker run -i
tty: true # docker run -t
shm_size: '2gb'
restart: always
depends_on:
- chrome
selenium:
image: "selenium/standalone-chrome:latest"
container_name: "chrome"
hostname: chrome
shm_size: '2gb'
restart: always
ports:
- "4444:4444"
I've tested a docker compose locally where I have a selenium/standalone-chrome container and a dotnet core one with automated UI tests implemented. Using hostname setting in the docker compose file, I can proper connect and run the automated tests with success.
Now I'm trying to deploy them to Azure Web App for Container, but the dotnet core application is raising an error saying it could not connect to the other container:
2022-04-29T19:22:26.175504823Z Unhandled exception. OpenQA.Selenium.WebDriverException: An unknown exception was encountered sending an HTTP request to the remote WebDriver server for URL http://chrome:4444/wd/hub/session. The exception message was: Name or service not known
2022-04-29T19:22:26.175552225Z ---> System.Net.Http.HttpRequestException: Name or service not known
2022-04-29T19:22:26.175558125Z ---> System.Net.Sockets.SocketException (0xFFFDFFFF): Name or service not known
2022-04-29T19:22:26.175562626Z at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
2022-04-29T19:22:26.175566926Z --- End of inner exception stack trace ---
2022-04-29T19:22:26.175571026Z at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
2022-04-29T19:22:26.175575226Z at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean allowHttp2, CancellationToken cancellationToken)
2022-04-29T19:22:26.175579526Z at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
2022-04-29T19:22:26.175583826Z at System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
2022-04-29T19:22:26.175588027Z at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
2022-04-29T19:22:26.175592327Z at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
2022-04-29T19:22:26.175596627Z at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
2022-04-29T19:22:26.175601027Z at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)
2022-04-29T19:22:26.175605227Z at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
2022-04-29T19:22:26.175615128Z --- End of inner exception stack trace ---
2022-04-29T19:22:26.175619328Z at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
2022-04-29T19:22:26.175623528Z at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
2022-04-29T19:22:26.175639629Z at OpenQA.Selenium.WebDriver.StartSession(ICapabilities desiredCapabilities)
2022-04-29T19:22:26.175643929Z at OpenQA.Selenium.WebDriver..ctor(ICommandExecutor executor, ICapabilities capabilities)
2022-04-29T19:22:26.175648529Z at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
2022-04-29T19:22:26.175652229Z at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(Uri remoteAddress, ICapabilities desiredCapabilities, TimeSpan commandTimeout)
2022-04-29T19:22:26.175656029Z at SparefootScrape.Program.StartDriver() in /src/Program.cs:line 99
2022-04-29T19:22:26.175659630Z at SparefootScrape.Program.Main(String[] args) in /src/Program.cs:line 39
2022-04-29T19:22:26.176521765Z at SparefootScrape.Program.<Main>(String[] args)
I also tried localhost rather than the 'chrome' value I've assigned using hostname in the docker compose file but it also didn't work.
Any tips?
Here's my docker-compose:
version: "1.0"
services:
scrape:
image: "xxxxxx.azurecr.io/yyyyy:4.0"
stdin_open: true # docker run -i
tty: true # docker run -t
shm_size: '2gb'
restart: always
depends_on:
- chrome
selenium:
image: "selenium/standalone-chrome:latest"
container_name: "chrome"
hostname: chrome
shm_size: '2gb'
restart: always
ports:
- "4444:4444"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为它可以违反Docker-Compose.yml的定义并重命名服务:
I put it to work inverting the definition on docker-compose.yml and renaming the service: