ОБНОВЛЕНИЕ 0429 - Полный образ докера, который вы можете использовать для работы с Windows, Docker, Chrome, Firefox и тестами. Все ссылки Dockerhub и инструкции в репозитории GitHub - https://github.com/jhealy/aspnet45-docker-selenium.
Мой тест на selenium.Chromedrive c # завершается неудачно с истечением времени ожидания при попытке получить удаленный сервер WebDriver.Основное сообщение выглядит как
HTTP-запрос к удаленному серверу WebDriver для URL http://localhost:49164/session, истекший через 60 секунд
Я подготовил приложение, используяdockerfile и скопируйте в него мое приложение.Я могу запустить приложение снаружи и внутри файла Docker с помощью powershell / wget.
В следующих разделах приведены Dockerfile, команды обеспечения и полный вывод скверных маленьких экранов ошибок.
DOCKERFILE
# extending the `microsoft/aspnet` image.
FROM microsoft/aspnet
# COPY ./bin/Publishoutput/ /inetpub/wwwroot
COPY ./MvcHelloWorld45/bin/Release/Publish/ /inetpub/wwwroot
RUN mkdir seleniumtests
COPY ./SeleniumDockerTest/bin/Release/ /seleniumtests
# choco chrome takes a bit
RUN echo 'Downloading chocolatey...'
RUN powershell -Command Install-PackageProvider -name chocolatey -Force
RUN powershell -Command Set-PackageSource -Name chocolatey -Trusted
RUN powershell -Command Get-PackageSource
RUN echo 'Install Chrome via chocolatey...'
RUN powershell -Command Install-Package GoogleChrome -MinimumVersion 74
ПРЕДОСТАВЛЕНИЕ
# build and run my image in local machine powershell
docker build -f dockerfile -t aspnet45 .
Docker run -d --name aspnet45run -p 5000:80 aspnet45
# verify web server is up and running
curl http://localhost:5000
# powershell into remote machine
Docker exec -it <first couple unique chars of ps> powershell
# inside remote machine make sure we can hit it
curl http://localhost -UseBasicParsing
# run test which works fine outside but blows up inside container
cd \seleniumtests
.\SeleniumDockerTest.exe
C # СЕЛЕНОВЫЕ ИСПЫТАНИЯ С ИСПОЛЬЗОВАНИЕМ NUGET SELENIUM.WEBDRIVER.CROME ДЛЯ CH74
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace SeleniumDockerTest
{
class Program
{
static IWebDriver m_driverGC;
static void Main(string[] args)
{
string targetUrl = @"http://localhsot";
try
{
ChromeOptions option = new ChromeOptions();
option.AddArgument("--headless");
option.AddArgument("--dns-prefetch-disable");
option.AddArgument("--disable-features=VizDisplayCompositon");
using (m_driverGC = new ChromeDriver(option))
{
m_driverGC.Navigate().GoToUrl(targetUrl);
string msg = "hello world";
Console.WriteLine($"CheckWebElements('{msg}')={CheckWebElements(msg)}");
m_driverGC.Close();
m_driverGC.Quit();
}
}
catch ( Exception ex )
{
Console.WriteLine("!!!error:" + ex.ToString());
}
}
static public bool CheckWebElements(string msg)
{
if (string.IsNullOrWhiteSpace(msg)) return false;
msg = msg.ToLower();
return m_driverGC.FindElement(By.Id("myH1")).Text.ToLower().Contains(msg);
}
}
}
ОШИБКИ БЛОКА
Ошибка тайм-аута Chrome WebDriver
[Target Url] =[http://localhost]
beginning chrome tests
[chrome options:] =[--headless --window-size=1920,1080 --disable-features=VizDisplayCompositor --disable-gpu]
Starting ChromeDriver 74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}) on port 49160
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[0430/150246.015:ERROR:network_change_notifier_win.cc(156)] WSALookupServiceBegin failed with: 0
[0430/150246.046:ERROR:audio_device_listener_win.cc(46)] RegisterEndpointNotificationCallback failed: 80070424
DevTools listening on ws://127.0.0.1:49163/devtools/browser/853e1883-9876-4fad-9dcc-6bf74c060baf
[0430/150246.253:ERROR:network_change_notifier_win.cc(156)] WSALookupServiceBegin failed with: 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!
[exception caught] =[OpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server for URL http://localhost:49160/session timed out after 60 seconds. ---> System.Net.WebException: The operation has timed out
at System.Net.HttpWebRequest.GetResponse()
at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)
--- End of inner exception stack trace ---
at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)
at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout)
at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeOptions options)
at SeleniumDockerTest.Program.DoChromeTests() in C:\dev\docker-selenium-aspnet45.git\SeleniumDockerTest\Program.cs:line 53]
!!!!!!!!!!!!!!!!!!!!!!!!!!!
Hit any key to continue
Ошибка тайм-аута веб-драйвера Firefox
PS C:\seleniumtests> .\seleniumdockertest.exe http://localhost
[Target Url] =[http://localhost]
firefox tests commencing
BrowserExecutableLocation=C:\Program Files\Mozilla Firefox\firefox.exe
-headless
1556651472894 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "-marionette" "-headless" "-foreground" "-no-remote" "-profile" "C:\\Users\\ContainerAdministrator\\AppData\\Local\\Temp\\rust_mozprofile.hlVVZVvFg66U"
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!error:OpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server for URL http://localhost:49158/session timed out after 60 seconds. ---> System.Net.WebException: The request was aborted: The operation has timed out.
at System.Net.HttpWebRequest.GetResponse()
at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)
--- End of inner exception stack trace ---
at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)
at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
at OpenQA.Selenium.Firefox.FirefoxDriver..ctor(FirefoxOptions options)
at SeleniumDockerTest.Program.DoFirefoxTests() in C:\dev\docker-selenium-aspnet45.git\SeleniumDockerTest\Program.cs:line 150
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
firefox tests completed
Hit any key to continue
Спасибо за просмотр!