Selenim test works fine locally on win10 or in a clean Windows Server 2016 with UI.
If I build a dockers container for windows and copy my tests in it fails with this message. Consistent on ff and chrome drivers. Seems to be a common error with not a lot of fixes out there.
Github repo with goodies - https://github.com/jhealy/devfish-shares/tree/master/docker-selenium-aspnet45
Repro
Verify we are serving web pages
Connect to container with interactive ps
Inside the container – make sure we can hit website
Extract out firefox, which we copy in with the docker file
Run selenium console app, which works fine outside container
Then I cry miserably cause I get the network timeout. Error dump below. Same thing for Chrome and FF with variance on the namespaces.
DOCKERFILE
# The `FROM` instruction specifies the base image. We are extending the `microsoft/aspnet` image.
FROM microsoft/aspnet
RUN mkdir seleniumtests
RUN mkdir seleniumtests/assets
# COPY IN THE WEBSITE
COPY ./MvcHelloWorld45/MvcHelloWorld45/bin/Publish/ /inetpub/wwwroot
# copy in the tests
COPY ./SeleniumDockerTest/bin/Release/ /seleniumtests
# chromedriver is bundled into the official nuget
# make sure geckodriver is there with the selenium tests
COPY ./assets/geckodriver-v0.24.0-win64/ /seleniumtests
# COPY IN FF
COPY ./assets/firefox /seleniumtests/assets
# choco chrome takes a bit
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
TIMEOUT ERROR
PS C:\seleniumtests> .\SeleniumDockerTest.exe http://localhost
1556475837609 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.PjTNZggGakAN"
!!!error:OpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server for URL http://localhost:49164/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.Firefox.FirefoxDriver..ctor(FirefoxOptions options)
at SeleniumDockerTest.Program.DoFirefoxTests() in C:\dev\devfish-shares.git\docker-selenium-aspnet45\SeleniumDockerTest\Program.cs:line 160
GOOGLE TEST
private static void DoChromeTests()
{
IWebDriver chromeDriver;
try
{
ChromeOptions option = new ChromeOptions();
option.AddArguments("--headless");
// fix set from https://bugs.chromium.org/p/chromium/issues/detail?id=942023
option.AddArguments("--window-size=1920,1080");
option.AddArguments("--disable-features=VizDisplayCompositor");
option.AddArguments("--disable-gpu");
//option.AddArgument("--no-sandbox");
//option.AddArgument("--dns-prefetch-disable");
Console.WriteLine("chrome options include --headless --dns-prefetch-disable --disablefeatures");
using (chromeDriver = new ChromeDriver(option))
{
chromeDriver.Navigate().GoToUrl(m_targetUrl);
string msg = "hello world";
Console.WriteLine($"CheckWebElements('{msg}')={CheckWebElements(msg,chromeDriver)}");
msg = "Matias Bruno";
Console.WriteLine($"CheckWebElements('{msg}')={CheckWebElements(msg,chromeDriver)}");
chromeDriver.Close();
chromeDriver.Quit();
}
}
catch (Exception ex)
{
Console.WriteLine("!!!error:" + ex.ToString());
}
}
FIREFOX TEST
private static void DoFirefoxTests()
{
Console.WriteLine("firefox tests commencing");
string fflocation = @"C:\Program Files\Mozilla Firefox\firefox.exe";
Console.WriteLine("BrowserExecutableLocation=" + fflocation);
IWebDriver firefoxDriver;
try
{
FirefoxOptions options = new FirefoxOptions();
options.BrowserExecutableLocation = fflocation;
options.AddArgument("--headless");
Console.WriteLine("--headless");
using (firefoxDriver = new FirefoxDriver(options))
{
firefoxDriver.Navigate().GoToUrl(m_targetUrl);
string msg = "hello world";
Console.WriteLine($"CheckWebElements('{msg}')={CheckWebElements(msg, firefoxDriver)}");
msg = "Matias";
Console.WriteLine($"CheckWebElements('{msg}')={CheckWebElements(msg, firefoxDriver)}");
firefoxDriver.Close();
firefoxDriver.Quit();
}
}
catch (Exception ex)
{
Console.WriteLine("!!!error:" + ex.ToString());
}
Console.WriteLine("firefox tests completed");
}