【发布时间】:2019-09-17 00:04:53
【问题描述】:
更新 0429 - 您可以提取和使用完整的 docker 映像,其中包含 Windows、Docker、Chrome、Firefox 和所有测试。Dockerhub 链接和 GitHub 存储库中的说明 - https://github.com/jhealy/aspnet45-docker-selenium。
我的 selenium.Chromedrive c# 测试失败,尝试获取远程 WebDriver 服务器超时。主要信息似乎是
对 URL http://localhost:49164/session 的远程 WebDriver 服务器的 HTTP 请求在 60 秒后超时
我使用 dockerfile 配置应用程序并将我的应用程序复制到其中。 我可以通过 powershell/wget 在外部和 docker 文件内部访问应用程序。
以下部分包括 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
使用 NUGET SELENIUM.WEBDRIVER.CHROME 对 CH74 进行 C# SELENIUM 测试
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 超时错误
[目标网址] =[http://localhost] 开始 chrome 测试 [chrome 选项:] =[--headless --window-size=1920,1080 --disable-features=VizDisplayCompositor --disable-gpu] 在端口 49160 上启动 ChromeDriver 74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}) 只允许本地连接。 请保护 ChromeDriver 和相关测试框架使用的端口,防止恶意代码访问。 [0430/150246.015:ERROR:network_change_notifier_win.cc(156)] WSALookupServiceBegin 失败:0 [0430/150246.046:ERROR:audio_device_listener_win.cc(46)] RegisterEndpointNotificationCallback 失败:80070424 DevTools 监听 ws://127.0.0.1:49163/devtools/browser/853e1883-9876-4fad-9dcc-6bf74c060baf [0430/150246.253:ERROR:network_change_notifier_win.cc(156)] WSALookupServiceBegin 失败:0 !!!!!!!!!!!!!!!!!!!!!!!!!!! [捕获异常] =[OpenQA.Selenium.WebDriverException:对 URL http://localhost:49160/session 的远程 WebDriver 服务器的 HTTP 请求在 60 秒后超时。 ---> System.Net.WebException:操作已超时 在 System.Net.HttpWebRequest.GetResponse() 在 OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo) --- 内部异常堆栈跟踪结束 --- 在 OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo) 在 OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(命令 commandToExecute) 在 OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(命令 commandToExecute) 在 OpenQA.Selenium.Remote.RemoteWebDriver.Execute(字符串 driverCommandToExecute,Dictionary`2 参数) 在 OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities) 在 OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor,ICapabilities desiredCapabilities) 在 OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeDriverService 服务,ChromeOptions 选项,TimeSpan 命令超时) 在 OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeOptions 选项) 在 C:\dev\docker-selenium-aspnet45.git\SeleniumDockerTest\Program.cs:line 53 中的 SeleniumDockerTest.Program.DoChromeTests()] !!!!!!!!!!!!!!!!!!!!!!!!!!! 按任意键继续Firefox 网络驱动程序超时错误
PS C:\seleniumtests> .\seleniumdockertest.exe http://localhost [目标网址] =[http://localhost] 火狐测试开始 BrowserExecutableLocation=C:\Program Files\Mozilla Firefox\firefox.exe -无头 1556651472894 mozrunner::runner INFO 运行命令:“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: 对 URL http://localhost:49158/session 的远程 WebDriver 服务器的 HTTP 请求在 60 秒后超时。 ---> System.Net.WebException:请求已中止:操作已超时。 在 System.Net.HttpWebRequest.GetResponse() 在 OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo) --- 内部异常堆栈跟踪结束 --- 在 OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo) 在 OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(命令 commandToExecute) 在 OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(命令 commandToExecute) 在 OpenQA.Selenium.Remote.RemoteWebDriver.Execute(字符串 driverCommandToExecute,Dictionary`2 参数) 在 OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities) 在 OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor,ICapabilities desiredCapabilities) 在 OpenQA.Selenium.Firefox.FirefoxDriver..ctor(FirefoxOptions 选项) 在 C:\dev\docker-selenium-aspnet45.git\SeleniumDockerTest\Program.cs:line 150 中的 SeleniumDockerTest.Program.DoFirefoxTests() !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 火狐测试完成 按任意键继续感谢收看!
【问题讨论】:
标签: selenium docker selenium-chromedriver docker-for-windows